aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
AgeCommit message (Collapse)AuthorFilesLines
2023-08-30binutils/dwarf.c abbrev list leakAlan Modra1-1/+7
* dwarf.c (process_debug_info): Call free_abrev_list on return paths.
2023-08-30Re: readelf/objdump: Handle DWARF info with mixed types of range sectionAlan Modra1-1/+4
PR 30791 * dwarf.c (free_debug_information): Free range_versions.
2023-08-23readelf/objdump: Handle DWARF info with mixed types of range section.Nick Clifton1-5/+25
PR 30791 * dwarf.h (debug_info): Add range_versions field. * dwarf.c (read_and_display_attr_value): When recording a range arribute also ecord the dwarf version number. (is_range_list_for_this_section): New function. (display_debug_ranges): Only show debug ranges whose version is suitable for the secction being displayed.
2023-08-22objdump: file name table entry count checkAlan Modra1-3/+3
Fuzzers have found that objdump -W takes a really long time if the entry count uleb is ridiculously large, and format attributes don't consume data (which doesn't make sense for a table of names). * dwarf.c (display_formatted_table): Sanity check count of table entries.
2023-06-09readelf/objdump remember_state memory leaksAlan Modra1-5/+7
* dwarf.c (display_debug_frames <DW_CFA_restore_state>): Do free invalid remember_state.
2023-04-20ubsan: signed integer overflow in display_debug_lines_rawAlan Modra1-4/+4
This one was caused by me unnecessarily promoting an "int adv" to "int64_t adv". The expression overflowing was 4259 + 9223372036854775807 with the left number being unsigned int. * dwarf.h (DWARF2_Internal_LineInfo): Replace unsigned short with uint16_t and unsigned char with uint8_t. Make li_line_base an int8_t. * dwarf.c (display_debug_lines_raw): Revert "adv" back to an int.
2023-04-19Fix: readelf: loc_offset XX too bigNick Clifton1-1/+1
PR 30355 * dwarf.c (read_and_display_attr_value): Correctly handle DW_loclistx attributes that index a version 5 .debug_loclists section.
2023-04-18objdump buffer overflow in fetch_indexed_stringAlan Modra1-13/+7
PR 30361 * dwarf.c (fetch_indexed_string): Sanity check string index.
2023-04-11Replace an assertion in the dwarf code with a warning message.Nick Clifton1-2/+8
PR 30327 * dwarf.c (read_and_display_attr_value): Warn if the number of views is greater than the number of locations.
2023-04-11Fix an attempt to allocate an excessive amount of memory when parsing a ↵Nick Clifton1-0/+13
corrupt DWARF file. PR 30313 * dwarf.c (display_debug_lines_decoded): Check for an overlarge number of files or directories.
2023-04-11Fix a potential illegal memory access when displaying corrupt DWARF information.Nick Clifton1-10/+14
PR 30312 * dwarf.c (prealloc_cu_tu_list): Always allocate at least one entry.
2023-04-03Memory leak in process_abbrev_setAlan Modra1-7/+3
We may have added some abbrevs to the list before hitting an error. Free the list elements too. free_abbrev_list returns list->next so we need to init it earlier to avoid an uninitialised memory access. * dwarf.c (process_abbrev_set): Call free_abbrev_list on errors. Set list->next earlier.
2023-03-30Fix an illegal memory access triggered by parsing corrupt DWARF info.Nick Clifton1-3/+29
PR 30284 * dwarf.c (read_and_display_attr_value): Detect and ignore negative base values.
2023-03-14Prevent an over large memory allocation in readelf when parsing a corrupt ↵Nick Clifton1-0/+3
DWARF file. PR 30227 * dwarf.c (process_cu_tu_index): Prevent excessive memory allocation when nused is large and ncols is zero.
2023-03-14Adjust the decoded line output to fit into 80 columns.Nick Clifton1-5/+10
PR 30216 * dwarf.c (display_debug_lines_decoded): Reduce space for filenames. * testsuite/binutils-all/dw5.W: Adjust expected output. * testsuite/binutils-all/objdump.WL: Adjust expected output.
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.