Commit Graph

4682 Commits

Author SHA1 Message Date
Alan Modra
79674bfc36 PR31941 objcopy --globalize-symbol
I think FILE symbols are special, and I can't see why anyone would
want them to be made global.  The fact that no one has reported this
bug since commit 7b4a0685e8 in 2005 supports that claim.

	PR 31941
	* objcopy.c (filter_symbols): Don't allow BSF_FILE symbols to
	be made global.
2024-07-01 11:04:31 +09:30
Marcus Nilsson
ebe3f6d0f1 objcopy: Allow making symbol global and weak on same invocation
Previously objcopy had to be run twice in order to make a local symbol
weak, first once to globalize it, and once again to mark it as weak.

	* objcopy.c (filter_symbols): Weaken symbols after making
	local/global changes.
	* testsuite/binutils-all/symbols-5.d,
	* testsuite/binutils-all/symbols-5.s: New test.
2024-07-01 07:19:47 +09:30
Alan Modra
4b8c2aaf2d Assertion `(data) <= (end)' failed in read_bases
* dwarf.c (skip_attribute): Don't increment data past end.
	Use SKIP_{S,U}LEB rather than READ_{S,U}LEB.
2024-06-30 14:41:37 +09:30
H.J. Lu
67b1d28b52 Set BFD_DECOMPRESS when reading build-id debuglink
We should set BFD_DECOMPRESS to decompress sections unless dumping the
section contents when reading build-id debuglink.

	PR binutils/31925
	* objdump.c (open_debug_file): Set BFD_DECOMPRESS to decompress
	sections unless dumping the section contents.
	* testsuite/binutils-all/objdump.exp (test_build_id_debuglink):
	Add a compress option.
	Run test_build_id_debuglink with none and zlib.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2024-06-27 14:22:25 -07:00
Pali Roh?r
973563710c Improve comments describing the Import Directory Table
PR 31728
2024-06-27 12:17:27 +01:00
Nick Clifton
057a2b4c4b Revert: 35fd2ddeb1
PR 20814
2024-06-26 13:17:25 +01:00
Szabolcs Nagy
22a8698b56 aarch64: Add DT_RELR tests for ILP32 ABI 2024-06-25 11:07:51 +01:00
Nick Clifton
e13c4e5890 Updated Spanish translations for the bfd and binutils sub-directories 2024-06-24 15:03:22 +01:00
Alan Modra
56f3903369 Revert "Remove LIBINTL_DEP"
This reverts commit e874cbd387.
The patch was wrong.  LIBINTL_DEP is needed with an in-tree gettext.
2024-06-20 21:15:27 +09:30
Alan Modra
e874cbd387 Remove LIBINTL_DEP
The intl directory in the source no longer exists.  LIBINTL_DEP is
thus always empty.  Remove references to it.

config/
	* gettext-sister.m4: Don't AC_SUBST LIBINTL_DEP.
bfd/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
binutils/
	* Makefile.am (*_DEPENDENCIES): Remove LIBINTL_DEP.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
gas/
	* Makefile.am (as_new_DEPENDENCIES): Remove LIBINTL_DEP.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
gdb/
	* Makefile.in (INTL_DEPS): Don't set or reference.
	* configure: Regenerate.
gdbserver/
	* Makefile.in (INTL_DEPS): Don't set or reference.
gdbsupport/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
gold/
	* Makefile.am (deps_var): Remove LIBINTL_DEP.
	(incremental_dump_DEPENDENCIES, dwp_DEPENDENCIES): Likewise.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
	* testsuite/Makefile.am (DEPENDENCIES): Remove LIBINTL_DEP.
	* testsuite/Makefile.in: Regenerate.
gprof/
	* Makefile.am (gprof_DEPENDENCIES): Remove LIBINTL_DEP.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
ld/
	* Makefile.am (ld_new_DEPENDENCIES): Remove LIBINTL_DEP.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
libctf/
	* Makefile.in: Regenerate.
	* configure: Regenerate.
opcodes/
	* configure.ac (BUILD_LIBS): Remove LIBINTL.
	(BUILD_LIB_DEPS): Remove LIBINTL_DEP.
	* Makefile.in: Regenerate.
	* configure: Regenerate.
2024-06-20 18:33:28 +09:30
Jan Beulich
28c812b349 readelf: rename recently added testsuite files
Files named *.0 are somewhat odd for testsuite expectations. Rename the
one such file to *.r with a suitable base name suffix, and have its
sibling follow suit in this latter regard.
2024-06-18 13:23:36 +02:00
Maciej W. Rozycki
38362a0c63 binutils/testsuite: Add a helper for relative path construction
Implement a helper to construct a relative path between two locations in
the filesystem, for example to make a path from the source to the object
directory for the case where a tool has been set up to look at a given
path and there is a need to point it elsewhere, but an absolute path
will not work.  The helper works on normalized paths internally, so the
result is correct even in the presence of symlinks as intermediate path
components.

So given "/path/to/src/gas/testsuite/gas/all" as the FROM argument and
then "/path/to/obj/gas/testsuite/tmpdir/none.s" as the TO argument the
helper will return "../../../../../obj/gas/testsuite/tmpdir/none.s" in
the absence of symlinks.
2024-06-17 23:28:20 +01:00
Alan Modra
1b19566b18 PR31898 bug in processing DW_RLE_startx_endx
PR 31898
	* dwarf.c (display_debug_rnglists_list): Correct fetch of "end"
	indexed address.  Remove excess parens.
2024-06-17 15:57:50 +09:30
Alan Modra
9dc9a56ebc support_dt_relr aarch64
Tweak commit db335d7e0a so that support_dt_relr returns false for
aarch64*-*-*ilp32.
2024-06-11 20:29:25 +09:30
Clément Chigot
db335d7e0a ld-aarch64: check support before launching dt_relr tests
Not all aarch64 targets supports dt_relr as this requires some
mechanisms on the OS side.

Adjust support_dt_relr helper and use it in aarch64-elf.exp.
2024-06-10 09:02:08 +02:00
Matthieu Longo
e83746f535 autoupdate: regen after replacing obsolete macros 2024-06-10 08:25:56 +09:30
Matthieu Longo
3dee0baea2 autoupdate: add square brackets around arguments of AC_INIT
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fINIT-2
2024-06-10 08:25:56 +09:30
Matthieu Longo
2cac47f5ba autoupdate: replace obsolete macros AC_AIX, AC_MINIX, and AC_GNU_SOURCE
- AC_AIX, AC_MINIX, and AC_GNU_SOURCE by AC_USE_SYSTEM_EXTENSIONS
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fAIX
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fMINIX-1
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fGNU_005fSOURCE-1
2024-06-10 08:25:55 +09:30
Matthieu Longo
c22e3e25de autoupdate: replace obsolete macros AC_HELP_STRING
- AC_HELP_STRING by AS_HELP_STRING
  https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fHELP_005fSTRING-1
Except for the ifdef in lib-prefix.m4, make the defun of AC_LIB_ARG_WITH
unconditional.
2024-06-10 08:25:55 +09:30
Richard Earnshaw
ecc5fed791 NEWS: arm: note that FPA support has been removed 2024-06-05 17:45:45 +01:00
Nick Clifton
cc08f5580e Update binutils release documentation to include using the -z option when invoking src-release.sh 2024-05-30 12:52:37 +01:00
Szabolcs Nagy
d565a95828 readelf: Use section names for displaying RELR relocs
In some cases using section names instead of symbol names for
displaying an address is more useful.

If the symbol falls outside the section where the address is
then likely it is not useful to display the address relative to.

And if symbols are stripped from a binary then printing the
section that contains the address is more useful than printing
<no sym>.
2024-05-29 16:08:04 +01:00
Szabolcs Nagy
d41629d35e readelf: Fix symbol display for RELR relocs
Filter symbols before binary searching for the right symbol to display
for a given address, such that only displayable symbols are present and
at most one per address.

The current logic does not handle multiple symbols for the same address
well if some of them are empty, the selected symbol is not stable with
respect to an unrelated symbol table change and on aarch64 often mapping
symbols are displayed which is not useful.

Filtering solves these problems at the cost of a linear scan of the
sorted symbol table.

The heuristic to select the best symbol likely could be improved, this
patch aims to improve symbol display for RELR without complex logic
such that the output is useful and stable for ld tests.
2024-05-29 16:08:04 +01:00
Nick Clifton
08b0f198b1 Add new ELF section and segment types to readelf. 2024-05-28 10:12:28 +01:00
Luca Boccassi
762910fbd1 readelf: add pretty printing for FDO Dlopen Metadata note 2024-05-20 16:47:00 +01:00
Georg-Johann Lay
e8c83191cc Include .rodata size in avr-objdump -P mem-usage.
PR 31687
2024-05-20 13:33:55 +01:00
Georg-Johann Lay
f65d4a2f81 Let avr-objdump show .note.gnu.avr.deviceinfo
PR 31704
2024-05-20 12:12:10 +01:00
Tom de Vries
e548840a03 [binutils/readelf] Fix handling of DW_MACRO_define_strx in dwo file
When printing a DW_MACRO_define_strx entry in a .debug_macro.dwo section, we
run into:
...
 DW_MACRO_define_strx lineno : 0 macro : <no .debug_str_offsets section>
...

Fix this in display_debug_macro by passing the correct dwo argument to a
fetch_indexed_string call.

That works fine for readelf -w, with with readelf -wm we have:
...
 DW_MACRO_define_strx lineno : 0 macro : <no .debug_str_offsets.dwo section>
...

Fix this in display_debug_macro by doing load_debug_section_with_follow for
str_dwo / str_index_dwo sections instead of str / str_index sections when
handling .debug_macro.dwo.

PR 31735
2024-05-15 09:45:55 +02:00
Tom de Vries
7e4f1f4bc7 [binutils/readelf] Fix printing of dwarf4 .debug_str_offsets.dwo
When compiling a hello world with dwarf4 split dwarf:
...
$ gcc -gdwarf-4 -gsplit-dwarf hello.c -save-temps -dA
...
we have in a-hello.s these three initial entries in .debug_str_offsets:
...
	.section        .debug_str_offsets.dwo,"e",@progbits
	.4byte  0       // indexed string 0x0: short int
	.4byte  0xa     // indexed string 0x1: /home/vries/binutils
	.4byte  0x1f    // indexed string 0x2: main
...
but "readelf -ws a.out" starts at the third entry:
...
Contents of the .debug_str_offsets.dwo section (loaded from a-hello.dwo):

    Length: 0x30
       Index   Offset [String]
           0 00000000  main
...

This is a regression since commit 407115429b ("Modified changes for
split-dwarf and dwarf-5."), which introduced a variable
debug_str_offsets_hdr_len in display_debug_str_offsets.

Fix this by setting display_debug_str_offsets to 0 for the dwarf4 case.

PR 31734
2024-05-15 09:45:55 +02:00
Richard Earnshaw
30d57f2e41 arm: update documentation for removal of the Maverick extension
Finally, update the documentation and add a NEWS item.
2024-05-14 10:56:58 +01:00
Richard Earnshaw
e06a561b73 arm: binutils: drop Maverick support.
Remove the decoding of the Maverick flag from readelf.
2024-05-14 10:56:58 +01:00
Alan Modra
ad658482c1 Re: PR31692, objdump fails .debug_info size check
The fuzzers found a hole.  bfd_section_size_insane doesn't check
!SEC_HAS_CONTENTS sections against file size for obvious reasons,
which allows fuzzed debug sections to be stupidly large.  Real debug
sections of course always have contents.

	PR 31692
	* objdump.c (load_specific_debug_section): Don't allow sections
	without contents.
2024-05-10 23:17:03 +09:30
Nick Clifton
2b34e06765 Add missing \n to the end of warning messages in dwarf.c.
PR 31722
2024-05-10 13:23:41 +01:00
Tom Tromey
573b697e9d Fix typo in binutils manual
I happened to notice that the binutils manual has a typo in the name
of a command-line option.
2024-05-08 08:38:05 -06:00
Alan Modra
635d05b88f PR31692, objdump fails .debug_info size check
PR 31692
	* objdump.c (load_specific_debug_section): Replace bfd_get_size
	check with bfd_section_size_insane.  Call free_debug_section
	after printing error messages.  Set section->start NULL when
	freeing.
2024-05-02 19:07:50 +09:30
Jan Beulich
6fde04116b objcopy: check input flavor before setting PE/COFF section alignment
coff_section_data() and elf_section_data() use the same underlying
field. The pointer being non-NULL therefore isn't sufficient to know
that pei_section_data() can validly be used on the incoming object.
Apparently in 64-bit-host builds the resulting memory corruption is
benign, whereas in 32-bit-host builds a segmentation fault occurs upon
de-referencing pei_section_data()'s return value.
2024-04-26 14:23:14 +02:00
Nick Clifton
3b3e209011 Update readelf's display of RELR sections to include the number of locations relocated 2024-04-24 12:45:04 +01:00
Alan Modra
bfe6fb329a PPC maintainers
I'm retiring from IBM, and Geoff hasn't been active for a very long
time.

	* MAINTAINERS (ppc): Remove myself and Geoff Keating.  Add
	Geoff to past maintainers.
2024-04-24 11:08:01 +09:30
H.J. Lu
6c2119acf7 objcopy.c: Fix bfd_copy_private_symbol_data on 32-bit hosts
Use long with bfd_copy_private_symbol_data to fix

.../binutils/objcopy.c: In
function ‘copy_object’:
.../binutils/objcopy.c:3383:17: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘long int’ [-Werror=sign-compare]
 3383 |   for (i = 0; i < symcount; i++)
      |                 ^

on 32-bit hosts.

	PR binutils/14493
	* objcopy.c (copy_object): Use long with
	bfd_copy_private_symbol_data.
2024-04-23 08:30:20 -07:00
Waqar Hameed
0de4ba0269 objdump: Round ASCII art lines in jump visualization 2024-04-23 16:10:50 +01:00
Alan Modra
e13e2ba45f use copy_private_symbol_data in objcopy
osympp appearing twice here is not a bug.

	PR 14493
	* objcopy.c (copy_object): Run the symbols through
	bfd_copy_private_symbol_data.
2024-04-23 11:20:41 +09:30
Nick Alcock
6364617120 binutils, objdump: Add --ctf-parent-section
This lets you examine CTF where the parent and child dicts are in entirely
different sections, rather than in a CTF archive with members with different
names.  The linker doesn't emit ELF objects structured like this, but some
third-party linkers may; it's also useful for objcopy-constructed files
in some cases.

(This is what the objdump --ctf-parent option used to do before commit
80b56fad5c in 2021.  The new semantics of that option are much more
useful, but that doesn't mean the old ones are never useful at all, so let's
bring them back.)

(I was specifically driven to add this by DTrace's obscure "ctypes" and
"dtypes" options, which dump its internal, dynamically-generated dicts out
to files for debugging purposes: there are two, one the parent of the other.
Since they're in two separate files rather than a CTF archive and we have no
tools that paste files together into archives, objdump wouldn't show them --
and even pasting them together into an ELF executable with objcopy didn't
help, since objdump had no options that could be used to look in specific
sections for the parent dict.  With --ctf-parent-section, this sort of
obscure use case becomes possible again.  You'll never need it for the
output of the normal linker.)

binutils/

	* doc/ctf.options.texi: Add --ctf-parent-section=.
	* objdump.c (dump_ctf): Implement it.
	(dump_bfd): Likewise.
	(main): Likewise.
2024-04-19 16:14:45 +01:00
Alan Modra
170957ff9b Tidy objdump opb expressions
I don't think any of these can overflow, but since all of the
expressions I'm editing here are inside a while loop with condition
addr_offset < stop_offset, this change makes it more obvious that they
can't overflow.

	* objdump.c (disassemble_bytes): Calculate octet expressions
	involving both addr_offset and stop_offset by first
	subtracting addr_offset from stop_offset.
2024-04-18 10:31:59 +09:30
Victor Do Nascimento
5b1c70bfe0 aarch64: Remove asserts from operand qualifier decoders [PR31595]
Given that the disassembler should never abort when decoding
(potentially random) data, assertion statements in the
`get_*reg_qualifier_from_value' function family prove problematic.

