Commit Graph

4793 Commits

Author SHA1 Message Date
Jens Remus
2b1dd3156b s390: Announce s390 64-bit (s390x) SFrame V2 support in binutils
The preceding commits add s390 64-bit (s390x) support in binutils to
generate SFrame stack trace information (.sframe section) in the
assembler from CFI directives (with option --gsframe), generate .sframe
section for linker-generated .plt section in the linker, and dump SFrame
information in objdump and readelf (with option --sframe).

binutils/
	* NEWS: Announce s390 64-bit (s390x) SFrame V2 support in
	as, ld, objdump, and readelf.

gas/
	* NEWS: Update s390 64-bit (s390x) SFrame V2 support in
	assembler.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-07-11 10:29:40 +02:00
Alan Modra
d72ad17caa AM_PO_SUBDIRS
Swap AM_PO_SUBDIRS and ZW_GNU_GETTEXT_SISTER_DIR lines in
*/configure.ac.  ZW_GNU_GETTEXT_SISTER_DIR indirectly invokes
AC_REQUIRE(AM_PO_SUBDIRS) so results in AM_PO_SUBDIRS being emitted
before ZW_GNU_GETTEXT_SISTER_DIR if it hasn't already been invoked.
2025-07-11 08:23:40 +09:30
Alan Modra
5942dd9913 Merge init_private_section_data with copy_private_section_data
init_private_section_data is used by the linker and is a special case
of copy_private_section_data that copies a reduced set of section data
from input to output.  Merge the two functions, adding a link_info
param to copy_private_section_data and remove init_private_section_data.
2025-07-09 11:13:55 +09:30
Indu Bhagat
54f153a345 NEWS: sframe: mention new semantics for SFrame FDE function start addr
The SFrame FDE's function start address is always emitted as follows by
GAS and ld:  it is the offset of the start PC of the respective function
from the FDE field itself.

GAS and ld will emit a flag SFRAME_F_FDE_FUNC_START_PCREL set to 1
when emitting the field in this encoding.

	* binutils/NEWS: Announce the change of encoding for SFrame FDE
	  func start addr field.
        * gas/NEWS: Announce the emission of new flag
	  SFRAME_F_FDE_FUNC_START_PCREL.
        * ld/NEWS: Likewise.  Relocatable links are now fixed.
2025-07-06 12:53:03 -07:00
Indu Bhagat
0b1bf2fc98 bfd: gas: ld: libsframe: adopt new encoding for FDE func start addr field
This patch convenes a set of changes in bfd, gas, ld, libsframe towards
moving to the new encoding for the 'sfde_func_start_address' field in
SFrame FDE.

First, gas must now mark all SFrame sections with the new flag
SFRAME_F_FDE_FUNC_START_PCREL.  gas was already emitting the field
in the said encoding.

	* gas/gen-sframe.c (output_sframe_internal): Emit the flag
	SFRAME_F_FDE_FUNC_START_PCREL.

Similarly for ld, adopt the new semantics of sfde_func_start_address
consistently.  This means:
  - When merging SFrame sections, check that all input SFrame sections
    have the SFRAME_F_FDE_FUNC_START_PCREL flag set.  If the check
    fails, ld errors out.
  - When merging SFrame sections, keep even the in-memory contents of
    the FDE function start address (buffer passed to libsframe
    sframe_encoder_write () for writing out) encoded in the new
    semantics.  While it is, in theory, possible that instead of doing this
    change here, we adjust the value of sfde_func_start_address at the final
    write (sframe_encoder_write) time.  But latter is not favorable for
    maintenanance and may be generally confusing for developers.
  - When creating SFrame for PLT entries, emit flag
    SFRAME_F_FDE_FUNC_START_PCREL.

include/
        * sframe-api.h (SFRAME_F_LD_MUSTHAVE_FLAGS): New definition.
bfd/
	* elf-sframe.c (_bfd_elf_merge_section_sframe): Check for flag
	combinatation SFRAME_F_LD_MUSTHAVE_FLAGS set for all input and
	output SFrame sections.  If not, error out.  Also, adopt the new
        semantics of function start address encoding.
	* bfd/elfxx-x86.c (_bfd_x86_elf_create_sframe_plt): Emit flag
	SFRAME_F_FDE_FUNC_START_PCREL.

Next, for dumping SFrame sections, now that we are emitting the same
encoding in GAS, non-relocatable and relocatable SFrame links, it is the
time to set relocate to TRUE in debug_displays[].

binutils/
	* dwarf.c (struct dwarf_section_display): Allow sframe sections
	  to now be relocated.
