Commit Graph

4884 Commits

Author SHA1 Message Date
Jose E. Marchesi
0e7ca0fdc8 binutils/MAINTAINERS: list new gprofng maintainers
As agreed with Nick I will be co-maintaining gprofng moving forward
along with Claudiu.  Update the MAINTAINERS file accordingly.
2025-11-05 20:33:07 +01:00
Nick Clifton
12ef7d5b7b Remove call to abort in the DGB debug format printing code, thus allowing the display of a fuzzed input file to complete without triggering an abort.
PR 33448
2025-11-03 11:49:02 +00:00
Alan Modra
87b6078fc2 tidy m4 plugin config support
In CLANG_PLUGIN_FILE it is possible for plugin_file to be non-NULL
when LLVMgold.so does not exist.

configure output is messy, with results not printed against their
  "checking.." line, eg.
checking for clang... (cached) yes
checking for clang plugin file... checking for x86_64-pc-linux-gnu-ar... (cached) ar --plugin /usr/lib/llvm-20/lib/clang/20/../../LLVMgold.so
/usr/lib/llvm-20/lib/clang/20/../../LLVMgold.so

This patch fixes those problems, and a similar interposition of other
configure output between AC_MSG_CHECKING and AC_MSG_RESULT in
gcc-plugin.m4.  It also tidies some of the message text, and makes
similar code in gcc-plugin.m4 and clang-plugin.m4 a little more
consistent.

config/
	* clang-plugin.m4 (CLANG_PLUGIN_FILE): Don't place checks for
	tools (llvm-config, ar) inside AC_MSG_CHECKING..AC_MSG_RESULT
	for clang plugin file.  Clear plugin_file before loop exit.
	(CLANG_PLUGIN_FILE_FOR_TARGET): Similarly.
	* gcc-plugin.m4 (GCC_PLUGIN_OPTION): Similarly.
	(GCC_PLUGIN_OPTION_FOR_TARGET): Correct AC_MSG_CHECKING.  Tidy
	return code.
binutils/
	* testsuite/lib/binutils-common.exp <llvm_plug_opt>: Set for
	non-native.
	* configure: Regenerate.
/
	* configure: Regenerate.
bfd/
	* configure: Regenerate.
gas/
	* configure: Regenerate.
gdb/
	* configure: Regenerate.
gprof/
	* configure: Regenerate.
gprofng/
	* configure: Regenerate.
	* libcollector/configure: Regenerate.
ld/
	* configure: Regenerate.
libbacktrace/
	* configure: Regenerate.
libctf/
	* configure: Regenerate.
libiberty/
	* configure: Regenerate.
libsframe/
	* configure: Regenerate.
opcodes/
	* configure: Regenerate.
sim/
	* configure: Regenerate.
zlib/
	* configure: Regenerate.
2025-11-03 10:59:50 +10:30
Alan Modra
0bb5cbb9b4 Pass -B to objcopy binary symbol test
objcopy -I binary -O some_coff_target does not currently work without
choosing a valid arch with -B.  This used to be the case for ELF
targets too, until commit 6765ee1825.

	* testsuite/binutils-all/objcopy.exp (binary_symbol): Pass
	-B arch to objcopy.  Choose different output object files for
	the two tests.
2025-10-31 09:44:38 +10:30
Alon Bar-Lev
6fa97b38ff objcopy: add option to specify custom prefix for symbol of binary input
When using --input-target=binary, objcopy currently derives symbol names
from a mangled version of the input file name.  This approach can lead to
unpredictable results, as the generated symbols depend on the file path and
working directory.

This patch introduces a new option:

  --binary-symbol-prefix <prefix> Use <prefix> as the base symbol name for
                                    the input file (default: derived from
                                    file name)

It allows specifying an explicit symbol prefix, while preserving the existing
behavior as a fallback.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
2025-10-30 15:32:52 +10:30
Pietro Monteiro
4cfcc5412c objcopy: Don't add zstd to the debug compression options if not available
If zstd is not available or was intentionally disabled by the user
don't add it to the list of the available options to compress debug
sections when showing usage.

binutils/
	* objcopy.c (copy_usage): Only output
	--compress-debug-sections=zstd if HAVE_ZSTD.
2025-10-22 13:49:05 +10:30
Jens Remus
5079bf8959 gas: sframe: Represent .cfi_undefined RA as FRE without offsets
In DWARF CFI an "undefined" register rule for the return address (RA)
register indicates that there is no return address and the stack trace
is complete.

Represent DW_CFA_undefined as SFrame FRE without any offsets, so that a
stack tracer implementation can use this as indication that an outermost
frame has been reached and the stack trace is complete.

This representation is backward compatible, as existing stack tracers
should already deal with the case, that an SFrame FRE a so far invalid
offset count of zero and stop the trace.

include/
	* sframe.h (SFRAME_V2_FRE_RA_UNDEFINED_P): New macro to test
	FRE info word for RA undefined (FRE without any offsets).

binutils/
	* NEWS: Mention SFrame can represent an undefined RA as FRE
	without	any offsets.

