aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
AgeCommit message (Collapse)AuthorFilesLines
2023-01-01Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The newer update-copyright.py fixes file encoding too, removing cr/lf on binutils/bfdtest2.c and ld/testsuite/ld-cygwin/exe-export.exp, and embedded cr in binutils/testsuite/binutils-all/ar.exp string match.
2022-12-30PR29948, heap-buffer-overflow in display_debug_lines_decodedAlan Modra1-52/+64
This fixes a couple of places in display_debug_lines_decoded that were off by one in checking DWARF5 .debug_line directory indices. It also displays the DWARF5 entry 0 for the program current directory rather than "." as is done for pre-DWARF5. I decided against displaying DW_AT_comp_dir for pre-DWARF5 since I figure it is better for readelf to minimally interpret debug info. binutils/ PR 29948 * dwarf.c (display_debug_lines_decoded): Display the given directory entry 0 for DWARF5. Properly check directory index against number of entries in the table. Revert to using unsigned int for n_directories and associated variables. Correct warning messages. gas/ * testsuite/gas/elf/dwarf-5-loc0.d: Update.
2022-12-19Tidy PR29893 and PR29908 fixAlan Modra1-20/+4
PR 29893 PR 29908 * dwarf.c (display_debug_addr): Combine dwarf5 unit_length checks. Delete dead code.
2022-12-19Fix potential illegal memory accesses when parsing corrupt DWARF data.Nick Clifton1-0/+14
PR 29914 * dwarf.c (fetch_indexed_value): Fail if the section is not big enough to contain a header size field. (display_debug_addr): Fail if the computed address size is too big or too small.
2022-12-16Fix previous delta to allow for compilation on 32-bit systemsNick Clifton1-3/+3
2022-12-16Fix a potential illegal memory access when parsing corrupt DWARF information.Nick Clifton1-1/+20
PR 29908 * dwarf.c (display_debug_addr): Check for corrupt header lengths.
2022-12-14asan: signed integer overflow in display_debug_framesAlan Modra1-108/+116
* dwarf.c (struct Frame_Chunk): Make col_offset an int64_t. Adjust all places allocating col_offset and col_type to use the size of the array element rather than the size of a type. (frame_display_row): Adjust printing of col_offset. (display_debug_frames): Factor out multiplication by code_factor and data_factor. Avoid signed overflow. Use 64-bit variables.
2022-12-13PR29893, buffer overflow in display_debug_addrAlan Modra1-2/+7
PR 29893 * dwarf.c (display_debug_addr): Sanity check dwarf5 unit_length field. Don't read past end.
2022-12-12PR29872, uninitialised value in display_debug_lines_decoded dwarf.c:5413Alan Modra1-27/+38
Plus segvs if the C-library doesn't handle printf %s of NULL. PR 29872 * dwarf.c (null_name): New function. (process_debug_info): Use it here.. (display_debug_lines_raw): ..and here.. (display_debug_lines_decoded): ..and here. xcalloc directory_table. Simplify xcalloc of file_table.
2022-12-11PR29870, objdump SEGV in display_debug_lines_decoded dwarf.c:5524Alan Modra1-2/+2
DWARF5 directory and file table allow more opportunity for fuzzers to break things. There are likely other places in dwarf.c that should be fixed too. PR 29870 * dwarf.c (display_debug_lines_decoded): Handle NULL file_table name entry.
2022-12-01binutils: improve holes detection in .debug_loclists.Clément Chigot1-14/+33
The previous warnings about holes in .debug_loclists sections don't take into account the headers of each CU and could include the locviews if they precede the loclist. The following warning can be triggered between two CU. ... <previous CU views> ... 0000001d <End of list> 0000002a v000000000000000 v000000000000000 location view pair 0000002c v000000000000000 v000000000000000 location view pair readelf: Warning: There is a hole [0x1e - 0x2e] in .debug_loclists section. 0000002e v000000000000000 v000000000000000 views at 0000002a for: ... But [0x1e - 0x2a] corresponds to the CU header and [0x2a - 0x2e] are the locviews. Thus there is no hole here. binutils/ChangeLog: * dwarf.c (display_debug_loc): Adjust holes detections for headers and locviews.
2022-11-23Don't use "long" in readelf for file offsetsAlan Modra1-7/+7
The aim here is to improve readelf handling of large 64-bit object files on LLP64 hosts (Windows) where long is only 32 bits. The patch changes more than just file offsets. Addresses and sizes are also changed to avoid "long". Most places get to use uint64_t even where size_t may be more appropriate, because that allows some overflow checks to be implemented easily (*alloc changes). * dwarf.c (cmalloc, xcmalloc, xcrealloc, xcalloc2): Make nmemb parameter uint64_t. * dwarf.h: Update prototypes. (struct dwarf_section): Make num_relocs uint64_t. * elfcomm.c (setup_archive): Update error format. * elfcomm.h (struct archive_info): Make sym_size, longnames_size, nested_member_origin, next_arhdr_offset uint64_t. * readelf.c (struct filedata): Make archive_file_offset, archive_file_size, string_table_length, dynamic_addr, dynamic_nent, dynamic_strings_length, num_dynamic_syms, dynamic_syminfo_offset uint64_t. (many functions): Replace uses of "unsigned long" with "uint64_t" or "size_t".
2022-11-18PR29799 heap buffer overflow in display_gdb_index dwarf.c:10548Alan Modra1-1/+1
PR 29799 * dwarf.c (display_gdb_index): Typo fix.
2022-10-30Pool section entries for DWP version 1Alan Modra1-49/+41
Ref: https://gcc.gnu.org/wiki/DebugFissionDWP?action=recall&rev=3 Fuzzers have found a weakness in the code stashing pool section entries. With random nonsensical values in the index entries (rather than each index pointing to its own set distinct from other sets), it's possible to overflow the space allocated, losing the NULL terminator. Without a terminator, find_section_in_set can run off the end of the shndx_pool buffer. Fix this by scanning the pool directly. binutils/ * dwarf.c (add_shndx_to_cu_tu_entry): Delete range check. (end_cu_tu_entry): Likewise. (process_cu_tu_index): Fill shndx_pool by directly scanning pool, rather than indirectly from index entries.
2022-10-03RISC-V: Assign DWARF numbers to vector registersTsukasa OI1-10/+18
This commit assigns DWARF register numbers to vector registers (v0-v31: 96..127) to implement RISC-V DWARF Specification version 1.0-rc4 (now in the frozen state): https://github.com/riscv-non-isa/riscv-elf-psabi-doc/releases/tag/v1.0-rc4 binutils/ChangeLog: * dwarf.c (dwarf_regnames_riscv): Assign DWARF register numbers 96..127 to vector registers v0-v31. gas/ChangeLog: * config/tc-riscv.c (tc_riscv_regname_to_dw2regnum): Support vector registers. * testsuite/gas/riscv/dw-regnums.s: Add vector registers to the DWARF register number test. * testsuite/gas/riscv/dw-regnums.d: Likewise.
2022-09-20Bug 29580 - typo in warning message: .note.gnu.build-id data size is too bugZeke Lu1-1/+1
2022-09-08i686-w64-mingw32-objdump -WL returns incorrect file pathsNick Clifton1-0/+7
PR 29523 * dwarf.c (display_debug_lines_decoded): Correctly handle DWARF-5 directory and filename tables.
2022-08-16PR29362, some binutils memory leaksAlan Modra1-28/+24
2022-08-16 Alan Modra <amodra@gmail.com> Cunlong Li <shenxiaogll@163.com> PR 29362 * dwarf.c (free_debug_information): New function, extracted.. (free_debug_memory): ..from here. (process_debug_info): Use it when before clearing out unit debug_information. Clear all fields. * objcopy.c (delete_symbol_htabs): New function. (main): Call it via xatexit. (copy_archive): Free "dir". * objdump.c (free_debug_section): Free reloc_info.
2022-08-13readelf: print 0x0 as 0, and remove trailing spacesAlan Modra1-95/+95
This changes readelf output a little, removing the 0x prefix on hex output when the value is 0, except in cases where a fixed field width is shown. %#010x is not a good replacement for 0x%08x.
2022-08-13Make dwarf_vma uint64_tAlan Modra1-982/+882
This replaces dwarf_vma, dwarf_size_type and dwarf_signed_vma with uint64_t and int64_t everywhere. The patch also gets rid of DWARF_VMA_FMT since we can't use that with uint64_t, and all of the configure support for deciding the flavour of HOST_WIDEST_INT. dwarf_vmatoa also disappears, replacing most uses with one of PRIx64, PRId64 or PRIu64. Printing of size_t and ptrdiff_t values now use %z and %t rather than by casting to unsigned long. Also, most warning messages that used 0x%lx or similar now use %#lx and a few that didn't print the 0x hex prefix now also use %#. The patch doesn't change normal readelf output, except in odd cases where values previously might have been truncated.
2022-08-13Don't use bfd_size_type in readelf.c and dwarf.cAlan Modra1-30/+28
Replacing bfd_size_type with dwarf_size_type or uint64_t is mostly cosmetic. The point of the change is to avoid use of a BFD type in readelf, where we'd like to keep as independent of BFD as possible. Also, the patch is a step towards using standard types.
2022-08-05Sanity check loc_offsets indexAlan Modra1-10/+20
Fixes a segfault found by the fuzzers. * dwarf.c (fetch_indexed_value): Return -1 on error. (read_and_display_attr_value): Don't display string when fetch_indexed_value returns an error. Sanity check loc_offsets index.
2022-08-05binutils/Dwarf: avoid "shadowing" of glibc function nameJan Beulich1-13/+13
As before: Old enough glibc has an (unguarded) declaration of index() in string.h, which triggers a "shadows a global declaration" warning.
2022-07-21PR29390, DW_CFA_AARCH64_negate_ra_state vs. DW_CFA_GNU_window_saveAlan Modra1-2/+11
PR 29390 binutils/ * dwarf.c (is_aarch64, DW_CFA_GNU_window_save_name): New. (display_debug_frames): Use them. (init_dwarf_regnames_aarch64): Set is_aarch64. (init_dwarf_regnames_by_elf_machine_code): Clear is_aarch64. (init_dwarf_regnames_by_bfd_arch_and_mach): Likewise. gas/ * testsuite/gas/aarch64/pac_ab_key.d: Adjust expected output. * testsuite/gas/aarch64/pac_negate_ra_state.d: Likewise.
2022-07-21PR29337, readelf CU/TU mixup in .gdb_indexAlan Modra1-2/+2
Commit 244e19c79111 changed a number of variables in display_gdb_index to count entries rather than words. PR 29337 * dwarf.c (display_gdb_index): Correct use of cu_list_elements.
2022-07-21PR29370, infinite loop in display_debug_abbrevAlan Modra1-13/+6
The PR29370 testcase is a fuzzed object file with multiple .trace_abbrev sections. Multiple .trace_abbrev or .debug_abbrev sections are not a violation of the DWARF standard. The DWARF5 standard even gives an example of multiple .debug_abbrev sections contained in groups. Caching and lookup of processed abbrevs thus needs to be done by section and offset rather than base and offset. (Why base anyway?) Or, since section contents are kept, by a pointer into the contents. PR 29370 * dwarf.c (struct abbrev_list): Replace abbrev_base and abbrev_offset with raw field. (find_abbrev_list_by_abbrev_offset): Delete. (find_abbrev_list_by_raw_abbrev): New function. (process_abbrev_set): Set list->raw and list->next. (find_and_process_abbrev_set): Replace abbrev list lookup with new function. Don't set list abbrev_base, abbrev_offset or next.
2022-07-21binutils/dwarf.c: abbrev cachingAlan Modra1-98/+110
I'm inclined to think that abbrev caching is counter-productive. The time taken to search the list of abbrevs converted to internal form is non-zero, and it's easy to decode the raw abbrevs. It's especially silly to cache empty lists of decoded abbrevs (happens with zero padding in .debug_abbrev), or abbrevs as they are displayed when there is no further use of those abbrevs. This patch stops caching in those cases. * dwarf.c (record_abbrev_list_for_cu): Add free_list param. Put abbrevs on abbrev_lists here. (new_abbrev_list): Delete function. (process_abbrev_set): Return newly allocated list. Move abbrev base, offset and size checking to.. (find_and_process_abbrev_set): ..here, new function. Handle lookup of cached abbrevs here, and calculate start and end for process_abbrev_set. Return free_list if newly alloc'd. (process_debug_info): Consolidate cached list lookup, new list alloc and processing into find_and_process_abbrev_set call. Free list when not cached. (display_debug_abbrev): Similarly.
2022-07-21miscellaneous dwarf.c tidiesAlan Modra1-110/+106
* dwarf.c: Leading and trailing whitespace fixes. (free_abbrev_list): New function. (free_all_abbrevs): Use the above. Free cu_abbrev_map here too. (process_abbrev_set): Print actual section name on error. (get_type_abbrev_from_form): Add overflow check. (free_debug_memory): Don't free cu_abbrev_map here.. (process_debug_info): ..or here. Warn on another case of not finding a neeeded abbrev.
2022-07-06Descriptive DWARF operations dump support for DW_AT_rankBhuvanendra Kumar N1-0/+1
DW_AT_rank is a dwarf-5 feature.
2022-07-05Support for location and range lists for split-dwarf and dwarf-5.Bhuvanendra Kumar N1-9/+32
Adding support for location and range lists for split-dwarf and dwarf-5. Following issues are taken care. 1. Display of the index values for DW_FORM_loclistx and DW_FORM_rnglistx. 2. Display of .debug_loclists.dwo and .debug_rnglists.dwo sections. * dwarf.c(read_and_display_attr_value): Handle DW_FORM_loclistx and DW_FORM_rnglistx for .dwo files. (process_debug_info): Load .debug_loclists.dwo and .debug_rnglists.dwo if exists. (load_separate_debug_files): Load .debug_loclists and .debug_rnglists if exists. Include 2 entries in debug_displays table. * dwarf.h (enum dwarf_section_display_enum): Include 2 entries.
2022-07-04Modified changes for split-dwarf and dwarf-5.Bhuvanendra Kumar N1-3/+9
* dwarf.c(process_debug_info): Include DW_TAG_skeleton_unit. (display_debug_str_offsets): While dumping .debug_str_offsets.dwo, pass proper str_offsets_base to fetch_indexed_string(). (load_separate_debug_files): Skip DWO ID dump for dwarf-5.
2022-07-01Add newline to the end of the rnglists displsy.Nick Clifton1-0/+1
2022-06-30Fix implementation of readelf's -wE and -wN options,Nick Clifton1-2/+8
* dwarf.c (dwarf_select_sections_by_name): If the entry's value is zero then clear the corresponding variable. (dwarf_select_sections_by_letters): Likewise. * testsuite/binutils-all/debuginfo.exp: Expect -WE and -wE debuginfod tests to fail.
2022-06-28Fix the display of the idnex values for DW_FORM_loclistx and ↵Nick Clifton1-86/+132
DW_FORM_rnglistx. Correct the display of .debug.loclists sections. PR 29267 * dwarf.c (display_debug_rnglists): New function, broken out of.. (display_debug_ranges): ... here. (read_and_display_attr_value): Correct calculation of index displayed for DW_FORM_loclistx and DW_FORM_rnglistx. * testsuite/binutils-all/x86-64/pr26808.dump: Update expected output.
2022-06-27Replace a run-time assertion failure with a warning message when parsing ↵Nick Clifton1-1/+6
corrupt DWARF data. PR 29289 * dwarf.c (display_debug_names): Replace assert with a warning message.
2022-06-27Fix NULL pointer indirection when parsing corrupt DWARF data.Nick Clifton1-6/+5
PR 29290 * dwarf.c (read_and_display_attr_value): Check that debug_info_p is set before dereferencing it.
2022-06-27Stop bogus warnings about DWARF indexed string offsets being too big.Nick Clifton1-72/+17
* dwarf.c (fetch_indexed_string): Do not use length of first table in string section as the length of every table in the section. * testsuite/binutils-all/pr26112.r: Update expected output.
2022-06-27Fix location list offset address dump under DW_AT_location (dwarf-5)Bhuvanendra Kumar N1-12/+26
For clang compiled objects with dwarf-5, location list offset address dump under DW_AT_location is corrected, where DW_FORM_loclistx is used. While dumping the location list offset, the address dumped is wrong where it was refering to .debug_addr instead of .debug_loclists * dwarf.c (fetch_indexed_value): Add base_address as parameter and use it to access the section offset. (read_and_display_attr_value): Handle DW_FORM_loclistx form separately. Pass loclists_base to fetch_indexed_value().
2022-06-22Binutils support for split-dwarf and dwarf-5Kumar N, Bhuvanendra1-14/+43
* dwarf.c (fetch_indexed_string): Added new parameter str_offsets_base to calculate the string offset. (read_and_display_attr_value): Read DW_AT_str_offsets_base attribute. (process_debug_info): While allocating memory and initializing debug_information, do it for do_debug_info also, if its true. (load_separate_debug_files): Load .debug_str_offsets if exists. * dwarf.h (struct debug_info): Add str_offsets_base field.
2022-06-22PR29270, DW_FORM_udata signed outputAlan Modra1-1/+5
PR 29270 * dwarf.c (read_and_display_attr_value): Output DW_FORM_udata as unsigned.
2022-06-21Binutils support for dwarf-5 (location and range lists related)Nick Clifton1-13/+40
* dwarf.h (struct debug_info): Add rnglists_base field. * dwarf.c (read_and_display_attr_value): Read attribute DW_AT_rnglists_base. (display_debug_rnglists_list): While handling DW_RLE_base_addressx, DW_RLE_startx_endx, DW_RLE_startx_length items, pass the proper parameter value to fetch_indexed_addr(), i.e. fetch the proper entry in .debug_addr section. (display_debug_ranges): Add rnglists_base to the .debug_rnglists base address. (load_separate_debug_files): Load .debug_addr section, if exists.
2022-06-16Restore readelf -wFAlan Modra1-102/+59
Commit 94585d6d4495 resulted in readelf -wF failing with Unrecognized debug letter option 'F' binutils/ * dwarf.c (debug_dump_long_opts): Add letter. (debug_option_table): New, replacing.. (opts_table, letter_table): ..these. (dwarf_select_sections_by_names): Adjust to suit. Set do_debug_frames outside of loop. (dwarf_select_sections_by_letters): Similarly. gas/ * testsuite/gas/i386/ehinterp.d: Use readelf -wF.
2022-06-16PR29250, readelf erases CIE initial register stateAlan Modra1-37/+31
PR 29250 binutils/ * dwarf.c (display_debug_frames): Set col_type[reg] on sizing pass over FDE to cie->col_type[reg] if CIE specifies reg. Handle DW_CFA_restore and DW_CFA_restore_extended on second pass using the same logic. Remove unnecessary casts. Don't call frame_need_space on second pass over FDE. gas/ * testsuite/gas/i386/ehinterp.d, * testsuite/gas/i386/ehinterp.s: New test. * testsuite/gas/i386/i386.exp: Run it.
2022-06-14asan: applying zero offset to NULL pointerAlan Modra1-2/+3
* dwarf.c (fetch_indexed_string): Move initialisation of "curr" and "end" after checking for missing section.
2022-05-25Add bionutils support for DWARF v5's DW_OP_addrx.Natarajan, Kavitha1-4/+13
2022-05-24PR29171, invalid read causing SIGSEGVAlan Modra1-4/+5
The fix here is to pass "section" down to read_and_display_attr_value. The test in read_and_display_attr_value is a little bit of hardening. PR 29171 * dwarf.c (display_debug_macro, display_debug_names): Pass section to read_and_display_attr_value2. (read_and_display_attr_value): Don't attempt to check for .dwo section name when section is NULL.
2022-05-24PR29170, divide by zero displaying fuzzed .debug_namesAlan Modra1-21/+24
PR 29170 * dwarf.c (display_debug_names): Don't attempt to display bucket clashes when bucket count is zero.
2022-05-24PR29169, invalid read displaying fuzzed .gdb_indexAlan Modra1-58/+22
PR 29169 * dwarf.c (display_gdb_index): Combine sanity checks. Calculate element counts, not word counts.
2022-05-20Stop readekf and objdump from aggressively following links.Nick Clifton1-35/+75
* dwarf.c (dwarf_select_sections_by_names): Return zero if no sections were selected. (dwarf_select_sections_by_letters): Likewise. * dwarf.h: (dwarf_select_sections_by_names): Update prototype. (dwarf_select_sections_by_letters): Update prototype. * objdump.c (might_need_separate_debug_info): New function. (dump_bfd): Call new function before attempting to load separate debug info files. (main): Do not enable dwarf section dumping for -WK or -WN. * readelf.c (parse_args): Do not enable dwarf section dumping for -wK or -wN. (might_need_separate_debug_info): New function. (process_object): Call new function before attempting to load separate debug info files. * testsuite/binutils-all/debuginfo.exp: Expect -WE and -wE debuginfod tests to pass. * testsuite/binutils-all/objdump.Wk: Add extra regexps. * testsuite/binutils-all/readelf.k: Add extra regexps.
2022-05-04Dwarf: rename yet another instance of "index"Jan Beulich1-3/+3
As before, on sufficiently old glibc this conflicts with a global identifier in the library headers. While there also zap the unusual padding by blanks.