aboutsummaryrefslogtreecommitdiff
path: root/binutils/dwarf.c
AgeCommit message (Collapse)AuthorFilesLines
2022-04-06Add code to display the contents of .debug_loclists sections which contain ↵Nick Clifton1-72/+441
offset entry tables. PR 28981 * dwarf.c (fetch_indexed_value): Rename to fecth_indexed_addr and return the address, rather than a string. (fetch_indexed_value): New function - returns a value indexed by a DW_FORM_loclistx or DW_FORM_rnglistx form. (read_and_display_attr_value): Add support for DW_FORM_loclistx and DW_FORM_rnglistx. (process_debug_info): Load the loclists and rnglists sections. (display_loclists_list): Add support for DW_LLE_base_addressx, DW_LLE_startx_endx, DW_LLE_startx_length and DW_LLE_default_location. (display_offset_entry_loclists): New function. Displays a .debug_loclists section that contains offset entry tables. (display_debug_loc): Call the new function. (display_debug_rnglists_list): Add support for DW_RLE_base_addressx, DW_RLE_startx_endx and DW_RLE_startx_length. (display_debug_ranges): Display the contents of the section's header. * dwarf.h (struct debug_info): Add loclists_base field. * testsuite/binutils-all/dw5.W: Update expected output. * testsuite/binutils-all/x86-64/pr26808.dump: Likewise.
2022-03-10Add option to objdump/readelf to disable access to debuginfod servers.Nick Clifton1-10/+26
* dwarf.c (use_debuginfod): New variable. Set to 1. (load_separate_debug_info): Only call debuginfod_fetch_separate_debug_info is use_debuginfod is true. (dwarf_select_sections_by_names): Add do-not-use-debuginfod and use-debuginfod options. (dwarf_select_sections_by_letters): Add D and E options. * dwarf.h (use_debuginfod): New extern. * objdump.c (usage): Mention the new options. * readelf.c (usage): Likewise. * doc/binutils.texi: Document the new options. * doc/debug-options.texi: Describe the new options. * NEWS: Mention the new feature. * testsuite/binutils-all/debuginfod.exp: Add tests of the new options.
2022-01-12objdump, readelf: Emit "CU:" format only when wide output is requestedHans-Peter Nilsson1-1/+1
As pre-approved by Alan in https://sourceware.org/pipermail/binutils/2021-September/118019.html and I believe people have run into getting testsuite failures for test-environments with "long" directory names, at least once more since that time. Enough. I grepped the gas, binutils and ld testsuites for "CU:" to catch target-specific occurrences, but I noticed none. I chose to remove "CU:" on the objdump tests instead of changing options to get the wide format, so as to keep the name of the test consistent with actual options; but added it to the readelf options for the gas test as I believe the "CU:" format is preferable. Tested for cris-elf and native x86_64-pc-linux-gnu. binutils: * dwarf.c (display_debug_lines_decoded): Don't check the string length of the directory, instead emit the "CU: dir/name" format only if wide output is requested. * testsuite/binutils-all/dw5.W, testsuite/binutils-all/objdump.WL: Adjust accordingly. gas: * testsuite/gas/elf/dwarf-5-loc0.d: Add -W to readelf options.
2022-01-04Add ATTRIBUTE_UNUSED to load_build_id_debug_file()'s main_filename parameter.Nick Clifton1-1/+1
2022-01-04Remove a spurious debugging message.Nick Clifton1-3/+0
PR 28716 * dwarf.c (load_build_id_debug_file): Remove spurious printf.
2022-01-02Update year range in copyright notice of binutils filesAlan Modra1-1/+1
The result of running etc/update-copyright.py --this-year, fixing all the files whose mode is changed by the script, plus a build with --enable-maintainer-mode --enable-cgen-maint=yes, then checking out */po/*.pot which we don't update frequently. The copy of cgen was with commit d1dd5fcc38ead reverted as that commit breaks building of bfp opcodes files.
2021-12-17try_build_id_prefix gcc-10 -Wformat-security errorsAlan Modra1-3/+2
dwarf.c:11300:3: error: format not a string literal and no format arguments [-Werror=format-security] 11300 | f += sprintf (f, prefix); PR 28697 * dwarf.c (try_build_id_prefix): Avoid -Wformat-security error.
2021-12-16When loading separate debug info files, also attempt to locate a file based ↵Nick Clifton1-1/+115
upon the build-id. PR 28697 * dwarf.c (load_build_id_debug_file): New function. (try_build_id_prefix): New function. (check_for_and_load_links): Call load_build_id_debug_file. (debug_displays): Add entry for .note.gnu.build-id. * dwarf.h (enum dwarf_section_display_enum): Add note_gnu_build_id. * testsuite/binutils-all/debuginfod.exp (test_fetch_debuglink): Fix regexp for loads via debuglink section.
2021-12-10Don't return the main file as the separate debug infoH.J. Lu1-1/+17
On Fedora 35, $ readelf -d /usr/bin/npc caused readelf to run out of stack since load_separate_debug_info returned the input main file as the separate debug info: (gdb) bt #0 load_separate_debug_info ( main_filename=main_filename@entry=0x510f50 "/export/home/hjl/.cache/debuginfod_client/dcc33c51c49e7dafc178fdb5cf8bd8946f965295/debuginfo", xlink=xlink@entry=0x4e5180 <debug_displays+4480>, parse_func=parse_func@entry=0x431550 <parse_gnu_debuglink>, check_func=check_func@entry=0x432ae0 <check_gnu_debuglink>, func_data=func_data@entry=0x7fffffffdb60, file=file@entry=0x51d430) at /export/gnu/import/git/sources/binutils-gdb/binutils/dwarf.c:11057 #1 0x000000000043328d in check_for_and_load_links (file=0x51d430, filename=0x510f50 "/export/home/hjl/.cache/debuginfod_client/dcc33c51c49e7dafc178fdb5cf8bd8946f965295/debuginfo") at /export/gnu/import/git/sources/binutils-gdb/binutils/dwarf.c:11381 #2 0x00000000004332ae in check_for_and_load_links (file=0x51b070, filename=0x518dd0 "/export/home/hjl/.cache/debuginfod_client/dcc33c51c49e7dafc178fdb5cf8bd8946f965295/debuginfo") Return NULL if the separate debug info is the same as the input main file to avoid infinite recursion. PR binutils/28679 * dwarf.c (load_separate_debug_info): Don't return the input main file.
2021-12-02Fix illegal memory access whilst parsing corrupt DWARF debug information.Nick Clifton1-2/+16
PR 28645 * dwarf.c (process_cu_tu_index): Add test for overruning section whilst processing slots.
2021-11-30Use dwarf_vma type for offsets, ranges and section sizes in DWARF decoder.Nick Clifton1-36/+45
* dwarf.c (find_debug_info_for_offset): Use dwarf_vma type for offsets, sizes and ranges. (display_loc_list): Likewise. Also use print_dwarf_vma to print the offset. (display_loclists_list): Likewise. (display_loc_list_dwo): Likewise. (display_debug_str): Likewise. (display_debug_aranges): Likewise. (display_debug_ranges_list): Likewise. (display_debug_rnglists_list): Likewise. (display_debug_ranges): Likewise.
2021-11-10PR28543, readelf entered an infinite loopAlan Modra1-0/+2
This little tweak terminates fuzzed binary readelf output a little quicker. PR 28543 * dwarf.c (read_and_display_attr_value): Consume a byte when form is unrecognized.
2021-11-05PR28541, unstable cie offset in the output of readelfAlan Modra1-6/+11
Calculating "0 - pointer" can indeed result in seeming randomness as the pointer address varies. PR 28541 * dwarf.c (display_debug_frames): Don't print cie offset when invalid, print "invalid" instead. Remove now redundant warning.
2021-11-03Use section name in warnings in display_debug_locTom Tromey1-8/+12
While looking at an apparently malformed executable with "readelf --debug-dump=loc", I got this warning: readelf: ./main: Warning: There is a hole [0x89 - 0x95] in .debug_loc section. However, the executable only has a .debug_loclists section. This patch fixes the warning messages in display_debug_loc to use the name of the section that is being processed. binutils/ChangeLog 2021-11-03 Tom Tromey <tromey@adacore.com> * dwarf.c (display_debug_loc): Use section name in warnings.
2021-11-03asan: assert (addr_ranges) <= (start)Alan Modra1-10/+9
That assert would be more obvious if it were reported as "addr_ranges <= end_ranges". Fix that by using the obvious variable in the final loop. Stop the assertion by using a signed comparison: It's possible for the rounding up of the arange pointer to exceed the end of the block when the block size is fuzzed. * dwarf.c (display_debug_aranges): Use "end_ranges" in loop displaying ranges rather that "start". Simplify rounding up to 2*address_size boundary. Use signed comparison in loop.
2021-10-17PR28459, readelf issues bogus warningAlan Modra1-1/+0
I'd missed the fact that the .debug_rnglists dump doesn't exactly display the contents of the section. Instead readelf rummages through .debug_info looking for DW_AT_ranges entries, then displays the entries in .debug_rnglists pointed at, sorted. A simpler dump of the actual section contents might be more useful and robust, but it was likely done that way to detect overlap and holes. Anyway, the headers in .debug_rnglists besides the first are ignored, and limiting to the unit length of the first header fails if there is more than one unit. PR 28459 * dwarf.c (display_debug_ranges): Don't constrain data to length in header.
2021-09-29PR27202, readelf -wL doesn't work on ".loc 0"Alan Modra1-3/+8
For DWARF revision 4 and earlier, display_debug_lines_decoded populates the file_table array with entries read from .debug_line after the directory table. file_table[0] contains the first entry. DWARF rev 4 line number programs index this entry as file number one. DWARF revision 5 changes .debug_line format quite extensively, and in particular gives file number zero a meaning. PR 27202 * dwarf.c (display_debug_lines_decoded): Correct indexing used for DWARF5 files.
2021-07-16Updated Swedish translation for the binutils sub-directoryNick Clifton1-2/+4
2021-07-14objdump: add DWARF support for AIXClément Chigot1-45/+45
DWARF sections have special names on AIX which need be handled by objdump in order to correctly print them. This patch also adds the correlation in bfd for future uses. bfd/ * libxcoff.h (struct xcoff_dwsect_name): Add DWARF name. * coff-rs6000.c (xcoff_dwsect_names): Update. * coffcode.h (sec_to_styp_flags): Likewise. (coff_new_section_hook): Likewise. binutils/ * dwarf.h (struct dwarf_section): Add XCOFF name. * dwarf.c (struct dwarf_section_display): Update. * objdump.c (load_debug_section): Add XCOFF name handler. (dump_dwarf_section): Likewise. gas/ * config/tc-ppc.c (ppc_change_debug_section): Update to match new name's field.
2021-07-10PR28069, assertion fail in dwarf.c:display_discr_listAlan Modra1-16/+8
We shouldn't be asserting on anything to do with leb128 values, or reporting file and line numbers when something unexpected happens. leb128 data is of indeterminate length, perfect for fuzzer mayhem. It would only make sense to assert or report dwarf.c/readelf.c source lines if the code had already sized and sanity checked the leb128 values. After removing the assertions, the testcase then gave: <37> DW_AT_discr_list : 5 byte block: 0 0 0 0 0 (label 0, label 0, label 0, label 0, <corrupt> readelf: Warning: corrupt discr_list - unrecognized discriminant byte 0x5 <3d> DW_AT_encoding : 0 (void) <3e> DW_AT_identifier_case: 0 (case_sensitive) <3f> DW_AT_virtuality : 0 (none) <40> DW_AT_decimal_sign: 5 (trailing separate) So the DW_AT_discr_list was showing more data than just the 5 byte block. That happened due to "end" pointing a long way past the end of block, and uvalue decrementing past zero on one of the leb128 bytes. PR 28069 * dwarf.c (display_discr_list): Remove assertions. Delete "end" parameter, use initial "data" pointer as the end. Formatting. Don't count down bytes as they are read. (read_and_display_attr_value): Adjust display_discr_list call. (read_and_print_leb128): Don't pass __FILE__ and __LINE__ to report_leb_status. * dwarf.h (report_leb_status): Don't report file and line numbers. Delete file and lnum parameters, (READ_ULEB, READ_SLEB): Adjust.
2021-07-05PR28047, readelf crash due to assertion failureAlan Modra1-6/+10
DW_FORM_ref1, DW_FORM_ref2, DW_FORM_ref4, DW_FORM_ref1, and DW_FORM_ref_udata are all supposed to be within the containing unit. PR 28047 * dwarf.c (get_type_abbrev_from_form): Add cu_end parameter. Check DW_FORM_ref1 etc. arg against cu_end rather than end of section. Adjust all callers.
2021-07-02PR28048, heap-buffer-overflow on readelf -WwAlan Modra1-1/+1
PR 28048 * dwarf.c (get_type_signedness): Don't run off end of buffer printing DW_FORM_string attribute.
2021-06-30Handle DW_FORM_implicit_const when displaying an attributeNick Clifton1-0/+4
* dwarf.c (read_and_display_attr_value): Handle DW_FORM_implicit_const.
2021-06-30Fix signedness of def_cfa_sf and def_cfa_offset_sfRichard Henderson1-7/+9
* dwarf.c (display_debug_frames): Both DW_CFA_def_cfa_sf and DW_CFA_def_cfa_offset_sf have a signed offset.
2021-06-19dwarf.c: string_fortify.h strncpy errorAlan Modra1-16/+8
In function 'strncpy', inlined from 'display_debug_lines_decoded' at /home/alan/src/binutils-gdb/binutils/dwarf.c:5434:5, inlined from 'display_debug_lines' at /home/alan/src/binutils-gdb/binutils/dwarf.c:5567:21: /usr/include/bits/string_fortified.h:95:10: error: '__builtin_strncpy' specified bound 36 equals destination size [-Werror=stringop-truncation] No need for strncpy here, the string being copied always fits the destination buffer. * dwarf.c (display_debug_lines_decoded): Use memcpy rather than strncpy when trimming file name length to MAX_FILENAME_LENGTH. Don't make an unnecessary copy when length is good.
2021-06-14Use consistent type in binutils/dwarf.cEric Botcazou1-10/+10
If you look at the type used for implicit_const objects in binutils/dwarf.c, you'll get sometimes bfd_signed_vma and sometimes dwarf_signed_vma. They are the same on 64-bit hosts, but not on 32-bit hosts, and the latter discrepancy, in particular in process_abbrev_set, is responsible for the following error issued by objdump on some object files containing DWARF 5: binutils/dwarf.c:1108: read LEB value is too large to store in destination variable binutis/ * dwarf.c (struct abbrev_attr): Change type of implicit_const. (add_abbrev_attr): Likewise. (process_abbrev_set): Likewise. (display_debug_abbrev): Adjust to above change.
2021-06-07fix Dwarf2 build with certain gcc versionsJan Beulich1-1/+1
Older gcc reports: .../bfd/dwarf2.c: In function 'read_ranges': .../bfd/dwarf2.c:3107: error: comparison between signed and unsigned .../bfd/dwarf2.c: In function 'read_rnglists': .../bfd/dwarf2.c:3189: error: comparison between signed and unsigned Similarly for binutils/dwarf.c. Arrange for the left sides of the > to also be unsigned quantities.
2021-05-19Fix a build problem if ENABLE_CHECKING is not defined.Eli Schwartz1-0/+4
* dwarf.c (ENABLE_CHECKING): Define to 0 if not previously set.
2021-05-19PR27884, skip_attr_bytes: Assertion (data) <= (end) failedAlan Modra1-19/+23
PR 27884 * dwarf.c (get_type_abbrev_from_form): Replace cu_offset_return param with map_return, and return map for DW_FORM_ref_addr. (get_type_signedness): Adjust calls to get_type_abbrev_from_form. Pass returned cu map start and end to recursive call. (read_and_display_attr_value): Similarly.
2021-05-15process_cu_tu_indexAlan Modra1-27/+9
* dwarf.c (process_cu_tu_index): Avoid pointer UB. Use _mul_overflow. Delete dead code.
2021-05-15display_gdb_indexAlan Modra1-11/+7
* dwarf.c (display_gdb_index): Avoid pointer UB and overflow in length calculations.
2021-05-15display_debug_namesAlan Modra1-15/+29
* dwarf.c (display_debug_names): Complain when header length is too small. Avoid pointer UB. Sanity check augmentation string, CU table, TU table and foreign TU table sizes.
2021-05-15display_debug_framesAlan Modra1-103/+107
* dwarf.c (display_debug_frames): Delete initial_length_size. Avoid pointer UB. Constrain data reads to length given in header. Sanity check cie header length. Only skip up to next FDE on finding augmentation data too long.
2021-05-15read_cieAlan Modra1-1/+12
* dwarf.c (read_cie): Add more sanity checks to ensure data pointer is not bumped past end.
2021-05-15display_debug_rangesAlan Modra1-10/+6
* dwarf.c (display_debug_ranges): Delete initial_length_size. Correct fallback size calculated on finding a reloc. Constrain data reads to length given in header. Avoid pointer UB.
2021-05-15display_debug_rnglists_listAlan Modra1-1/+1
* dwarf.c (display_debug_rnglists_list): Avoid pointer UB.
2021-05-15display_debug_str_offsetsAlan Modra1-2/+2
* dwarf.c (display_debug_str_offsets): Constrain reads to length given in header.
2021-05-15display_debug_arangesAlan Modra1-18/+15
* dwarf.c (display_debug_aranges): Delete initial_length_size. Use end_ranges to constrain data reads to header length. Avoid pointer UB.
2021-05-15display_loc_listAlan Modra1-7/+13
* dwarf.c (display_loc_list): Avoid pointer UB. Correct check before reading uleb length. Warn on excess length.
2021-05-15display_debug_macroAlan Modra1-6/+10
* dwarf.c (display_debug_macro): Print strings that might not be zero terminated with %*s. Don't bump curr if unterminated.
2021-05-15get_line_filename_and_dirnameAlan Modra1-15/+22
* dwarf.c (get_line_filename_and_dirname): Delete initial_length_size. Simplify length sanity check, and check for too small lengths. Constrain data reads to header length. Avoid pointer UB.
2021-05-15display_debug_macinfoAlan Modra1-9/+15
The existing code went to the bother of using strnlen for scanning but went wild when printing, and possibly incremented curr past end. * dwarf.c (display_debug_macinfo): Print strings that might not be zero terminated with %*s. Don't bump curr if unterminated.
2021-05-15display_debug_pubnames_workerAlan Modra1-20/+14
* dwarf.c (display_debug_pubnames_worker): Delete initial_length_size. Simplify length check. Constrain reads to length given by header.
2021-05-15display_debug_lines_decodedAlan Modra1-4/+4
The directory_table strnlen used the negative of the proper size. After fixing that I realised we don't need strnlen here. * dwarf.c (display_debug_lines_decoded): Don't use strnlen when we have already checked for NUL termination.
2021-05-15read_debug_line_headerAlan Modra1-18/+5
This patch also better constrains the data read, and removes pointer UB. * dwarf.c (read_debug_line_header): Delete initial_length_size. Avoid pointer UB. Keep within length specified by header. Delete dead code.
2021-05-15process_debug_infoAlan Modra1-82/+61
This patch constrains process_debug_info to stay within the data specified by the CU length rather than allowing access up to the end of the section. * dwarf.c (process_debug_info): Always do the first CU length scan for sanity checks. Remove initial_length_size var and instead calculate end_cu. Use end_cu to limit data reads. Delete now dead code checking length.
2021-05-15SAFE_BYTE_GET_INTERNALAlan Modra1-1/+4
We won't want this assert triggering in the next release. * dwarf.c (SAFE_BYTE_GET_INTERNAL): Assert only when ENABLE_CHECKING.
2021-05-15_mul_overflow and get_encoded_valueAlan Modra1-1/+1
A sufficiently mad compiler optimiser can take undefined behaviour according to the C standard as an opportunity to remove code. Since "data + size" might be seen to be past the end of an array, calculating such an expression is UB. _mul_overflow is infrastructure for later patches. * bucomm.h (_mul_overflow): Define. * dwarf.c (get_encoded_value): Avoid pointer UB.
2021-05-13revert previous deltaNick Clifton1-7/+0
2021-05-13Fix an infinite loop in the DWARF decoder when parsing a corrupt string table.Nick Clifton1-1/+8
PR 27861 * dwarf.c (display_debug_str_offsets): Warn if the length field is larger than the amount of data remaining in the section.