aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
AgeCommit message (Collapse)AuthorFilesLines
2024-02-23x86: also permit YMM/ZMM use in CFI directivesJan Beulich1-1/+2
Next to code using %ymm<N> or %zmm<N> it is more natural to have .cfi_* directives also reference those, not the corresponding %xmm<N>. Accept their names as kind of aliases, i.e. resolving to the same numbers. While extending the respective 64-bit testcase, also add %bnd<N> there (should have happened right with 633789901c83 ["x86-64: Dwarf2 register numbers for %bnd<N>"], sorry), requiring binutils/dwarf.c to be adjusted accordingly as well.
2024-01-26Assertion failure dumping .eh_frame_hdrAlan Modra1-6/+6
dwarf.c can hit "Assertion '(start) <= (end)' failed" on truncated sections, due to get_encoded_eh_value wrongly returning a full count for truncated words. * dwarf.c (get_encoded_eh_value): Return zero for truncated words.
2024-01-19Update readelf's and objdump's debug frame displaying feature to include the ↵Nick Clifton1-0/+260
contents of the .eh_frame_hdr section, if present.
2024-01-04Update year range in copyright notice of binutils filesAlan Modra1-1/+1
Adds two new external authors to etc/update-copyright.py to cover bfd/ax_tls.m4, and adds gprofng to dirs handled automatically, then updates copyright messages as follows: 1) Update cgen/utils.scm emitted copyrights. 2) Run "etc/update-copyright.py --this-year" with an extra external author I haven't committed, 'Kalray SA.', to cover gas testsuite files (which should have their copyright message removed). 3) Build with --enable-maintainer-mode --enable-cgen-maint=yes. 4) Check out */po/*.pot which we don't update frequently.
2023-12-15Re: readelf..debug-dump=loc displays bogus base addressesAlan Modra1-16/+10
Commit b05efa39b479 removed checks I added in commit f22f27f46c75 to prevent segfaults when debug_info_p is NULL, which can be the case with fuzzed objects. Restore those checks. Also, for dwo look at rnglists_dwo rather than rnglists.
2023-12-05memory leak in display_debug_addrAlan Modra1-6/+7
* dwarf.c (display_debug_addr): Free dummy debug_addr_info entry. Don't return without freeing debug_addr_info on error paths.
2023-12-04Fix two buglets in .debug_names dumpingTom Tromey1-3/+8
While working on gdb's .debug_names writer, I found a couple of small bugs in binutils .debug_names dumping. First, the DWARF spec (section 6.1.1.4.6 Name Table) says: These two arrays are indexed starting at 1, [...] I think it is clearer for binutils to follow this, particularly because DW_IDX_parent refers to this number. Second, I think the handling of an empty hash table is slightly wrong. Currently the dumping code assumes there is always an array of hashes. However, section 6.1.1.4.5 Hash Lookup Table says: The optional hash lookup table immediately follows the list of type signatures. and then: The hash lookup table is actually two separate arrays: an array of buckets, followed immediately by an array of hashes. My reading of this is that the hash table as a whole is optional, and so the hashes will not exist in this case. (This also makes sense because the hashes are not useful without the buckets anyway.) This patch fixes both of these problems. FWIW I have some gdb patches in progress that change gdb both to omit the hash table and to use DW_IDX_parent. 2023-12-04 Tom Tromey <tom@tromey.com> * dwarf.c (display_debug_names): Handle empty .debug_names hash table. Name entries start at 1.
2023-12-01binutils/Dwarf: avoid "shadowing" of glibc function nameJan Beulich1-10/+10
Yet once again: Old enough glibc has an (unguarded) declaration of index() in string.h, which triggers a "shadows a global declaration" warning with at least some gcc versions.
2023-11-20Restore .gdb_index v9 display in readelfTom Tromey1-8/+49
An earlier patch (commit b05efa39 "readelf..debug-dump=loc displays bogus base addresses") inadvertently removed support for displaying .gdb_index v9 sections. This patch corrects the oversight. I tested this by using readelf on an appropriate file. * dwarf.c (display_gdb_index): Restore v9 display code.
2023-11-10readelf..debug-dump=loc displays bogus base addressesVsevolod Alekseyev1-305/+160
PR 30880 * dwarf.c (read_and_display_attr_value): Fix loclist handling. (display_loclists_list): Likewise.
2023-10-24[readelf] Handle unknown name of main in .gdb_index sectionTom de Vries1-7/+12
When compiling hello world and adding a v9 .gdb-index section: ... $ gcc -g hello.c $ gdb-add-index a.out ... readelf shows it as: ... Shortcut table: Language of main: unknown: 0 Name of main: ^A ... The documentation of gdb says about the "Name of main" that: ... This value must be ignored if the value for the language of main is zero. ... Implement this approach in display_gdb_index, such that we have instead: ... Shortcut table: Language of main: unknown: 0 Name of main: <unknown> ... Tested on x86_64-linux. Approved-By: Jan Beulich <jbeulich@suse.com>
2023-10-10asan: null dereference in read_and_display_attr_valueAlan Modra1-16/+9
This fixes multiple places in read_and_display_attr_value dealing with range and location lists that can segfault when debug_info_p is NULL. Fuzzed object files can contain arbitrary DW_FORMs. * dwarf.c (read_and_display_attr_value): Don't dereference NULL debug_info_p.
2023-10-10[readelf] Handle .gdb_index section version 9Tom de Vries1-63/+113
Add the abilitity to print a v9 .gdb_index section. The v9 section contains an extra table, which is printed as follows: ... Shortcut table: Language of main: Fortran 95 Name of main: contains_keyword ... [ For the example, I used the exec of gdb test-case gdb.fortran/nested-funcs-2-exp when running the test-case with target board cc-with-gdb-index. ] Tested on x86_64-linux. Approved-By: Nick Clifton <nickc@redhat.com>
2023-10-03Fix: readelf..info misreports DW_FORM_loclistx, DW_FORM_rnglistxVsevolod Alekseyev1-79/+31
PR 29267 * dwarf.c (fetch_indexed_value): Delete. (fetch_indexed_offset): Correct base address calculation. (read_and_display_attr_value): Replace uses of fetch_indexed_value with fetch_indexed_offset.
2023-09-25Fix readelf's display of dwarf v5 range listsVsevolod Alekseyev1-157/+354
PR 30792 * dwarf.h (struct debug_info): Remove range_versions field. * dwarf.c (fetch_indexed_offset): New function. (read_and_display_attr_value): Use it for DW_FORM_rnglistx. Remove code to initialise range_versions. (skip_attribute): New function. (read_bases): Read and reccord all range and address bases in a CU. (process_debug_info): Call read_bases. (display_debug_rnglists): Rename to display_debug_rnglists_unit_header and only display the range list header information. (display_debug_ranges): Adjust.
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.