Consider the random 32-bit word W, encoded in a data segment and
encountered on execution of `objdump -D <obj_name>'.

If:

  (W & ~opcode_mask) == valid instruction

Then before `print_insn_aarch64_word' has a chance to report the
instruction as potentially undefined, an attempt will be made to have
the qualifiers for the instruction's register operands (if any)
decoded.  If the relevant bits do not map onto a valid qualifier for
the matched instruction-like word, an abort will be triggered and the
execution of objdump aborted.

As this scenario is perfectly feasible and, in light of the fact that
objdump must successfully decode all sections of a given object file,
it is not appropriate to assert in this family of functions.

Therefore, we add a new pseudo-qualifier `AARCH64_OPND_QLF_ERR' for
handling invalid qualifier-associated values and re-purpose the
assertion conditions in qualifier-retrieving functions to be the
predicate guarding the returning of the calculated qualifier type.
If the predicate fails, we return this new qualifier and allow the
caller to handle the error as appropriate.

As these functions are called either from within
`aarch64_extract_operand' or `do_special_decoding', both of which are
expected to return non-zero values, it suffices that callers return
zero upon encountering `AARCH64_OPND_QLF_ERR'.

Ar present the error presented in the hypothetical scenario has been
encountered in `get_sreg_qualifier_from_value', but the change is made
to the whole family to keep the interface consistent.