gas/
	* gen-sframe.h (struct sframe_row_entry): Add ra_undefined_p
	flag.
	* gen-sframe.c (sframe_row_entry_new): Initialize ra_undefined_p
	flag to not set.
	(sframe_row_entry_initialize): Treat ra_undefined_p flag as
	sticky.
	(sframe_fre_set_ra_track): Reset ra_undefined_p flag.
	(sframe_xlate_do_restore): Reset ra_undefined_p flag to saved
	state.
	(sframe_xlate_do_same_value): Reset ra_undefined_p flag.
	(sframe_xlate_do_cfi_undefined): For RA set ra_undefined_p flag.
	(output_sframe_row_entry): Represent RA undefined as SFrame FRE
	without any offsets and FRE info word fields zeroed.
	* NEWS: Mention assembler represents .cfi_undefined RA in SFrame
	as FRE without any offsets.

libsframe/
	* doc/sframe-spec.texi (Changes from Version 1 to Version 2):
	Mention that a SFrame FRE without any offsets flag indicates an
	outermost frame with an undefined RA.
	(fre_offset_count): Document that a FRE offset count of zero
	indicates an outermost frame with an undefined RA.
	* sframe.c (sframe_get_fre_ra_undefined_p): Use macro
	SFRAME_V2_FRE_RA_UNDEFINED_P.
	(sframe_fre_get_fp_offset, sframe_fre_get_ra_offset): Do not
	return fixed FP/RA offset if RA undefined.
	* sframe-dump.c (dump_sframe_func_with_fres): Show FRE without
	any offsets as "RA undefined".

gas/testsuite/
	* gas/cfi-sframe/cfi-sframe.exp: Run tests for .cfi_undefined RA
	on AArch64, s390x, and x86-64.
	* gas/cfi-sframe/cfi-sframe-aarch64-ra-undefined-1.d: Add test
	for .cfi_undefined RA on AArch64.
	* gas/cfi-sframe/cfi-sframe-aarch64-ra-undefined-1.s: Likewise.
	* as/cfi-sframe/cfi-sframe-s390x-ra-undefined-1.d: Add test
	for .cfi_undefined RA on s390x.
	* gas/cfi-sframe/cfi-sframe-s390x-ra-undefined-1.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-ra-undefined-1.d: Add test
	for .cfi_undefined RA on x86-64.
	* gas/cfi-sframe/cfi-sframe-x86_64-ra-undefined-1.s: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-10-15 17:45:48 +02:00
Nick Clifton
c0316a54b4 Add a position statement about LLM generated content 2025-10-13 15:16:12 +01:00
Nick Clifton
f039dfba55 Add note about how to obtain permission to upload new releases 2025-10-13 15:14:42 +01:00
Jan Beulich
b8c152b9a9 objdump: enable PE support for Interix
This is just so the target won't need excluding in a forthcoming new
testcase. Without doing so objdump would fail saying "option -P/--private
not supported by this file".
2025-10-10 15:59:18 +02:00
Hans-Peter Nilsson
c1a7d03958 cris: bfd: Default selected target to the configured target
Whether targ_defvec is set to the best match for the configured target
or some of the other supported targets usually doesn't matter, as the
actual target being used, usually is set by some other mechanism, like
an input object file.

In some situations it matters though: it might be confusing to see
--help output not showing the configured target first in the list of
supported targets.  Also, some corner cases risk running into bugs like
PR33485, for cris-elf and cris-linux because cris_aout_vec is the
default target where instead the bug-free behavior of
cris_elf32_us_vec or cris_elf32_vec would be expected.

The test just verifies that the target list emitted for the --help
option has the expected target first.

bfd:

	* config.bfd <cris-*-* | crisv32-*-*>: Split into <cris-*-*aout*>,
	<cris-*-linux-* | crisv32-*-linux-*>, <cris-*-* | crisv32-*-*> cases
	respectively setting targ_defvec per the target instead of always
	cris_aout_vec.

binutils:

	* testsuite/binutils-all/cris: New directory intended for
	tests focused on behavior of the binutils programs, not the assembler
	or linker.
	* testsuite/binutils-all/cris/cris.exp: New file with run_dump_test
	loop.
	testsuite/binutils-all/cris/tgt-a.d,
	testsuite/binutils-all/cris/tgt-e.d,
	testsuite/binutils-all/cris/tgt-l.d: New tests.

Co-authored-by: Maciej W. Rozycki <macro@redhat.com>
2025-10-08 05:44:48 +02:00
Alan Modra
049a70652a segv in debug_write_type
In commit 6c3458a8b7 I claimed that u.kenum is always non-NULL,
which is true for debug_make_enum_type, but not for enums made by
debug_make_undefined_tagged_type.  Fix that oversight

	PR 32829
	* debug.c (debug_write_type): Handle NULL u.kenum.
	(debug_type_samep): Likewise.
2025-10-06 13:31:31 +10:30
Alan Modra
236cf2bf60 readelf reloc range check
A fuzzed object file hit this sanitizer error.
readelf.c:16764:9: runtime error: pointer index expression with base
0x6dd4491e1590 overflowed to 0xe7af96d4491e17a1

