Commit Graph

482 Commits

Author SHA1 Message Date
Jan Beulich
a40a04601f x86: also permit YMM/ZMM use in CFI directives
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 633789901c ["x86-64: Dwarf2 register
numbers for %bnd<N>"], sorry), requiring binutils/dwarf.c to be adjusted
accordingly as well.
2024-02-23 11:59:09 +01:00
Alan Modra
e14f7abaf8 Assertion failure dumping .eh_frame_hdr
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-26 17:19:45 +10:30
Nick Clifton
1878f44b70 Update readelf's and objdump's debug frame displaying feature to include the contents of the .eh_frame_hdr section, if present. 2024-01-19 14:39:08 +00:00
Alan Modra
fd67aa1129 Update year range in copyright notice of binutils files
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.
2024-01-04 22:58:12 +10:30
Alan Modra
e838a672aa Re: readelf..debug-dump=loc displays bogus base addresses
Commit b05efa39b4 removed checks I added in commit f22f27f46c 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-15 12:56:45 +10:30
Alan Modra
1024d59cb2 memory leak in display_debug_addr
* dwarf.c (display_debug_addr): Free dummy debug_addr_info entry.
	Don't return without freeing debug_addr_info on error paths.
2023-12-05 18:20:51 +10:30
Tom Tromey
e0a874120a Fix two buglets in .debug_names dumping
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-04 11:20:44 -07:00
Jan Beulich
236b484749 binutils/Dwarf: avoid "shadowing" of glibc function name
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-12-01 10:13:17 +01:00
Tom Tromey
8116169676 Restore .gdb_index v9 display in readelf
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-20 09:31:32 -07:00
Vsevolod Alekseyev
b05efa39b4 readelf..debug-dump=loc displays bogus base addresses
PR 30880
  * dwarf.c (read_and_display_attr_value): Fix loclist handling. (display_loclists_list): Likewise.
2023-11-10 15:26:48 +00:00
Tom de Vries
07a9e70911 [readelf] Handle unknown name of main in .gdb_index section
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-24 12:35:08 +02:00
Alan Modra
f22f27f46c asan: null dereference in read_and_display_attr_value
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 22:17:29 +10:30
Tom de Vries
9847ba8f08 [readelf] Handle .gdb_index section version 9
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-10 10:26:40 +02:00
Vsevolod Alekseyev
8c7125feaa Fix: readelf..info misreports DW_FORM_loclistx, DW_FORM_rnglistx
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-10-03 09:27:27 +01:00
Vsevolod Alekseyev
84102ebc29 Fix readelf's display of dwarf v5 range lists
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-09-25 18:01:31 +01:00
Alan Modra
0283863037 binutils/dwarf.c abbrev list leak
* dwarf.c (process_debug_info): Call free_abrev_list on
	return paths.
2023-08-30 11:22:23 +09:30
Alan Modra
a422bb9db1 Re: readelf/objdump: Handle DWARF info with mixed types of range section
PR 30791
	* dwarf.c (free_debug_information): Free range_versions.
2023-08-30 11:22:23 +09:30
Nick Clifton
589d38af0d readelf/objdump: Handle DWARF info with mixed types of range section.
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-23 11:36:25 +01:00
Alan Modra
8032f75b29 objdump: file name table entry count check
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-08-22 11:41:37 +09:30
Alan Modra
ca5321d49a readelf/objdump remember_state memory leaks
* dwarf.c (display_debug_frames <DW_CFA_restore_state>): Do free
	invalid remember_state.
2023-06-09 12:56:12 +09:30
Alan Modra
329dd2b6fc ubsan: signed integer overflow in display_debug_lines_raw
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-20 09:03:53 +09:30
Nick Clifton
28ab94f51d Fix: readelf: loc_offset XX too big
PR 30355
  * dwarf.c (read_and_display_attr_value): Correctly handle DW_loclistx attributes that index a version 5 .debug_loclists section.
2023-04-19 11:48:24 +01:00
Alan Modra
34d63622f6 objdump buffer overflow in fetch_indexed_string
PR 30361
	* dwarf.c (fetch_indexed_string): Sanity check string index.
2023-04-18 10:24:40 +09:30
Nick Clifton
7bb9e56c6a Replace an assertion in the dwarf code with a warning message.
PR 30327
  * dwarf.c (read_and_display_attr_value): Warn if the number of views is greater than the number of locations.
2023-04-11 17:24:09 +01:00
Nick Clifton
9f1c612b7c Fix an attempt to allocate an excessive amount of memory when parsing a corrupt DWARF file.
PR 30313
  * dwarf.c (display_debug_lines_decoded): Check for an overlarge number of files or directories.
2023-04-11 16:14:23 +01:00
Nick Clifton
688fe114cd Fix a potential illegal memory access when displaying corrupt DWARF information.
PR 30312
  * dwarf.c (prealloc_cu_tu_list): Always allocate at least one entry.
2023-04-11 15:59:07 +01:00
Alan Modra
31991eaaee Memory leak in process_abbrev_set
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-04-03 07:29:01 +09:30
Nick Clifton
8d17c53b8d Fix an illegal memory access triggered by parsing corrupt DWARF info.
PR 30284
  * dwarf.c (read_and_display_attr_value): Detect and ignore negative base values.
2023-03-30 11:04:53 +01:00
Nick Clifton
97b75c421f Prevent an over large memory allocation in readelf when parsing a corrupt DWARF file.
PR 30227
  * dwarf.c (process_cu_tu_index): Prevent excessive memory allocation when nused is large and ncols is zero.
2023-03-14 13:15:12 +00:00
Nick Clifton
7506fc9bf1 Adjust the decoded line output to fit into 80 columns.
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-03-14 12:21:13 +00:00
Alan Modra
d87bef3a7b Update year range in copyright notice of binutils files
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.
2023-01-01 21:50:11 +10:30
Alan Modra
a984f112b0 PR29948, heap-buffer-overflow in display_debug_lines_decoded
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-30 21:31:19 +10:30
Alan Modra
956bc7a29f Tidy PR29893 and PR29908 fix
PR 29893
	PR 29908
	* dwarf.c (display_debug_addr): Combine dwarf5 unit_length checks.
	Delete dead code.
2022-12-19 22:30:36 +10:30
Nick Clifton
42f39fdedc Fix potential illegal memory accesses when parsing corrupt DWARF data.
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-19 11:13:46 +00:00
Nick Clifton
c7ce51d8c8 Fix previous delta to allow for compilation on 32-bit systems 2022-12-16 15:44:55 +00:00
Nick Clifton
fa501b6930 Fix a potential illegal memory access when parsing corrupt DWARF information.
PR 29908
	* dwarf.c (display_debug_addr): Check for corrupt header lengths.
2022-12-16 12:06:43 +00:00
Alan Modra
d0517d6e33 asan: signed integer overflow in display_debug_frames
* 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-14 13:07:43 +10:30
Alan Modra
c8628c770b PR29893, buffer overflow in display_debug_addr
PR 29893
	* dwarf.c (display_debug_addr): Sanity check dwarf5 unit_length
	field.  Don't read past end.
2022-12-13 00:36:08 +10:30
Alan Modra
b1f1cefd58 PR29872, uninitialised value in display_debug_lines_decoded dwarf.c:5413
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-12 19:25:19 +10:30
Alan Modra
f2f58a399c PR29870, objdump SEGV in display_debug_lines_decoded dwarf.c:5524
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-11 14:47:57 +10:30
Clément Chigot
de3b40320c binutils: improve holes detection in .debug_loclists.
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-12-01 15:49:03 +01:00
Alan Modra
26c527e62e Don't use "long" in readelf for file offsets
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-23 07:53:13 +10:30
Alan Modra
69bfd1759d PR29799 heap buffer overflow in display_gdb_index dwarf.c:10548
PR 29799
	* dwarf.c (display_gdb_index): Typo fix.
2022-11-18 11:31:17 +10:30
Alan Modra
28750e3b96 Pool section entries for DWP version 1
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-30 19:30:42 +10:30
Tsukasa OI
7b4f240762 RISC-V: Assign DWARF numbers to vector registers
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-10-03 04:04:35 +00:00
Zeke Lu
6af418600c Bug 29580 - typo in warning message: .note.gnu.build-id data size is too bug 2022-09-20 11:19:06 +01:00
Nick Clifton
2caffd34df i686-w64-mingw32-objdump -WL returns incorrect file paths
PR 29523
	* dwarf.c (display_debug_lines_decoded): Correctly handle DWARF-5
	directory and filename tables.
2022-09-08 09:56:39 +01:00
Alan Modra
450da4bd38 PR29362, some binutils memory leaks
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-16 00:25:10 +09:30
Alan Modra
cc44342012 readelf: print 0x0 as 0, and remove trailing spaces
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-13 14:11:27 +09:30
Alan Modra
31e5a3a380 Make dwarf_vma uint64_t
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-13 14:11:27 +09:30