Bug: https://sourceware.org/PR31595
2024-04-17 11:18:55 +01:00
Nick Clifton
3f6a060c75 Remove accidental commit of an experimental change 2024-04-16 15:06:34 +01:00
Fangrui Song
21061c384c Simplify readelf's RELR relocation display. 2024-04-16 13:17:35 +01:00
Vijay Shankar
ccbf42ec88 When mapping sections to segments ensure that we do not add sections whose VMA->LMA relationship does not match the relationship of earlier sections in the segment.
PR 31540
2024-04-15 16:27:21 +01:00
Alan Modra
0f8adbf77d Re: Fix null pointer dereference in process_debug_info()
read_bases has a potential null-pointer deref too, and without a
debug_info_p there isn't any point in calling read_bases.

	* dwarf.c (process_debug_info): Don't call read_bases when
	debug_info_p is NULL.
2024-04-12 09:00:52 +09:30
Nick Clifton
fcf8f3237c Improve readelf's display of RELR relocs. 2024-04-11 16:57:18 +01:00
Nick Clifton
8e8d0b63ff Add -j/--display-section option to readelf. 2024-04-11 15:57:26 +01:00
Alan Modra
ef70c9e7b2 Re: Update objcopy's --section-alignment option
ubsan: shift exponent 255 is too large for 64-bit type