The same could occur in any of the IN_RANGE reloc checks, where the
reloc address is calculated as "start + r_offset" then compared
against "start" and "end".  So don't do that.  Compare r_offset
against the memory size, first.

	* readelf.c (IN_RANGE): Delete.
	(in_range): New inline funcion.
	(target_specific_reloc_handling): Replace "end" param with
	"size".  Update uses.  Replace IN_RANGE with in_range.
	(apply_relocations): Delete "end" variable.  Update
	target_specific_reloc_handling calls and replace IN_RANGE.
	Avoid pointer overflow.
2025-10-06 13:31:31 +10:30
Jan Beulich
d94cdcc881 Dwarf: adjust fetch_indirect{,_line}_string()'s return type
As already is the case for fetch_indexed_string() and
fetch_alt_indirect_string(), have them return a pointer to plain char,
properly compatible with e.g. the %s format specifier that the return
values are used with in several cases. This way no casts at call sites are
necessary, and several (bogus) ones in the functions can be exchanged for
just one each. Some other constification is needed elsewhere, now that
const-ness isn't being cast away anymore.
2025-09-26 12:21:11 +02:00
H.J. Lu
4f62e7d83f Binutils: Add clang LTO support to AR and RANLIB
Detect the clang plugin file and and pass it to --plugin for ar and ranlib
so that binutils can be built with clang LTO.

bfd/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

binutils/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

gas/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

gprof/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.
	* testsuite/Makefile.in: Likewise.

gprofng/

	PR binutils/33470
	* Makefile.am (ACLOCAL_AMFLAGS): Add -I ../config.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.
	* gp-display-html/Makefile.in: Likewise.
	* libcollector/Makefile.in: Likewise.
	* libcollector/aclocal.m4: Likewise.
	* libcollector/configure: Likewise.
	* src/Makefile.in: Likewise.
	* libcollector/Makefile.am (ACLOCAL_AMFLAGS): Add -I ../../config.

ld/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

libctf/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

libsframe/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

opcodes/

	PR binutils/33470
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-25 12:30:13 +08:00
Nick Clifton
3b465bc232 Updated and new translations for the binutils 2025-09-18 11:56:52 +01:00
Richard Earnshaw
c2e7c05ad4 binutils: testsuite: fix duplicate testnames in readelf.exp
There are two places in readelf.exp where we generate duplicate
testnames.

The first is due to calling readelf_find_size twice with the same
iteration index (2).  This is fixed by using 4 for the second
instance.

The other is at the end of readelf_thin_archive_test.  This test calls
readelf_test before unconditionally passing.  It happens to construct
exactly the same test name as readelf test (might not be a
coincidence), so we end up with a duplicate test.  But it seems wrong
anyway to 'pass' a test that readelf_test might have failed, so simply
delete this duplicate pass entry.
2025-09-16 17:15:57 +01:00
Richard Earnshaw
f52a9a2b06 binutils: testsuite: avoid dup names when using multiple as: directives
binutils tests support running a test with distinct options to the
assembler by allowing

	#as: <optset-1>
	#as: <optset-2>