gas/testsuite/
	* gas/cfi-sframe/cfi-sframe-aarch64-pac-ab-key-1.d: Update the
	test.  Relocatable SFrame sections now display non-zero value
	(appropriate function start address).

Now, as the SFrame sections on-disk and in-memory use the new semantics of
sfde_func_start_address encoding (i.e., function start address is the
offset from the sfde_func_start_address field to the start PC), the
calculation to make it human readable (i.e., relatable to the addresses
in .text sections) needs adjustment.

libsframe/
	* sframe-dump.c (dump_sframe_func_with_fres): Adjust the
	function start address for dumping.

Now that both the emission of the new encoding, and the relocation of
sections before dumping them is in place, it is time to adjust the
testcases.

gas/testsuite/
	* gas/cfi-sframe/cfi-sframe-aarch64-1.d: Update expected output
	to include SFRAME_F_FDE_FUNC_START_PCREL instead of NONE.
	* gas/cfi-sframe/cfi-sframe-aarch64-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-aarch64-3.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-aarch64-4.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-1.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-10.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-11.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-3.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-4.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-5.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-6.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-7.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-8.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-common-9.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-1.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-empty-1.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-empty-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-empty-3.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-x86_64-empty-4.d: Likewise.
	* gas/cfi-sframe/common-empty-1.d: Likewise.
	* gas/cfi-sframe/common-empty-2.d: Likewise.
	* gas/cfi-sframe/common-empty-3.d: Likewise.
	* gas/scfi/x86_64/scfi-cfi-sections-1.d: Likewise.
	* gas/scfi/x86_64/scfi-dyn-stack-1.d: Likewise.
ld/testsuite/
	* ld-aarch64/sframe-simple-1.d: Update expected output to
	include SFRAME_F_FDE_FUNC_START_PCREL.
	* ld-x86-64/sframe-ibt-plt-1.d: Likewise.
	* ld-x86-64/sframe-plt-1.d: Likewise.
	* ld-x86-64/sframe-pltgot-1.d: Likewise.
	* ld-x86-64/sframe-pltgot-2.d: Likewise.
	* ld-x86-64/sframe-simple-1.d: Likewise.

Naturally, the change of semantics for 'SFrame FDE function start address'
has consequences on the implementation in libsframe.  As per the new
semantics:
  - Function start address in the SFrame FDE (sfde_func_start_address)
    is an offset from the FDE function start address field to the start
    PC of the associated function.

Note that, the libsframe library brings the SFrame section contents into
its own memory to create a sframe_decoder_ctx object via sframe_decode
().  Many internal and user-interfacing APIs then may use
sframe_decoder_ctx object to interact and fulfill the work.

In context of changing semantics for sfde_func_start_address, following
relevant examples may help understand the impact:
  - sframe_find_fre () finds a the SFrame stack trace data (SFrame FRE)
    given a lookup offset (offset of lookup_pc from the start of SFrame
    section).  Now that the sfde_func_start_address includes the
    distance from the sfde_func_start_address field to the start of
    SFrame section itself, the comparison checks of
    sfde_func_start_address with the incoming lookup offset need
    adjustment.
  - Some internal functions (sframe_get_funcdesc_with_addr_internal ()
    finds SFrame FDE by using binary seach comparing
    sfde_func_start_address fields, etc.) need adjustments.
  - sframe_encoder_write () sorts the SFrame FDEs before writing out
    the SFrame data.  Sorting of SFrame FDE via the internal function
    sframe_sort_funcdesc() needs adjustments: the new encoding of
    sfde_func_start_address means the distances are not from the same
    anchor, so cannot be sorted directly.

This patch takes the approach of adding a new internal function:
  - sframe_decoder_get_secrel_func_start_addr (): This function returns
    the offset of the start PC of the function from the start of SFrame
    section, i.e., it gives a section-relative offset.

As the sframe_decoder_get_secrel_func_start_addr () API needs the value
of the function index in the FDE list, another internal API needs
sframe_fre_check_range_p () adjustments too.

Sorting the FDEs (via sframe_sort_funcdesc ()) is done by first bringing
all offsets in sfde_func_start_address relative to start of SFrame
section, followed by sorting, and then readjusting the offsets accroding
to the new position in the FDE list.

libsframe/
	* sframe.c (sframe_decoder_get_secrel_func_start_addr): New
	static function.
        (sframe_fre_check_range_p): Adjust the interface a bit.
	(sframe_get_funcdesc_with_addr_internal): Use
	sframe_decoder_get_secrel_func_start_addr () when comparing
	sfde_func_start_address with user input offset.
        (sframe_find_fre): Adopt the new semantics.
        (sframe_sort_funcdesc): Likewise.