I should have known oss-fuzz wouldn't be satisfied so easily.  The pef
format allows quite silly section alignments in object files.

	* objcopy.c (setup_section): Limit shift exponent when checking
	vma and lma for alignment.
2024-04-11 17:05:15 +09:30
Nick Clifton
ea83005a36 readelf: Add -j/--display-section command line option. 2024-04-10 12:23:44 +01:00
H.J. Lu
303da223b1 mmap: Avoid the sanitizer configure check failure
When -fsanitize=address,undefined is used to build, the mmap configure
check failed with

=================================================================
==231796==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d72b in main /home/alan/build/gas-san/all/bfd/conftest.c:239

Direct leak of 4096 byte(s) in 1 object(s) allocated from:
    #0 0x7cdd3d0defdf in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x5750c7f6d2e1 in main /home/alan/build/gas-san/all/bfd/conftest.c:190

SUMMARY: AddressSanitizer: 8192 byte(s) leaked in 2 allocation(s).

Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP to avoid the sanitizer
configure check failure.

bfd/

	* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

binutils/

	* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

ld/

	* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

libctf/

	* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

libsframe/

	* configure.ac: Replace AC_FUNC_MMAP with GCC_AC_FUNC_MMAP.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.
2024-04-10 03:57:46 -07:00
Christophe Lyon
54e2d897a6 Add missing install-dvi and install-ps Makefie targets.
For some reason, these targets are missing although others from the
same family are present. This looks like an oversight.

This enables calling 'make install-dvi' from the top-level build
directory.
2024-04-05 07:02:56 +00:00
Alan Modra
fab240554b Re: Update objcopy's --section-alignment option
ubsan: left shift of 1 by 31 places cannot be represented in type 'int'

	* objcopy.c (setup_section): Avoid undefined behaviour when
	checking vma and lma for alignment.
2024-04-04 21:02:29 +10:30
Nandakumar Edamana
1bc2544b89 dlltool: replace unchecked malloc with xmalloc 2024-04-04 17:58:50 +10:30
Nick Clifton
301bfc45ab Fix null pointer dereference in process_debug_info() 2024-04-03 11:19:33 +01:00
Nick Clifton
28b24770bb Extend objdump's --show-all-symbols option so that it also shows the extra symbols referenced by an instruction. 2024-04-03 11:17:19 +01:00
Nick Clifton
121a3f4b4f Update objcopy's --section-alignment option so that it sets the alignment flag on PE sections. Add a check for aligned sections not matching their VMAs. 2024-04-02 15:09:16 +01:00
Alan Modra
f37f8c46c2 objdump --disassemble=sym peculiarities
Given this testcase:
 .text
 mov $x1,%eax
f1:
 mov $f1,%eax
 .type f1,@function
 .size f1,.-f1

 mov $x2,%eax
f2:
 mov $f2,%eax
 .type f2,@function
 .size f2,.-f2+0x1000 #bad size

objdump --reloc --disassemble=f1 prints
00000000 <f1-0x5>:
   0:	b8 00 00 00 00       	mov    $0x0,%eax

and objdump --reloc --disassemble=f2 prints
0000000f <f2>:
   f:	b8 0f 00 00 00       	mov    $0xf,%eax
			10: R_386_32	.text