But results in both test runs using the same test name in the summary
file.  This causes confusion if one test fails but the other doesn't
(and GCC's compare_tests script will diagnose this as an error).  To
fix the ambiguity append the appropriate optset to the test name.

We only do this if a test has multiple runs in this way to avoid
causing every test result name to change.
2025-09-16 10:31:11 +01:00
H.J. Lu
45f3ea0bbb Revert "binutils: Require GNU tail for 'objdump -Wi' test"
This reverts commit 897d8d7bba.
2025-09-10 05:15:55 -07:00
Alan Modra
aa644b6710 readelf: tidy dump_relr_relocations
A comment in display_relocations said "RELRS has been freed by
dump_relr_relocations".  Except that hadn't happened on all return
paths.  Tidy that by freeing relrs allocated in dump_relr_relocations
in that function, and relrs allocated in display_relocation in that
function.

	* readelf.c (dump_relr_relocations): Only free relrs allocated
	in this function.
	(display_relocations): Free relrs here, on error return paths
	too.
2025-09-10 06:51:22 +09:30
Andrew C Aitchison
d67c8954d0 Correct -Ue output for nm, objdump and readelf
..., like PR33360 does for strings.

Signed-off-by: Andrew C Aitchison <github@aitchison.me.uk>
2025-09-09 12:06:42 +02:00
Dmitry Klochkov
7be4186c22 nm: fix treating an ifunc symbol as a stab if '--ifunc-chars=--' is given
If an ifunc symbol is processed in print_symbol(), a 'type' field of a
'syminfo' structure is set to any character specified by a user with an
'--ifunc-chars' option.  But afterwards the 'type' field is used to
check whether a symbol is a stab in print_symbol_info_{bsd,sysv}()
functions in order to print additional stab related data.  If the 'type'
field equals '-', a symbol is treated as a stab.  If '--ifunc-chars=--'
is given, all ifunc symbols will be treated as stab symbols and
uninitialized stab related fields of the 'syminfo' structure will be
printed which can lead to segmentation fault.

To fix this, check if a symbol is a stab before override the 'type'
field.  Also, add a test case for this fix.

	PR binutils/32556
	* nm.c (extended_symbol_info): Add is_stab.
	(print_symbol): Check if a symbol is a stab.
	(print_symbol_info_bsd): Use info->is_stab.
	(print_symbol_info_sysv): Use info->is_stab.
	* testsuite/binutils-all/nm.exp: Test nm --ifunc-chars=--.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32556
Fixes: e6f6aa8d18 ("Add option to nm to change the characters displayed for ifunc symbols")
Signed-off-by: Dmitry Klochkov <dmitry.klochkov@bell-sw.com>
2025-09-09 12:06:25 +02:00
Alan Modra
f87a66db64 PR 33406 SEGV in dump_dwarf_section
Trying to dump .sframe in a PE file results in a segfault accessing
elf_section_data.

	* objdump (dump_sframe_section, dump_dwarf_section): Don't access
	elf_section_type without first checking the file is ELF.
2025-09-09 18:55:26 +09:30
Nick Clifton
3ac272c1f1 objcopy: when an invalid bfd target string is used as a target option, print an error message that references the target string, not the file being copied 2025-09-09 08:57:38 +01:00
Alan Modra
7ab2cbe8d0 objdump gcc_compiled and gcc2_compiled
* objdump.c (remove_useless_symbols): Deal with gcc_compiled
	and gcc2_compiled here..
	(compare_symbols): ..rather than here..
	(disassemble_section): ..and here.
2025-09-09 17:20:03 +09:30
Alan Modra
5d56bdcd71 Revert "objdump: Check the SEC_CODE bit for code"
PR 33389
This reverts commit 6b27a22032.
2025-09-09 17:19:39 +09:30
H.J. Lu
897d8d7bba binutils: Require GNU tail for 'objdump -Wi' test
testsuite/binutils-all/objdump.exp has

set got [remote_exec host "tail -n +4 tmpdir/objdump.out" "" "/dev/null" "tmpdir/objdump.tail"]

But the default Solaris tail doesn't support "tail -n +4".  Add
ACX_PROG_GNU_TAIL to use GNU tail for 'objdump -Wi' test.

Tested on Linux and Solaris.

binutils/

	PR binutils/33396
	* Makefile.am (check-DEJAGNU): Also export TAIL.
	* Makefile.in: Regenerated.
	* aclocal.m4: Likewise.
	* configure: Likewise.
	* configure.ac: Add ACX_PROG_GNU_TAIL.
	* testsuite/binutils-all/objdump.exp: Require GNU tail for
	'objdump -Wi' test and replace tail with $env(TAIL).

config/

	PR binutils/33396
	* acx.m4 (ACX_PROG_GNU_TAIL): New.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Collin Funk <collin.funk1@gmail.com>
2025-09-08 05:44:09 -07:00
H.J. Lu
6b27a22032 objdump: Check the SEC_CODE bit for code
If a shared library has

$ readelf -D -sW x.so | grep _PROCEDURE_LINKAGE_TABLE_
     3: 00000000000002c0     0 OBJECT  GLOBAL DEFAULT    5 _PROCEDURE_LINKAGE_TABLE_
$

Disassembler treats PLT0 as data:

$ objdump -dw x.so

x.so:     file format elf64-x86-64

Disassembly of section .plt:

00000000000002c0 <_PROCEDURE_LINKAGE_TABLE_>:
 2c0:	ff 35 7a 01 10 00 ff 25 7c 01 10 00 0f 1f 40 00     .5z....%|.....@.

00000000000002d0 <foo@plt>:
 2d0:	ff 25 7a 01 10 00    	jmp    *0x10017a(%rip)        # 100450 <foo>
 2d6:	68 00 00 00 00       	push   $0x0
 2db:	e9 e0 ff ff ff       	jmp    2c0 <_PROCEDURE_LINKAGE_TABLE_>

Disassembly of section .text:

00000000000002e0 <func>:
 2e0:	e8 eb ff ff ff       	call   2d0 <foo@plt>
 2e5:	c3                   	ret

Check the SEC_CODE bit on section for code.

	PR binutils/33389
	* objdump.c (disassemble_section): Check SEC_CODE for code.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-08 05:41:45 -07:00
H.J. Lu
5c9a05428d elf: Define more SHT_SUNW_XXX
binutils/

	* readelf.c (get_solaris_section_type): Use SHT_SUNW_XXX and
	add SHT_SUNW_phname and SHT_SUNW_symtabnsort.

include/

	* elf/common.h (SHT_SUNW_symtabnsort): New.
	(SHT_SUNW_ancillary): Likewise.
	(SHT_SUNW_capchain): Likewise.
	(SHT_SUNW_capinfo): Likewise.
	(SHT_SUNW_symsort): Likewise.
	(SHT_SUNW_tlssort): Likewise.
	(SHT_SUNW_LDYNSYM): Likewise.
	(SHT_SUNW_dof): Likewise.
	(SHT_SUNW_cap): Likewise.
	(SHT_SUNW_SIGNATURE): Likewise.
	(SHT_SUNW_ANNOTATE): Likewise.
	(SHT_SUNW_DEBUGSTR): Likewise.
	(SHT_SUNW_DEBUG): Likewise.
	(SHT_SUNW_verdef): Likewise.
	(SHT_SUNW_verneed): Likewise.
	(SHT_SUNW_versym): Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-07 05:32:12 -07:00
Alan Modra
b62b7b641f Re: tekhex test for commit bf0f85df12
* testsuite/binutils-all/objcopy.exp (objcopy_tek2bin): Correct
	isremote to is_remote.
2025-09-06 10:33:16 +09:30
H.J. Lu
3e1716c9fc readelf: Handle 0 sh_entsize of GOT sections
Gold, lld and mold set sh_entsize to 0 on .got and .got.plt sections.
If sh_entsize of GOT sections is 0, assume 8 for ELFCLASS64 and 4 for
ELFCLASS32, except for x32 which uses 8.

	PR binutils/33368
	* readelf.c (process_got_section_contents): Handle 0 sh_entsize
	of GOT sections.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-05 04:56:27 -07:00
Andrew C Aitchison
674628ae3a PR 33360, Correct strings -Ue output
Signed-off-by: Andrew C Aitchison <andrew@aitchison.me.uk>
2025-09-04 07:36:08 +09:30
H.J. Lu
955b8e0939 readelf: Don't change the symbol table
1. Update dump_relr_relocations not to change the symbol table.
2. Update count_relr_relocations and dump_relr_relocations not to
retrieve the same data twice.

binutils/

	PR binutils/33328
	* readelf.c (count_relr_relocations): Add an argument to return
	the retrieved data and remove the FIXME in comments.
	(dump_relr_relocations): Add an argument for the retrieved data.
	Retrieve the data if needed.  Don't change the symbol table and
	remove the FIXME in comments.
	(display_relocations): Get the data from count_relr_relocations
	and pass it to dump_relr_relocations call.
	(process_relocs): Pass NULL to dump_relr_relocations.

ld/

	PR binutils/33328
	* testsuite/ld-i386/dt-relr-2.d: New file.
	* testsuite/ld-i386/dt-relr-2.s: Likewise.
	* testsuite/ld-x86-64/dt-relr-2-x32.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-2.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-2.s: Likewise.
	* testsuite/ld-i386/i386.exp: Run dt-relr-2.
	* testsuite/ld-x86-64/x86-64.exp: Run dt-relr-2 and dt-relr-2-x32.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-03 08:22:33 -07:00
H.J. Lu
5d3a6f777d readelf: Run --got-contents only on ET_DYN/ET_EXEC files
Update "readelf --got-contents" to skip on non-ET_DYN/ET_EXEC files.

	* readelf.c (process_got_section_contents): Skip if not
	ET_DYN/ET_EXEC files.
	* testsuite/binutils-all/readelf-got.d: Removed.
	* testsuite/binutils-all/readelf.exp: Don't run readelf-got.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-03 05:44:54 -07:00
H.J. Lu
8a94d92a46 readelf: Call qsort only if all_relocations_count > 1
Don't call qsort if all_relocations_count < 1.

	PR binutils/33351
	* readelf.c (process_got_section_contents): Call qsort only if
	all_relocations_count > 1.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-03 05:38:23 -07:00
H.J. Lu
eae0da7eb4 readelf: Report if no GOT section found
Update "readelf --got-contents" to report if no GOT section found.

	* readelf.c (process_got_section_contents): Report if no GOT
	section found.
	* testsuite/binutils-all/readelf-got.d: New file.
	* testsuite/binutils-all/readelf.exp: Run readelf-got.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-09-02 08:29:26 -07:00
H.J. Lu
81e90cf63a readelf: Add --got-contents option
Add --got-contents option to readelf, inspired by the -G option on Solaris,
to display contents of GOT sections:

$ readelf --got-contents libfoo.so

Global Offset Table '.got' contains 1 entry:
 Index:    Address       Reloc         Sym. Name + Addend/Value
     0: 000000200340 R_X86_64_GLOB_DAT foo + 0

Global Offset Table '.got.plt' contains 4 entries:
 Index:    Address       Reloc         Sym. Name + Addend/Value
     0: 000000200348                   200220
     1: 000000200350                   0
     2: 000000200358                   0
     3: 000000200360 R_X86_64_JUMP_SLO bar + 0

When --got-content options are used:

1. Allocate an array, all_relocations, to hold all relocations.
2. Update dump_relr_relocations and dump_relocations to scan relocations
and cache them in all_relocations.  Don't display relocations if not
requested.
3. Add process_got_section_contents to display contents of GOT sections
by matching the GOT entry offset against the cached relocations.
4. Update process_mips_specific to only display the GOT related contents
for --got-contents.

binutils/

	* NEWS: Mention "readelf --got-contents".
	* readelf.c (do_got_section_contents): New.
	(elf_relocation): Likewise.
	(all_relocations_root): Likewise.
	(all_relocations): Likewise.
	(all_relocations_count): Likewise.
	(update_all_relocations): Likewise.
	(dump_relr_relocations): Add a bool argument to indicate if
	relocations should be displayed.  Populate all_relocations if
	do_got_section_contents is true.
	(dump_relocations): Likewise.
	(long_option_values): Add OPTION_GOT_CONTENTS.
	(options): Add --got-contents.
	(usage): Show --got-contents.
	(parse_args): Support --got-contents.
	(display_relocations): Add a bool argument, dump_reloc, to
	indicate if relocations should be displayed.  Call
	update_all_relocations.  Pass dump_reloc to dump_relr_relocations
	and dump_relocations.
	(process_relocs): Check do_got_section_contents.  Handle
	do_got_section_contents for dynamic relocations.
	(process_section_contents): Pass true to display_relocations.
	(process_mips_specific): Add a bool argument, dump_got, to
	indicate if only the GOT related contents should be displayed.
	Display all MIPS specific information if dump_got is false.
	(elf_relocation_cmp): New.
	(display_elf_relocation_at): Likewise.
	(process_got_section_contents): Likewise.
	(process_object): Call process_got_section_contents.
	* doc/binutils.texi: Document --got-contents.

ld/

	* testsuite/ld-i386/binutils.exp: New file.
	* testsuite/ld-i386/got-1.s: Likewise.
	* testsuite/ld-i386/libgot-1a.rd: Likewise.
	* testsuite/ld-i386/libgot-1b.rd: Likewise.
	* testsuite/ld-i386/libgot-1c.rd: Likewise.
	* testsuite/ld-i386/libgot-1d.rd: Likewise.
	* testsuite/ld-x86-64/binutils.exp: Likewise.
	* testsuite/ld-x86-64/got-1.s: Likewise.
	* testsuite/ld-x86-64/libgot-1a-x32.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1a.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1b-x32.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1b.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1c-x32.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1c.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1d-x32.rd: Likewise.
	* testsuite/ld-x86-64/libgot-1d.rd: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-29 06:17:19 -07:00
H.J. Lu
f83ec9ae4a readelf: Update "-D -r" to dump DT_RELR
1. Update dump_relr_relocations to take relr_size, relr_entsize and
relr_offset, instead of a pointer to Elf_Internal_Shdr, as function
arguments.
2. Update process_relocs to call dump_relr_relocations if relocation
type is reltype_relr.

binutils/

	PR binutils/33328
	* readelf.c (dump_relr_relocations): Replace a pointer to
	Elf_Internal_Shdr argument with relr_size, relr_entsize and
	relr_offset.
	(display_relocations): Update the dump_relr_relocations call.
	(process_relocs): Call dump_relr_relocations if relocation type
	is reltype_relr.

ld/

	PR binutils/33328
	* testsuite/ld-i386/dt-relr-1c.d: New file.
	* testsuite/ld-i386/dt-relr-1d.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1c-x32.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1c.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1d-x32.d: Likewise.
	* testsuite/ld-x86-64/dt-relr-1d.d: Likewise.
	* testsuite/ld-i386/i386.exp: Run PR binutils/33328 tests.
	* testsuite/ld-x86-64/x86-64.exp: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-27 18:07:50 -07:00
Alan Modra
93dfa8e923 objcopy "strip without global symbol" test
This binutils test fails with -fsanitize.  NOSANITIZE_CFLAGS isn't
available in the binutils testsuite, and importing it over from ld
requires a huge amount of tcl code to be moved.  So I chose to simply
add -fno-sanitize=all if -fsanitize= is seem in CFLAGS.

	* testsuite/binutils-all/objcopy.exp
	(objcopy_test_without_global_symbol): Add -fno-sanitize=all to
	flags if -fsanitize= is found in CFLAGS_FOR_TARGET.  Tidy use
	of objfile.
2025-08-27 21:45:12 +09:30
Alan Modra
d8867f5d1b tekhex test for commit bf0f85df12
* testsuite/binutils-all/tek2.obj: Change to a 3 byte data file
	that triggers tekhex error fixed by commit bf0f85df12.
	* testsuite/binutils-all/ar.exp: Adjust to suit.
	* testsuite/binutils-all/objcopy.exp (objcopy_tek2bin): New proc.
2025-08-27 21:45:12 +09:30
Alan Modra
3fa891a80c objcopy "Unable to recognise the format of the input file"
This bogus error comes up when trying something like
objcopy -O binary .../binutils/testsuite/binutils-all/tek2.obj xxx

This is an annoying message, as HJ said in
https://sourceware.org/pipermail/binutils/2002-August/021354.html
and removed it for some cases, eg. I can make it go away by specifying
-I tekhex.  The message is also untrue, as objcopy does in fact know
the format of the input file.

I think the message should be limited to ELF input files that are
being handled by the elf64-little, elf64-big, elf32-little or
elf32-big targets, due to libbfd being compiled with limited target
support.  I'm also changing the message a litle.

	* objcopy.c (copy_object): Change "Unable to recognise format"
	message to "Unable to recognise architecture" and only report
	this error for ELF objects lacking their proper target support.
	* testsuite/binutils-all/x86-64/x86-64.exp: Update to suit.
2025-08-27 21:45:12 +09:30
Alan Modra
ab0e81e536 Revert part of commit 8e885fece1
After commit 5e83077d55 we no longer choose a "plugin" target in
objcopy so ibfd->target_defaults can again be used to test whether the
user supplied a target.

	PR 33230
	* objcopy.c (copy_file): Revert change adding a target_defaulted
	variable and passing down to..
	(copy_archive, copy_object): ..here.  Remove target_defaulted
	parameter.  Use ibfd->target_defaulted.
2025-08-27 21:45:12 +09:30
Vladimir Mezentsev
5319c8dec6 MAINTAINERS: Remove my email address
My position was eliminated and I don't have access to my oracle email
account.
You need a new gprofng maintainer.
2025-08-26 02:48:13 +01:00
Jan Beulich
1bfc186f71 MAINTAINERS: move Jim Wilson to Past Maintainers
..., effectively yielding IA-64 maintainer-less, as per his request:
https://sourceware.org/pipermail/binutils/2025-August/143393.html
https://sourceware.org/pipermail/binutils/2025-August/143491.html
Jim - thanks much for your past work.
2025-08-22 07:56:59 +02:00
Alan Modra
fed7c3654c Remove cloudabi support
Apparently the cloudabi project is dead.  The cloudabi support branded
object files with ELFOSABI_CLOUDABI but other than that didn't do much.
2025-08-20 13:26:19 +09:30
Indu Bhagat
09292f4ae2 binutils: dwarf: fix display of large cfa_offset
eh_frame textual dump was not correct when the cfa_offset is a large
value.  The reason is that the dumping code generally assumes the
cfa_offset is an 'int'.

cfa_offset values can be updated by various DWARF opcodes, like:
  - DW_CFA_def_cfa, DW_CFA_def_cfa_offset which bring unsigned leb128
    cfa_offset
  - DW_CFA_def_cfa_sf, DW_CFA_def_cfa_offset_sf which bring signed
    leb128 cfa_offset

Internally, the routines in dwarf.c keep the value as 'uint64_t
cfa_offset'.  That size of the datatype is expected to work for most of
the real-world cases.  Care, however, needs to be taken when it comes
to the signedness of the value.  Fix the buggy behavior by adding an
additional field to track whether the value of cfa_offset is signed or
unsigned and display accordingly for "frames-interp" output.

The display of cfa_offset had issues in both "frames-interp" output
(objdump -WF or do_debug_frames_interp) and the "frames" output.

Add two new tests: cfi-common-10.s uses a large positive cfa_offset
(with "frames output), and cfi-x86_64-2.s uses a negative cfa_offset
(with "frames-interp" output).

ChangeLog:
	* binutils/dwarf.c (frame_display_row): Update format string
	based on signedness.
	(display_debug_frames): Track signedness.  Also fix display of
	cfa_offset using PRIu64 or PRId64 as applicable.
	* gas/testsuite/gas/cfi/cfi.exp: Add two new tests.
	* gas/testsuite/gas/cfi/cfi-common-10.d: New test.
	* gas/testsuite/gas/cfi/cfi-common-10.s: New test.
	* gas/testsuite/gas/cfi/cfi-x86_64-2.d: New test.
	* gas/testsuite/gas/cfi/cfi-x86_64-2.s: New test.
2025-08-19 01:08:06 -07:00
H.J. Lu
7e432e93f8 Limit BFD_SUPPORTS_PLUGINS check to plugin.h and targets.c
Minimize the BFD_SUPPORTS_PLUGINS check to make code more readable and
maintainable by:

1. Update bfd/plugin.h to define plugin functions as static inline if
BFD_SUPPORTS_PLUGINS is 0.
2. Remove BFD_SUPPORTS_PLUGINS check from all bfd and binutils files
except plugin.h and targets.c.
3. Replace the remaining BFD_SUPPORTS_PLUGINS checks with a function so
that plugin availability is checked at run time.

bfd/

	* archive.c: Include plugin.h unconditionally.
	(_bfd_compute_and_write_armap): Remove the BFD_SUPPORTS_PLUGINS
	check.
	* bfd-in.h (bfd_plugin_enabled): New.
	* bfd-in2.h: Regenerated.
	* elflink.c: Include plugin.h unconditionally.
	(elf_link_is_defined_archive_symbol): Remove the
	BFD_SUPPORTS_PLUGINS check.
	* format.c: Include plugin.h unconditionally.
	(bfd_set_lto_type): Remove the BFD_SUPPORTS_PLUGINS check.
	(bfd_check_format_matches): Replace the BFD_SUPPORTS_PLUGINS
	check with the bfd_plugin_enabled call.  Replace plugin_vec
	with bfd_plugin_vec.  Remove the BFD_SUPPORTS_PLUGINS check.
	* plugin.c (bfd_plugin_target_p): Removed.
	* plugin.h (bfd_plugin_vec): New.
	(bfd_plugin_target_p): Likewise.
	(bfd_plugin_set_program_name): New.  Static inline
	function if BFD_SUPPORTS_PLUGINS is 0.
	(bfd_plugin_open_input): Likewise.
	(bfd_plugin_set_plugin): Likewise.
	(bfd_link_plugin_object_p): Likewise.
	(register_ld_plugin_object_p): Likewise.
	(bfd_plugin_close_file_descriptor): Likewise.
	(bfd_plugin_vec): Likewise.
	(bfd_plugin_target_p): Likewise.
	* xtensa-dynconfig.c (xtensa_load_config): Replace the
	BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.

ar/

	* ar.c: Include plugin.h unconditionally.
	(plugin_target): Removed.
	(usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(ranlib_usage): Likewise.
	(decode_options): Likewise.
	(ranlib_main): Likewise.
	(main): Call bfd_plugin_set_program_name unconditionally.
	* nm.c: Include plugin.h unconditionally.
	(plugin_target): Removed.
	(usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(filter_symbols): Remove the BFD_SUPPORTS_PLUGINS check.
	(display_rel_file): Likewise.
	(main): Call bfd_plugin_set_program_name unconditionally.  Replace
	the BFD_SUPPORTS_PLUGINS check with the bfd_plugin_enabled call.
	* objcopy.c: Include plugin.h unconditionally.
	(strip_usage): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.
	(copy_archive): Remove the BFD_SUPPORTS_PLUGINS check.  Replace
	BFD_SUPPORTS_PLUGINS with the bfd_plugin_enabled call.
	(copy_file): Likewise.
	(strip_main): Likewise.

ld/

	* ldfile.c: Include plugin.h unconditionally.
	(ldfile_try_open_bfd): Remove the BFD_SUPPORTS_PLUGINS check.
	* ldlang.c: Include plugin.h unconditionally.
	(plugin_insert): Remove the BFD_SUPPORTS_PLUGINS check.
	(plugin_undefs): Likewise.
	(open_input_bfds): Likewise.
	(lang_check): Likewise.
	(lang_gc_sections): Likewise.
	(find_next_input_statement): Likewise.
	(lang_process): Likewise.
	* ldlang.h (lang_input_statement_flags): Likewise.
	* ldlex.h (option_values): Likewise.
	* ldmain.c: Include plugin.h unconditionally.
	(ld_cleanup): Remove the BFD_SUPPORTS_PLUGINS check.
	(main): Likewise.
	(add_archive_element): Likewise.
	* lexsup.c: Include plugin.h unconditionally.
	(ld_options): Remove the BFD_SUPPORTS_PLUGINS check.
	(parse_args): Replace the BFD_SUPPORTS_PLUGINS check with the
	bfd_plugin_enabled call.  Remove the BFD_SUPPORTS_PLUGINS check.
	(help): Append " (ignored)" to plugin options if bfd_plugin_enabled
	return false.
	* libdep_plugin.c: Remove the BFD_SUPPORTS_PLUGINS check.
	* plugin.c: Likewise.
	* testplug.c: Likewise.
	* testplug2.c: Likewise.
	* testplug3.c: Likewise.
	* testplug4.c: Likewise.

Co-Authored-By: Alan Modra <amodra@gmail.com>
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-08-18 17:05:43 -07:00
Alan Modra
74201a3208 Re: windres: don't exit so much on errors in read_coff_rsrc
oss-fuzz found that I missed some error paths in commit 9e68cae4fd.
This fix prevents reads of a NULL pointer in sort_resources.

	* rescoff.c (read_coff_res_dir): Check return of recursive calls
	and read_coff_data_entry calls.  Pass failures up the call chain.
2025-08-19 09:31:06 +09:30
Alan Modra
5e83077d55 Don't choose plugin target in binutils/
Instead make bfd_check_format try the plugin target first when the
user hasn't supplied a target.

bfd/
	* format.c (bfd_check_format_matches): Try for a plugin target
	match first.
	* targets.c (bfd_find_target): Don't specially treat "plugin".
binutils/
	* ar.c (plugin_target): Delete.
	(open_inarch): Don't set target of archive elements.
	(replace_members): Use target rather than plugin_target when
	opening replacement or additional files.
	* arsup.c (plugin_target): Delete.  Replace all uses with NULL.
	(ar_open): Don't set element target.
	* bucomm.h (set_plugin_target): Delete.
	* nm.c (plugin_target): Delete.
	(display_archive): Don't set element target.
	(display_file): Alway use target when opening file.
	* objcopy.c (copy_archive): Don't use plugin target for output
	elements.
	* NEWS: Mention stricter target checking.
2025-08-18 23:05:43 +09:30
Alan Modra
a5858e8136 Sanity check windows resource version len
oss-fuzz generated a total length field of 32, when the header was 40
bytes.  Subtracting gave -8ul for the remaining length..

I think we should be sanity checking the total length given in the
header against the remaining buffer length and the size of the header
each time get_version_header is called.

Possibly vallen should be sanity checked inside get_version_header
too, but I'll leave that to someone else.

	PR 27686
	* resbin.c (bin_to_res_version): Correct error message arg.
	Move len vs. buffer length sanity check..
	(get_version_header): ..to here.  Also sanity check len
	against off.
2025-08-17 22:32:43 +09:30