For the libsframe testsuite, use the new encoding for FDE func start
addr: distance between the FDE sfde_func_start_address field and the
start PC of the function itself.

Use SFRAME_F_FDE_FUNC_START_PCREL flag, though the sframe_encode ()
interface in libsframe applies no sanity checks for the encoding itself.

libsframe/testsuite/
	* libsframe.find/findfre-1.c: Adjust to use the new
	SFRAME_F_FDE_FUNC_START_PCREL specific encoding.
	* libsframe.find/findfunc-1.c: Likewise.
	* libsframe.find/plt-findfre-1.c: Likewise.
	* libsframe/testsuite/libsframe.decode/DATA2: Update data file
	due to usage of new SFRAME_F_FDE_FUNC_START_PCREL flag.
	* libsframe/testsuite/libsframe.encode/encode-1.c: Use flag
	SFRAME_F_FDE_FUNC_START_PCREL.
2025-07-06 12:53:03 -07:00
Indu Bhagat
c915c2c95a objdump, readelf: sframe: apply relocations before textual dump
PR libsframe/32589 - function start address is zero in SFrame section dump

Currently, readelf and objdump display the SFrame sections in ET_REL
object files with function start addresses of each function as 0.  This
makes it difficult to correlate SFrame stack trace information with the
individual functions in the object file.

For objdump, use the dump_dwarf () interface to dump SFrame section.
Similarly, for readelf, use the display_debug_section () interface to
dump SFrame section.  These existing interfaces (for DWARF debug
sections) already support relocating the section contents before
dumping, so lets use them for SFrame sections as well.

When adding a new entry for SFrame in debug_option_table[], use char
'nil' and the option name of "sframe-internal-only".  This is done so
that there is no additional (unnecessary) user-exposed ways of dumping
SFrame sections.  Additionally, we explicitly disallow the
"sframe-internal-only" from external/user input in --dwarf (objdump).
Similarly, "sframe-internal-only" is explicitly matched and disallowed
from --debug-dump (readelf).

For objdump and readelf, we continue to keep the same error messaging as
earlier:

  $ objdump --sframe=sframe bubble_sort.o
  ...
  No sframe section present

  $ objdump --sframe=.sfram bubble_sort.o
  ...
  No .sfram section present

  $ objdump --sframe=sframe-internal-only sort
  ...
  No sframe-internal-only section present

Similarly for readelf:

  $ readelf --sframe= bubble_sort.o
  readelf: Error: Section name must be provided
  $ readelf --sframe=.sfram bubble_sort.o
  readelf: Warning: Section '.sfram' was not dumped because it does not exist
  $ readelf --sframe=sframe bubble_sort.o
  readelf: Warning: Section 'sframe' was not dumped because it does not exist