It seems for f1 we get the insn before f1 and no reloc whereas, post
159daa36fa, f2 is disassembled correctly.  Some analysis says that
find_symbol_for_address may return a symbol past the current address,
and reloc skipping is broken.  Fix both of these problems.

	* objdump.c (disassemble_jumps, disassemble_bytes): Replace
        relppp with relpp, ie. don't update caller's rel_pp.  Adjust
        calls.
	(disassemble_section): Skip over relocs inside loop rather
        than before loop.  Revert 7e538762c2.  If given a symbol,
	don't start disassembling until its address is reached.
	Correct end of function calculation.
2024-04-02 10:32:04 +10:30
Alan Modra
159daa36fa asan: heap-buffer-overflow objdump.c:3299 in disassemble_bytes
Fix yet another crash, this one with a fuzzed function symbol size.
The patch also corrects objdump behaviour when both --disassemble=sym
and --stop-address=value are given.  Previously --disassemble=sym
overrode --stop-address, now we take the lower of the stop-address
value and the end of function.

	* objdump.c (disassemble_section): Sanity check ELF st_size.
2024-04-01 21:21:51 +10:30
H.J. Lu
bb9a951fab Don't claim a fat IR object if no IR object should be claimed
When the linker sees an input object containing nothing but IR during
rescan, it should ignore it (LTO phase is over).  But if the input object
is a fat IR object, which has non-IR code as well, it should be used to
resolve references as if it did not contain any IR at all.  This patch
adds lto_type to bfd and linker avoids claiming a fat IR object if no IR
object should be claimed.

bfd/

	PR ld/23935
	* archive.c (_bfd_compute_and_write_armap): Check bfd_get_lto_type
	instead of lto_slim_object.
	* elflink.c (elf_link_add_object_symbols): Likewise.
	* bfd.c (bfd_lto_object_type): New.
	(bfd): Remove lto_slim_object and add lto_type.
	(bfd_get_lto_type): New function.
	* elf.c (lto_section): Removed.
	(_bfd_elf_make_section_from_shdr): Don't set lto_slim_object.
	* format.c: (lto_section): New.
	(bfd_set_lto_type): New function.
	(bfd_check_format_matches): Call bfd_set_lto_type.
	* bfd-in2.h: Regenerated.

binutils/

	PR ld/23935
	* nm.c (display_rel_file): Check bfd_get_lto_type instead of
	lto_slim_object.

ld/

	PR ld/23935
	* ldmain.c (add_archive_element): Don't claim a fat IR object if
	no IR object should be claimed.
	* testsuite/ld-plugin/lto.exp (pr20103): Adjust fat IR test.
	Add PR ld/23935 test.
	* testsuite/ld-plugin/pr23935a.c: New file.
	* testsuite/ld-plugin/pr23935b.c: Likewise.
2024-03-26 07:17:17 -07:00
Andrew Burgess
f9ee45c3a9 bfd: make _bfd_section_size_insane part of the public API
If a BFD user is making use of a function like
bfd_get_section_contents to read a section into a pre-allocated
buffer, then that BFD user might also want to make use of
_bfd_section_size_insane prior to allocating the buffer they intend to
use in order to validate that the buffer size that plan to allocate is
sane.

This commit makes _bfd_section_size_insane public, by renaming it to
bfd_section_size_insane.

I've updated the existing uses within bfd/, I don't believe this
function is used outside of bfd/ currently.

One place that I plan to make use of this function is in
gdb/gdb_bfd.c, in the function gdb_bfd_get_full_section_contents.
This change isn't included in this commit, but will come later if/when
this has been merged into bfd.

There should be no change in behaviour after this commit.

bfd/

	* bfd-in2.h (bfd_section_size_insane): Add declaration.
	* compress.c (bfd_get_full_section_contents): Update for new name
	of _bfd_section_size_insane.
	(bfd_init_section_compress_status): Likewise.
	* dwarf2.c (read_section): Likewise.
	(_bfd_dwarf2_slurp_debug_info): Likewise.
	* libbfd.h (_bfd_section_size_insane): Remove declaration.
	* section.c (_bfd_section_size_insane): Rename to ...
	(bfd_section_size_insane): ... this.

binutils/

	* readelf.c (uncompress_section_contents): Update comment to
	account for new name of _bfd_section_size_insane.
2024-03-25 18:31:38 +00:00
Nick Clifton
696f6b6660 Remove redunant test of ELF size in core note decoder.
PR 31469
2024-03-19 15:17:23 +00:00
Nick Clifton
709b8d140b Fix seg-fault in the DWARF reader code when accessing an abbreviatuin table with a corrupt entry offset.
PR 31456
2024-03-19 14:16:47 +00:00
Stephen Kitt
64e215c15b tests: force non-deterministic mode in non-deterministic tests
Since ar can be built defaulting to deterministic mode, tests which
expect non-deterministic behaviour need to explicitly set the U flag.

The non-deterministic member test expects SOURCE_DATE_EPOCH to not be
set; this documents that. Unconditionally unsetting the variable
causes issues in test infrastructure (which expects unsetenv to only
be called on variables which are already set).

Signed-off-by: Stephen Kitt <steve@sk2.org>
2024-03-11 08:21:47 +01:00
Nick Clifton
164cc86b81 Add "-j1" to make command lines in the create-a-release README. 2024-03-06 10:57:39 +00:00
Jens Remus
75a28d1a97 s390: Print base register 0 as "0" in disassembly
Base and index register 0 have no effect in address computation:

"A value of zero in the B [base] or X [index] field specifies that no
base or index is to be applied, and, thus, general register 0 cannot be
designated as containing a base address or index."
IBM z/Architecture Principles of Operation [1], chapter "Organization",
section "General Registers".

Index register 0 is omitted in the s390 disassembly. Base register 0 is
omitted in D(B), D(L,B) and D(X,B) - the latter only if the index
register is zero.

To make it more apparent print base register 0 as "0" instead of "%r0",
whenever it would still be printed in the disassembly.

[1]: IBM z/Architecture Principles of Operation, SA22-7832-13,
     https://publibfp.dhe.ibm.com/epubs/pdf/a227832d.pdf

opcodes/
	* s390-dis.c: Print base register 0 as "0" in disassembly.

binutils/
	* NEWS: Mention base register 0 now being printed as "0" in s390
	disassembly.

gas/
	* testsuite/gas/s390/zarch-base-index-0.d: Update test case
	output verification patterns to accept "0" as base base
	register due to disassembler output format change.
	* gas/testsuite/gas/s390/zarch-omitted-base-index.d: Likewise.

Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2024-03-01 12:45:14 +01:00
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
Nick Clifton
bf4f7759ed Update how-to-make-a-release document to reference new git repository for the documentation 2024-02-16 12:04:59 +00:00
Frederic Cambus
d86205c3ec Add support to readelf for the PT_OPENBSD_SYSCALLS segment type.
binutils * readelf.c (get_segment_type): Handle PT_OPENBSD_SYSCALLS segment type.
include  * elf/common.h (PT_OPENBSD_SYSCALLS): Define.
2024-02-12 17:09:13 +00:00
Peter Bergner
4199cf1e15 PowerPC: Add support for Power11 options
binutils/
	* doc/binutils.texi (PowerPC -M option): Mention power11 and pwr11.

gas/
	* config/tc-ppc.c: (md_show_usage): Mention -mpower11 and -mpwr11.
	* doc/c-ppc.texi: Likewise.

opcodes/
	* ppc-dis.c (ppc_opts): Add "power11" and "pwr11" entries.
	(powerpc_init_dialect): Default to "power11".
2024-02-09 10:52:23 -06:00
Richard W.M. Jones
3f8f9745c7 PR 31283 windmc: Parse input correctly on big endian hosts
On big endian hosts (eg. s390x) the windmc tool fails to parse even
trivial files:

  $ cat test.mc
  ;
  $ ./binutils/windmc ./test.mc
  In test.mc at line 1: parser: syntax error.
  In test.mc at line 1: fatal: syntax error.

The tool starts by reading the input as Windows CP1252 and then
converting it internally into an array of UTF-16LE, which it then
processes as an array of unsigned short (typedef unichar).

There are lots of ways this is wrong, but in the specific case of big
endian machines the little endian pairs of bytes are byte-swapped.

For example, the ';' character in the input above is first converted
to UTF16-LE byte sequence { 0x3b, 0x00 }, which is then cast to
unsigned short.  On a big endian machine the first unichar appears to
be 0x3b00.  The lexer is unable to recognize this as the comment
character ((unichar)';') and so parsing fails.

The simple fix is to convert the input to UTF-16BE on big endian
machines (and do the reverse conversion when writing the output).

Fixes: https://sourceware.org/bugzilla/show_bug.cgi?id=31283
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
2024-02-08 12:14:40 +10:30
Alan Modra
3ef23ee926 memory leak in objdump disassemble_section
* objdump.c (disassemble_section): Free rel_ppstart on error path.
2024-02-07 21:28:24 +10:30
Sandra Loosemore
e4d85860c2 MAINTAINERS: Update my e-mail address. 2024-02-01 22:57:31 -07:00
Nick Clifton
f3911963c5 Update release making documentation after 2.42 release 2024-01-29 16:11:52 +00:00
H.J. Lu
1b06334552 elf: Rename is_standard_elf to uses_elf_em
Rename is_standard_elf to uses_elf_em for targets which use elf.em.

binutils/

	PR ld/31289
	* testsuite/lib/binutils-common.exp (is_standard_elf): Renamed
	to ...
	(uses_elf_em): This.

ld/

	PR ld/31289
	* testsuite/ld-elf/fatal-warnings-2a.d: Replace is_standard_elf
	with uses_elf_em.
	* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
2024-01-26 07:32:03 -08:00
Nick Clifton
c8567a87a6 Fix: Stripping Rust static libraries fails because of overly zealous illegal path check
PR 31250
  * objcopy.c (copy_archive): Improve the handling of archives that contain elements with invalid pathnames.
2024-01-26 11:54:08 +00: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
H.J. Lu
eb12b17047 elf: Add is_standard_elf
PR ld/31289 tests failed for fr30-elf, frv-elf, ft32-elf, iq2000-elf,
mn10200-elf, ms1-elf and msp430-elf targets:

FAIL: ld-elf/fatal-warnings-2a
FAIL: ld-elf/fatal-warnings-2b
FAIL: ld-elf/fatal-warnings-3a
FAIL: ld-elf/fatal-warnings-3b
FAIL: ld-elf/fatal-warnings-4a
FAIL: ld-elf/fatal-warnings-4b

even though PR ld/31289 targets xfail for [is_generic] targets.  These
targets not only don't use the generic_link_hash_table linker, but also
don't use the standard ELF emulation.  Add is_standard_elf for ELF
targets which use the standard ELF emulation and replace [is_generic]
with ![is_standard_elf] in PR ld/31289 tests.

binutils/

	PR ld/31289
	* testsuite/lib/binutils-common.exp (is_standard_elf): New.