PS: Note how this patch adds a new entry to debug_displays[] with a
    relocate value set to FALSE.  This will be set to TRUE in a subsequent
    patch ("bfd: gas: ld: libsframe: emit func start addr field as an offset
    from FDE") when fixes are made to emit the value of the
    'sfde_func_start_address' field in the new encoding
    SFRAME_F_FDE_FUNC_START_PCREL across gas and ld.

binutils/
	* dwarf.c (display_sframe): New definition.
	(dwarf_select_sections_all): Enable SFrame section too.
	(struct dwarf_section_display): Add entry for SFrame section.
	* dwarf.h (enum dwarf_section_display_enum): Add enumerator for
	SFrame.
	* objdump.c (dump_section_sframe): Remove.
	(dump_sframe_section): Add new definition.
	(dump_bfd): Use dump_sframe_section.
	* binutils/readelf.c (dump_section_as_sframe): Remove.
2025-07-06 12:53:03 -07:00
Vladimir Mezentsev
88c66eca24 Fix typos in binutils/dwarf.c
binutils/ChangeLog
2025-06-29  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

	* dwarf.c: Change "/usrlib64/debug/usr" to "/usr/lib64/debug/usr/" and
	.gun_debugaltlink to .gnu_debugaltlink.
2025-06-30 00:25:34 -07:00
H.J. Lu
803e6cfb43 x86-64.exp: Correct pr26808.dump to pr27708.dump
Change

verbose "cmp tmpdir/pr27708.out $srcdir/$subdir/pr26808.dump" 1

to

verbose "cmp tmpdir/pr27708.out $srcdir/$subdir/pr27708.dump" 1

	* testsuite/binutils-all/x86-64/x86-64.exp: Correct pr26808.dump
	to pr27708.dump.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-06-29 06:41:05 +08:00
Matthieu Longo
86a053ddd1 readelf: invalid error message triggered when last tag is an empty string
Disclaimer: this issue cannot occur with Object Attributes v1 (OAv1) while
using the GNU binutils because a value of '\0' (empty string) for a tag
with a string value is considered as the default value for the attribute,
and consequently is eliminated by gas from the output object file during
the serialization.

An empty string is a valid value for a NTBS tag in both OAv1 and OAv2 [1]
cases. However, contrarily to OAv1, a OAv2 subsection can be required and
so, tags in this subsection might have to be present even if the value is
the default. To comply with this requirement, the OAv2 serializer won't
drop the default values.

In the case where a NTBS tag has the value '\0' and is last in the object
attributes section, the current code in readelf used for dumping the object
attributes incorrectly detects an overflow, and prints out an error message
for a corrupted string tag.

This patch fixes the detection of the overflow so that it now accept an
empty string in the last tag of the object attributes section.

It also fixes the previous tests for the empty NTBS case and the non-null
terminated string one. The fix was also tested in the context of OAv2's
patch series [1] where the issue was originally detected. No regression
was found.

[1]: https://inbox.sourceware.org/binutils/20250509151319.88725-1-matthieu
     .longo@arm.com/
2025-06-25 09:41:24 +01:00
Nelson Chu
1c391a084f ld/NEWS,binutils/NEWS: Updated supports for RISC-V zicfiss and zicfilp 2025-06-24 18:15:14 +08:00
Kito Cheng
4ad5217caf RISC-V: Add GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED
This patch adds two new GNU properties for RISC-V:
GNU_PROPERTY_RISCV_FEATURE_1_CFI_SS and GNU_PROPERTY_RISCV_FEATURE_1_CFI_LP_UNLABELED.

We only add readelf and define the properties in this patch.

Ref: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/417
2025-06-24 18:14:39 +08:00
H.J. Lu
08c3cbe592 objcopy: Don't extend the output section size
Since the output section contents are copied from the input, don't
extend the output section size beyond the input section size.

	PR binutils/33049
	* objcopy.c (copy_section): Don't extend the output section
	size beyond the input section size.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-06-23 22:30:53 +08:00
H.J. Lu
eee822a660 objcopy: Correctly check archive element for LTO IR
commit 717a38e9a0
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Sun May 4 05:12:46 2025 +0800

    strip: Add GCC LTO IR support

added:

@@ -3744,6 +3768,12 @@ copy_archive (bfd *ibfd, bfd *obfd, const char
*output_target,
     goto cleanup_and_exit;
   }

+#if BFD_SUPPORTS_PLUGINS
+      /* Copy LTO IR file as unknown object.  */
+      if (bfd_plugin_target_p (ibfd->xvec))
                                ^^^^ A typo, should be this_element.
+  ok_object = false;
+      else
+#endif
       if (ok_object)
   {
     ok = copy_object (this_element, output_element, input_arch);

to check if the archive element is a LTO IR file.  "ibfd" is the archive
BFD.  "this_element" should be used to check for LTO IR in the archive
element.  Fix it by replacing "ibfd" with "this_element".

	PR binutils/33078
	* objcopy.c (copy_archive): Correctly check archive element for
	LTO IR.
	* testsuite/binutils-all/objcopy.exp (strip_test_archive): New.
	Run strip_test_archive.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-06-15 05:49:40 +08:00
Jeremy Drake
2c79b421c7 dlltool: respect use-nul-prefixed-import-tables option for delaylib
Noticed the extra zeros while inspecting the output.

Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2025-06-13 07:53:07 +02:00
Jeremy Drake
b2c87b521b ld,dlltool: move read-only delayimp data into .rdata
This allows the delay IAT to be in its own section with nothing else, as
required by IMAGE_GUARD_DELAYLOAD_IAT_IN_ITS_OWN_SECTION, documented at
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#load-configuration-layout

Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2025-06-13 07:52:47 +02:00
LIU Hao
3cad19db4e bfd,ld,dlltool: Emit delay-load import data into its own section
A delay-import symbol (of a function) is resolved when a call to it is made.
The delay loader may overwrite the `__imp_` pointer to the actual function
after it has been resolved, which requires the pointer itself be in a
writeable section.

Previously it was placed in the ordinary Import Address Table (IAT), which
is emitted into the `.idata` section, which had been changed to read-only
in db00f6c3ac, which caused segmentation
faults when functions from delay-import library were called.  This is
PR 32675.

This commit makes DLLTOOL emit delay-import IAT into `.didat`, as specified
by Microsoft. Most of the code is copied from `.idata`, except that this
section is writeable.  As a side-effect of this, PR 14339 is also fixed.

Using this DEF:

   ```
   ; ws2_32.def
   LIBRARY "WS2_32.DLL"
   EXPORTS
     WSAGetLastError
   ```

and this C program:

   ```
   // delay.c
   #define WIN32_LEAN_AND_MEAN 1
   #include <windows.h>
   #include <stdio.h>

   /////////////////////////////////////////////////////////
   // User code
   /////////////////////////////////////////////////////////

   DWORD WINAPI WSAGetLastError(void);
   extern PVOID __imp_WSAGetLastError;

   int
   main(void)
     {
       fprintf(stderr, "before delay load, __imp_WSAGetLastError = %p\n", __imp_WSAGetLastError);
       SetLastError(123);
       fprintf(stderr, "WSAGetLastError() = %d\n", WSAGetLastError());
       fprintf(stderr, "after delay load, __imp_WSAGetLastError = %p\n", __imp_WSAGetLastError);
       __imp_WSAGetLastError = (PVOID) 1234567;
       fprintf(stderr, "after plain write, __imp_WSAGetLastError = %p\n", __imp_WSAGetLastError);
     }

   /////////////////////////////////////////////////////////
   // Overridden `__delayLoadHelper2` facility
   /////////////////////////////////////////////////////////

   extern char __ImageBase[];
   PVOID WINAPI ResolveDelayLoadedAPI(PVOID ParentModuleBase, LPCVOID DelayloadDescriptor,
                                      PVOID FailureDllHook, PVOID FailureSystemHook,
                                      FARPROC* ThunkAddress, ULONG Flags);
   FARPROC WINAPI DelayLoadFailureHook(LPCSTR name, LPCSTR function);

   FARPROC WINAPI __delayLoadHelper2(LPCVOID pidd, FARPROC* ppfnIATEntry)
   {
     return ResolveDelayLoadedAPI(&__ImageBase, pidd, NULL, (PVOID) DelayLoadFailureHook,
                                  ppfnIATEntry, 0);
   }
   ```

This program used to crash:

   ```
   $ dlltool -nn -d ws2_32.def -y delay_ws2_32.a
   $ gcc -g delay.c delay_ws2_32.a -o delay.exe
   $ ./delay.exe
   before delay load, __imp_WSAGetLastError = 00007FF6937215C6
   Segmentation fault
   ```

After this commit, it loads and calls `WSAGetLastError()` properly, and
`__imp_WSAGetLastError` is writeable:

   ```
   $ dlltool -nn -d ws2_32.def -y delay_ws2_32.a
   $ gcc -g delay.c delay_ws2_32.a -o delay.exe
   $ ./delay.exe
   before delay load, __imp_WSAGetLastError = 00007FF76E2215C6
   WSAGetLastError() = 123
   after delay load, __imp_WSAGetLastError = 00007FFF191FA720
   after plain write, __imp_WSAGetLastError = 000000000012D687
   ```

Reference: https://learn.microsoft.com/en-us/windows/win32/secbp/pe-metadata#import-handling
Co-authored-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
Signed-off-by: Jeremy Drake <sourceware-bugzilla@jdrake.com>
2025-06-13 07:52:29 +02:00
Alan Modra
9efb7cdef4 dlltool invalid free
This is a followup to commt 619f863c55 "dlltool memory leaks".
The name passed to def_name is freed, so if missing we can't just
use "".  strdup it.

	* defparse.y (opt_name): xstrdup empty string.
2025-06-11 07:26:07 +09:30
Alice Carlotti
3d6d08beed MAINTAINERS: Add myself as an AArch64 maintainer 2025-06-09 17:16:56 +01:00
Alan Modra
f2172071e6 elfedit: segv with --enable-x86-feature
PR 33024
	PR 33025
	* elfedit.c (update_gnu_property): Sanity check program headers.
2025-05-28 22:34:50 +09:30
Alan Modra
5e3176dd79 PR 33023 memory leak in objdump when specifying --endian
* objdump.c (disassemble_data): Free modified xvec and replace
	original.
2025-05-28 15:55:27 +09:30
Collin Funk
5328074d84 binutils/doc: Remove '.info' suffix in @ref, etc
Texinfo 7.2 began showing warnings like:

    binutils.texi:882: warning: do not set .info suffix in reference for manual `ld.info'
    binutils.texi:1365: warning: do not set .info suffix in reference for manual `ld.info'

The Texinfo developers plan to stop removing the '.info' suffix
internally in a future release so without this patch the references will
break in the future.

Signed-off-by: Collin Funk <collin.funk1@gmail.com>
2025-05-16 10:37:04 +02:00
H.J. Lu
d1851edfe9 binutils: Don't complain plugin with all LTO sections removed
When all LTO sections have been removed, the BFD lto_type is set to
lto_non_ir_object by bfd_set_lto_type.  In this case, don't complain
needing a plugin when seeing a LTO slim symbol.

bfd/

	PR binutils/32967
	* archive.c (_bfd_compute_and_write_armap): Call
	bfd_lto_slim_symbol_p to check LTO slim symbol.
	* bfd-in2.h: Generated.
	* bfd.c (bfd_lto_slim_symbol_p): New.

binutils/

	PR binutils/32967
	* nm.c (filter_symbols): Call bfd_lto_slim_symbol_p to check
	LTO slim symbol.

ld/

	PR binutils/32967
	* testsuite/ld-plugin/lto-binutils.exp: Run PR binutils/32967
	tests.
	* testsuite/ld-plugin/strip-1a-s-all.nd: New file.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-05-15 08:43:58 +08:00
Alan Modra
c6c8d0b821 resbin: don't pass NULL as printf %s arg
Fix three place where a NULL could be passed to "toosmall".
2025-05-14 21:55:11 +09:30
Richard Earnshaw
3222beac6e Remove Marcus Shawcroft from the MAINTAINERS file
Marcus has resigned from the project.
2025-05-14 11:45:25 +01:00
Matthieu Longo
c5a0d25737 Remove annoying spaces from objcopy.exp 2025-05-14 10:38:13 +01:00
H.J. Lu
717a38e9a0 strip: Add GCC LTO IR support
Add GCC LTO IR support to strip by copying GCC LTO IR input as unknown
object file.  Don't enable LTO plugin in strip unless all LTO sections
should be removed, assuming all LTO sections will be removed with
-R .gnu.lto_.*.  Add linker LTO tests for strip with --strip-unneeded
and GCC LTO IR inputs.

binutils/

	PR binutils/21479
	* objcopy.c: Include "plugin-api.h" and "plugin.h".
	(lto_sections_removed): New.
	(command_line_switch): Add OPTION_PLUGIN.
	(strip_options): Likewise.
	(strip_usage): Display "--plugin NAME".
	(copy_unknown_file): New function.
	(copy_unknown_object): Call copy_unknown_file.
	(copy_archive): Copy input LTO IR member as unknown object.
	(copy_file): Set input target to "plugin" for strip if it is
	unset unless all LTO sections should be removed.  Copy input
	LTO IR file as unknown file.
	(strip_main): Call bfd_plugin_set_program_name. Handle
	OPTION_PLUGIN.  Set lto_sections_removed to true if all GCC
	LTO sections should be removed.
	* doc/binutils.texi: Document --plugin for strip.

ld/

	PR binutils/21479
	* testsuite/ld-plugin/lto-binutils.exp: New file.
	* testsuite/ld-plugin/strip-1a-fat.c: Likewise.
	* testsuite/ld-plugin/strip-1a-fat.rd: Likewise.
	* testsuite/ld-plugin/strip-1b-fat.c: Likewise.
	* testsuite/ld-plugin/strip-1b-fat.rd: Likewise.
	* testsuite/ld-plugin/strip-1a.c: Likewise.
	* testsuite/ld-plugin/strip-1b.c: Likewise.
	* testsuite/lib/ld-lib.exp (run_cc_link_tests): Add optional
	trailing ld options.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-05-14 15:09:40 +08:00
Peter Bergner
61a6e3c7bf MAINTAINERS: Update my email address
Update my email address and move up Surya's name as the main PPC contact.

Signed-off-by: Peter Bergner <bergner@tenstorrent.com>
2025-05-09 18:01:15 -05:00
Jiawei
433372af69 RISC-V: Add Privileged Architecture 1.13 CSRs.
This patch support RISC-V Privileged Architecture 1.13 CSRs 'medelegh' and
'hedelegh'. More details between 1.12 and 1.13 see [1].

[1] https://github.com/riscv/riscv-isa-manual/blob/main/src/priv-preface.adoc

Version log: Remove gas/po changes.

bfd/ChangeLog:

        * cpu-riscv.c: New option.
        * cpu-riscv.h (enum riscv_spec_class): Ditto.

binutils/ChangeLog:

        * doc/binutils.texi: New option.

gas/ChangeLog:

        * NEWS: Add priv-1.13 support.
        * config/tc-riscv.c: New option.
        * configure: Ditto.
        * configure.ac: Ditto.
        * testsuite/gas/riscv/csr-version-1p10.d: New CSR.
        * testsuite/gas/riscv/csr-version-1p10.l: New warning.
        * testsuite/gas/riscv/csr-version-1p11.d: New CSR.
        * testsuite/gas/riscv/csr-version-1p11.l: New warning.
        * testsuite/gas/riscv/csr-version-1p12.d: New CSR.
        * testsuite/gas/riscv/csr-version-1p12.l: New warning.
        * testsuite/gas/riscv/csr.s: New CSR.
        * testsuite/gas/riscv/attribute-15.d: New test.
        * testsuite/gas/riscv/attribute-16.d: New test.
        * testsuite/gas/riscv/csr-version-1p13.d: New test.
        * testsuite/gas/riscv/csr-version-1p13.l: New test.

include/ChangeLog:

        * opcode/riscv-opc.h (CSR_MEDELEGH): New CSR.
        (CSR_HEDELEGH): Ditto.
        (DECLARE_CSR): Ditto.
2025-05-09 12:28:42 +08:00
Alan Modra
4aaf663ded windres: buffer overflow
bin_to_res_menuexitems can be called with random data offsets (and thus
remaining lengths), confusing code that expects 4-byte aligned data.
Prevent an item length adjustment for alignment exceeding the
remaining length and then overflowing.
2025-05-08 09:26:56 +09:30
Alan Modra
a7cae7faf1 windres_get_* functions
windres_get_32 and similar have a length parameter that in most cases
is just the required length, so it is redundant.  The few cases where
a variable length is passed are all in resrc.c.  So, get rid of the
length parameter and introduce wrappers in resrc.c to check the
length.
2025-05-06 17:05:40 +09:30
Jan Beulich
36e66b193b Arm/COFF: accept .def outside of CCS mode
There's no reason to reject this common COFF directive when it doesn't
have any other meaning.
2025-05-02 10:05:12 +02:00
H.J. Lu
f72c4fa3d5 dwarf: Properly check holes in .debug_ranges/debug_rnglists
Don't warn if the offset of the first entry in .debug_rnglists starts
right after the header.  Warn holes in .debug_ranges and debug_rnglists
sections only if the last end pointer isn't the same as the current
start pointer.

	PR binutils/32927
	* dwarf.c (display_debug_ranges_list): Return the pointer to the
	end.
	(display_debug_ranges): Don't warn if the offset of the first
	entry in .debug_rnglists starts right after the header.  Warn a
	hole only if the last end pointer is the same as the next pointer.
	* testsuite/binutils-all/x86-64/dwarf4.s: New file.
	* testsuite/binutils-all/x86-64/dwarf5.s: Likewise.
	* testsuite/binutils-all/x86-64/pr32927-1.d: Likewise.
	* testsuite/binutils-all/x86-64/pr32927-2.d: Likewise.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Co-Authored-By: Alan Modra <amodra@gmail.com>
2025-05-01 13:52:15 +09:30
H.J. Lu
82bdc396a4 dwarf: Dump .debug_loclists only for DWARF-5
.debug_loclists section is loaded into debug_information as DWARF-5 debug
info and .debug_loc section is loaded into debug_information as pre-DWARF-5
debug info.  When dumping .debug_loc section, we should only process
pre-DWARF-5 debug info in debug_information.  When dumping .debug_loclists
section, we should only process DWARF-5 info in debug_information.

binutils/

	PR binutils/32809
	* dwarf.c (display_debug_loc): Dump .debug_loclists only for
	DWARF-5.

ld/

	PR binutils/32809
	* testsuite/ld-x86-64/dwarf4.s: New file.
	* testsuite/ld-x86-64/dwarf5a.s: Likewise.
	* testsuite/ld-x86-64/dwarf5b.s: Likewise.
	* testsuite/ld-x86-64/pr32809.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run pr32809.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2025-04-29 14:25:38 +08:00
Surya Kumari Jangala
f7745f8cef Update binutils/MAINTAINERS for PPC
binutils/
	* MAINTAINERS: Add myself as PPC maintainer.
2025-04-28 03:37:07 -05:00
Alan Modra
d2533f464f rescoff: close bfd on failure paths
Also free malloc'd relocs.
2025-04-21 09:01:50 +09:30
Alan Modra
46efd5fb30 buffer overrun in read_coff_res_dir
* rescoff.c (read_coff_res_dir): Add more sanity checking.
	Tidy and correct existing checks.
2025-04-16 14:37:17 +09:30
Alan Modra
c3fd596022 resbin.c formatting fixes
Also remove unnecessary casts on memory alloc function returns.
2025-04-16 14:37:17 +09:30
Alan Modra
d4c57933d6 Re: windres: buffer overflow in bin_to_res_toolbar
Commit 9e68cae4fd broke the check I added in commit 4846e543de.
Add missing "return NULL".
2025-04-16 14:37:17 +09:30
Marek Pikuła
88891208c3 RISC-V: Add missing disassembler option max
The flag already exists but it's not been exposed to user.

Signed-off-by: Marek Pikuła <m.pikula@partner.samsung.com>
2025-04-15 10:59:51 +08:00
Alan Modra
9e68cae4fd windres: don't exit so much on errors in read_coff_rsrc
windres code has the habit of exiting on any error.  That's not so
bad, but it does make oss-fuzz ineffective when testing windres.  Fix
many places that print errors and exit to instead print the error and
pass status up the call chain.  In the process of doing this, I
noticed write_res_file was calling bfd_close without checking return
status.  Fixing that resulted in lots of testsuite failures.  The
problem was a lack of bfd_set_format in windres_open_as_binary, which
leaves the output file as bfd_unknown format.  As it happens this
doesn't make any difference in writing the output binary file, except
for the bfd_close return status.
2025-04-15 06:59:15 +09:30
Alan Modra
4846e543de windres: buffer overflow in bin_to_res_toolbar
oss-fuzz testcase manages to hit a buffer overflow.  Sanity check
by passing the buffer length to bin_to_res_toolbar and ensuring reads
don't go off the end of the buffer.
2025-04-15 06:59:15 +09:30
Jan Beulich
e71f5f09ce nm: fall back to heuristic when ELF symbol has zero size
Size being set for a symbol isn't a strict requirement in ELF. For ones
not having their size set, fall back to the same logic as used for non-
ELF, non-COFF symbols.

While there switch to using elf_symbol_from() instead of kind of open-
coding it.
2025-04-07 12:45:30 +02:00
Jan Beulich
6fe5e01b13 nm: also retrieve size for COFF function symbols
Like ELF for all symbols, COFF can record size for at least function
ones. Use that - if available - in preference to the distance-to-next-
symbol heuristic.

To be able to use the new test there, make TI C54x follow TI C4x in
providing .sdef to cover for .def already having different meaning.
2025-04-07 12:45:11 +02:00
Jan Beulich
4fa9476ad2 objcopy: also check --file-alignment option argument
... to be a power of two, just like --section-alignment does.
2025-04-04 10:25:31 +02:00
Jan Beulich
379535a2e6 binutils: run objcopy set-section-alignment also for COFF
There's no reason to limit this to just ELF. TI C30 and Z8k don't encode
section alignment in the section entries though (which can't be quite
right, or there would need to be another means by which to express
alignment needs), so --set-section-alignment simply has no effect there.
2025-04-04 10:25:16 +02:00
Jan Beulich
43ea7d00a7 objcopy: constrain --section-alignment to PE binaries again
PR binutils/32732

The --set-section-alignment option is what ought to be used on object
files; --section-alignment should be affecting PE binaries only, and
only the value stored in the header. Sections don't individually have
alignment recorded there; see 6f8f6017a0 ("PR27567, Linking PE files
adds alignment section flags to executables").

Undo the core part of 121a3f4b4f ("Update objcopy's
--section-alignment option so that it sets the alignment flag on..."),
which includes removing the testcase again, while leaving all secondary
changes in place. (Note that the testcase did fail anyway for
i?86-interix, with objdump saying "option -P/--private not supported by
this file".)
2025-04-04 10:24:56 +02:00
Jan Beulich
cc0693d394 ar/objcopy: harmonize .exe suffix stripping
With it only being the tail of the name which wants checking, using
lbasename() isn't helpful. Mirror what objcopy.c:main() does to ar.c,
merely chaning the plain int of the local variable to size_t.
2025-04-04 10:20:31 +02:00
Jan Beulich
25a0668a95 binutils: properly split ar and ranlib
By not linking the exact same object file twice, in particular ranlib can
benefit quite a bit from the compiler eliminating dead code.
2025-04-04 10:20:14 +02:00
Jan Beulich
2fb3d389d8 binutils: properly split objcopy and strip
By not linking the exact same object file twice, in particular strip can
benefit quite a bit from the compiler eliminating dead code.
2025-04-04 10:19:51 +02:00
Alan Modra
6c3458a8b7 PR32829, SEGV on objdump function debug_type_samep
u.kenum is always non-NULL, see debug_make_enum_type.

	PR 32829
	* debug.c (debug_type_samep): Correct incomplete enum test.
	(debug_write_type): Remove dead code.
2025-04-01 23:45:46 +10:30