ld/

	PR ld/31289
	* testsuite/lib/binutils-common.exp (is_generic): Return 1 for
	fr30-*-*, frv-*-elf, ft32-*-*, iq2000-*-*, mn10200-*-*,
	moxie-*-moxiebox*, msp430-*-* and mt-*-*.
	* testsuite/ld-elf/fatal-warnings-2a.d: Replace [is_generic]
	with ![is_standard_elf].
	* testsuite/ld-elf/fatal-warnings-2b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-3b.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4a.d: Likewise.
	* testsuite/ld-elf/fatal-warnings-4b.d: Likewise.
2024-01-25 10:17:46 -08:00
Paul Iannetta
ab9bb4101c Add myself as the KVX port maintainer
binutils/ChangeLog:

	* MAINTAINERS: Add myself as the KVX port maintainer.
2024-01-24 09:25:57 +01:00
Mark Wielaard
91e9420f18 binutils: Fix calloc argument order in srconv.c
GCC 14 will warn about calling calloc with swapped size and count
arguments.

binutils/srconv.c: In function ‘nints’:
binutils/srconv.c:598:36: error: ‘xcalloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  598 |   return (int *) (xcalloc (sizeof (int), x));
      |                                    ^~~
binutils/srconv.c:598:36: note: earlier argument should specify number of elements, later size of each element

binutils/

	* srconv.c (nints): Swap xcalloc arguments.
	(wr_du): Likewise.
	(wr_dus): Likewise.
2024-01-22 18:20:21 +01:00
Mark Wielaard
dd0c018e72 binutils: Fix calloc argument order in coffgrok.c
GCC 14 will warn about calling calloc with swapped size and count
arguments.

binutils-gdb/binutils/coffgrok.c: In function ‘do_sections_p1’:
binutils-gdb/binutils/coffgrok.c:116:72: error: ‘xcalloc’ sizes specified with ‘sizeof’ in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  116 |   struct coff_section *all = (struct coff_section *) (xcalloc (sizeof (struct coff_section),
      |                                                                        ^~~~~~
binutils-gdb/binutils/coffgrok.c:116:72: note: earlier argument should specify number of elements, later size of each element

binutils/

	* coffgrok.c (empty_scope): Swap xcalloc arguments.
	(empty_symbol): Likewise.
	(do_lines): Likewise.
	(doit): Likewise.
	(coff_grok): Likewise.
2024-01-22 18:19:43 +01:00
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
Nick Clifton
bfdd2ca621 Updated translations for various sub-directories 2024-01-18 11:23:48 +00:00
Nick Clifton
0fb9921b9e Update HOWTO document after creating the 2.42 branch 2024-01-15 15:35:01 +00:00
Nick Clifton
e775d3a9b7 Change version to 2.42.50 and regenerate files 2024-01-15 15:13:36 +00:00
Nick Clifton
299b91cd85 Add markers for 2.42 branch 2024-01-15 14:42:15 +00:00
Nick Clifton
422cbe7c17 Update branch/release creation documentation 2024-01-15 14:21:37 +00:00
Nick Clifton
fad00902c2 nm: Replace --with-symbol-versions with --without-symbol-versions in --help output
PR 31243
  nm: Fix --help output
2024-01-15 12:25:00 +00:00
Joseph Myers
30a9c613df MAINTAINERS: Update my email address 2024-01-08 18:55:03 +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
Joseph Myers
b383acf248 MAINTAINERS: Update my email address
There will be another update in January.
2023-12-30 00:32:00 +00:00
Schimpe, Christina
eccdc733a5 x86: Add NT_X86_SHSTK note
Define NT_X86_SHSTK which is the note for x86 Shadow Stack (SHSTK) to
support Intel SHSTK in Linux kernel.
For now only userspace shadow stack and kernel IBT are supported by the
linux kernel.  This note should be used instead of NT_X86_CET introduced
in the commit "x86: Add NT_X86_CET note", as it is outdated and only
used by old binutils versions.
2023-12-28 07:51:14 -08:00
Alan Modra
145c21056a PR31191, objcopy leaves temporary files
Fix the ENOTDIR rmdir too.

	PR 31191
	* objcopy.c (copy_archive): Localise uses of "l".  Remove
	const from name_list.name.  Unlink output element on bfd_close
	error, and NULL list->name to indicate file is removed.  Adjust
	cleanup to prevent rmdir on non-existent file.
2023-12-27 16:34:39 +10:30
Mike Frysinger
ca86dbbdbc binutils: SECURITY: use https URI 2023-12-25 00:11:30 -05:00
Jens Remus
f96fe7f454 s390: Optionally print instruction description in disassembly
Print instruction description as comment in disassembly with s390
architecture specific option "insndesc":

- For objdump it can be enabled with option "-M insndesc"
- In gdb it can be enabled with "set disassembler-options insndesc"

Since comments are not column aligned the output can enhanced for
readability by postprocessing using a filter such as "expand":

... | expand -t 8,16,24,32,40,80

Or when using in combination with objdump option --visualize-jumps:

... | expand | sed -e 's/ *#/\t#/' | expand -t 1,80

Note that the instruction descriptions add about 128 KB to s390-opc.o:

s390-opc.o without instruction descriptions: 216368 bytes
s390-opc.o with instruction descriptions   : 348432 bytes

binutils/
	* NEWS: Mention new s390-specific disassembler option
	  "insndesc".

include/
	* opcode/s390.h (struct s390_opcode): Add field to hold
	  instruction description.

opcodes/
	* s390-mkopc.c: Copy instruction description from s390-opc.txt
	  into generated operation code table s390-opc.tab.
	* s390-opc.c (s390_opformats): Provide NULL as description in
	  .insn pseudo-mnemonics opcode table.
	* s390-dis.c: Add s390-specific disassembler option "insndesc"
	  and optionally print the instruction description as comment in
	  the disassembly when it is specified.

gas/
	* testsuite/gas/s390/s390.exp: Add new test disassembly test
	  case "zarch-insndesc".
	* testsuite/gas/s390/zarch-insndesc.s: New test case for s390-
	  specific disassembler option "insndesc".
	* testsuite/gas/s390/zarch-insndesc.d: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Andreas Krebbel <krebbel@linux.ibm.com>
2023-12-20 11:50:32 +01:00
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
3c8852fcc8 PR31096, nm shows 32bit addresses as 64bit addresses
Prior to commit 0e3c1eebb2 nm output depended on the host unsigned
long when printing "negative" symbol values for 32-bit targets.
Commit 0e3c1eebb2 made the output match that seen with a 64-bit host
unsigned long.  The fact that nm output changed depending on host is
of course a bug, but it is reasonable to expect 32-bit target output
is only 32 bits.  So this patch makes 32-bit target output the same as
it was on 32-bit hosts prior to 0e3c1eebb2.

	PR 31096
	* nm.c (print_format_string): Make it a static buffer.
	(get_print_format): Merge into..
	(set_print_format): ..this, renamed from set_print_width.  When
	print_width is 32, set up print_format_string for an int32_t
	value.  Don't malloc print_format_string.  Adjust calls.
	(print_value): Correct printing of 32-bit values.
2023-12-06 12:23:05 +10:30
Andreas Schwab
1b183017aa Add basic support for RISC-V 64-bit EFI objects
This adds a new PEI target pei-riscv64-little.  Only objdump and objcopy
are supported.

bfd:
	* .gitignore: Add pe-riscv64igen.c.
	* Makefile.am (BFD64_BACKENDS): Add pei-riscv64.lo,
	pe-riscv64igen.lo.
	(BFD64_BACKENDS_CFILES): Add pei-riscv64.c.
	(BUILD_CFILES): Add pe-riscv64igen.c.
	(pe-riscv64igen.c): New rule.
	* Makefile.in: Regenerate.
	* bfd.c (bfd_get_sign_extend_vma): Add pei-riscv64-little.
	* coff-riscv64.c: New file.
	* coffcode.h (coff_set_arch_mach_hook, coff_set_flags)
	(coff_write_object_contents): Add riscv64 (riscv64_pei_vec)
	support.
	* config.bfd (targ_selvecs): Add riscv64_pei_vec to all riscv*
	targets.
	* configure.ac: Handle riscv64_pei_vec.
	* configure: Regenerate.
	* libpei.h (GET_OPTHDR_IMAGE_BASE, PUT_OPTHDR_IMAGE_BASE)
	(GET_OPTHDR_SIZE_OF_STACK_RESERVE)
	(PUT_OPTHDR_SIZE_OF_STACK_RESERVE)
	(GET_OPTHDR_SIZE_OF_STACK_COMMIT, PUT_OPTHDR_SIZE_OF_STACK_COMMIT)
	(GET_OPTHDR_SIZE_OF_HEAP_RESERVE, PUT_OPTHDR_SIZE_OF_HEAP_RESERVE)
	(GET_OPTHDR_SIZE_OF_HEAP_COMMIT, PUT_OPTHDR_SIZE_OF_HEAP_COMMIT)
	(GET_PDATA_ENTRY, _bfd_XX_bfd_copy_private_bfd_data_common)
	(_bfd_XX_bfd_copy_private_section_data)
	(_bfd_XX_get_symbol_info, _bfd_XX_only_swap_filehdr_out)
	(_bfd_XX_print_private_bfd_data_common)
	(_bfd_XXi_final_link_postscript, _bfd_XXi_only_swap_filehdr_out)
	(_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
	(_bfd_XXi_swap_aux_in, _bfd_XXi_swap_aux_out)
	(_bfd_XXi_swap_lineno_in, _bfd_XXi_swap_lineno_out)
	(_bfd_XXi_swap_scnhdr_out, _bfd_XXi_swap_sym_in)
	(_bfd_XXi_swap_sym_out, _bfd_XXi_swap_debugdir_in)
	(_bfd_XXi_swap_debugdir_out, _bfd_XXi_write_codeview_record)
	(_bfd_XXi_slurp_codeview_record) [COFF_WITH_peRiscV64]: Define.
	(_bfd_peRiscV64_print_ce_compressed_pdata): Declare.
	* peXXigen.c (_bfd_XXi_swap_aouthdr_in, _bfd_XXi_swap_aouthdr_out)
	(_bfd_XXi_swap_scnhdr_out, pe_print_pdata)
	(_bfd_XX_print_private_bfd_data_common)
	(_bfd_XX_bfd_copy_private_section_data)
	(_bfd_XXi_final_link_postscript): Support COFF_WITH_peRiscV64.
	* pei-riscv64.c: New file.
	* peicode.h (coff_swap_scnhdr_in, pe_ILF_build_a_bfd)
	(pe_ILF_object_p): Support COFF_WITH_peRiscV64.
	(jtab): Add dummy entry that traps.
	* targets.c (_bfd_target_vector): Add riscv64_pei_vec.

binutils:
	* testsuite/binutils-all/riscv/pei-riscv64.d: New.
	* testsuite/binutils-all/riscv/pei-riscv64.s: New.

include:
	* coff/riscv64.h: New file.
	* coff/pe.h (IMAGE_FILE_MACHINE_RISCV32)
	(IMAGE_FILE_MACHINE_RISCV64): Define.
2023-12-05 13:20:27 +01:00