Commit Graph

8038 Commits

Author SHA1 Message Date
Xi Ruoyao
99f48156dd LoongArch: Fix symbol size after relaxation
There's a logic error in loongarch_relax_perform_deletes: when there's
not any delete operation of which the start address is strictly smaller
than the symbol address, splay_tree_predecessor() will return nullptr
and the symbol size will be unchanged even if some bytes of it are
removed.

Make the logic more complete to fix this issue.  Also factor out the
symbol size adjustment logic into a function to avoid code bloating.

Tested-by: WANG Xuerui <git@xen0n.name>
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
2025-08-08 16:52:19 +08:00
Alan Modra
2a07e06e26 Re: Re-enable development on the 2.45 branch
regen configure for the version bump 2.45 -> 2.45.0
2025-07-28 09:08:39 +09:30
Nick Clifton
2bc7af1ff7 This is the 2.45 release 2025-07-27 09:56:42 +01:00
Rainer Orth
21b517c1d5 ld: Force SHELL=/bin/bash in ld for Solaris [PR32580]
As described in PR ld/32580, when using SHELL=/bin/sh or /bin/ksh on
Solaris, the generated linker scripts get corrupted.  So far, the only
workaround is to enforce /bin/bash instead.

This is a major nuisance for developers and users alike, so this patch
automates this by overriding SHELL in ld/configure.ac.

Tested on amd64-pc-solaris2.11 in three configurations:

* CONFIG_SHELL unset

* CONFIG_SHELL=/bin/ksh

* CONFIG_SHELL='/bin/bash --norc'

In the first two cases, SHELL was set to /bin/bash as desired, while in
the third it was left unchanged.

2025-07-24  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	ld:
	PR ld/32580
	* configure.ac <*-*-solaris2*>: Enforce SHELL=/bin/bash.
	* configure: Regenerate.

(cherry picked from commit 96ad2fd3c0)
2025-07-25 09:50:37 +02:00
Alan Modra
44cd1f92e5 PR 33197 [AVR] Incorrect syntax in generated ldscript
Rearrange scripttempl/avr.sc to avoid oddities of shells expanding
${RELOCATING+stuff} in here documents where "stuff" contains quoted
strings.  Also I think it is better to avoid multi-line "stuff" as it
can be tricky to spot the ending brace.

(cherry picked from commit ae114fb523)
2025-07-24 09:42:24 +02:00
Nick Clifton
612c12759a Updated translations for various sub-directories 2025-07-22 15:57:38 +01:00
Torbjörn SVENSSON
888f048f72 ld: Rename a file on Windows fails if target already exists
To rename a file on Windows, the target name cannot exist. Removing file
prior to renaming ensures this is handled.
To remove a file on Windows, the file cannot be open. Closing the bfd
handle ensures this is handled.
Moved call to free on isympp / osympp to after bfd is closed to align
with comment earlier in the cmdline_add_object_only_section function.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
(cherry picked from commit 233cd59464)
2025-07-22 16:41:16 +02:00
H.J. Lu
39363ad0a0 x86-64: Remove sframe relocs against discarded sections
Since unlike eh_frame editing code, sframe editing code keeps
R_X86_64_NONE reloc as is, its r_offset is wrong, we must not
generate R_X86_64_NONE reloc in sframe section against discarded
sections for "ld -r".

bfd/

	PR ld/33156
	* elf64-x86-64.c (elf_x86_64_relocate_section): Also remove
	sframe relocations against discarded sections for "ld -r".

ld/

	PR ld/33156
	* testsuite/ld-elf/eh-group.exp (as_gsframe): New.
	Assemble eh-group.o with $as_gsframe.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit d7f343eaad)
2025-07-16 07:53:45 -07:00
H.J. Lu
b4782f2504 sframe: Allow input R_*_NONE relocations
"ld -r" generates R_*_NONE relocations in sframe section if input
relocations in sframe section are against discarded section.  Allow
input R_*_NONE relocations if there are more relocation entries than
SFrame entries, instead of assuming number of SFrame entries == number
of relocation entries.

bfd/

	PR ld/33127
	* elf-sframe.c (sframe_decoder_init_func_bfdinfo): Allow input
	R_*_NONE relocations if there are more relocation entries than
	SFrame entries.

ld/

	PR ld/33127
	* testsuite/ld-x86-64/sframe-reloc-2a.s: New file.
	* testsuite/ld-x86-64/sframe-reloc-2b.s: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run PR ld/33127 tests.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 5f9bf0cf71)
2025-07-16 07:53:22 -07:00
H.J. Lu
64304170aa ld: Clear map_head_is_link_order for .gnu_object_only
Clear map_head_is_link_order when generating .gnu_object_only section so
that lang_add_section can add new sections and .sframe sections will be
properly merged by _bfd_elf_merge_section_sframe.

	PR ld/33146
	* ldlang.c (cmdline_emit_object_only_section): Clear
	map_head_is_link_order.
	* testsuite/ld-plugin/lto.exp (as_gsframe): New.
	(lto_link_tests): Add $as_gsframe to compile lto-4b.o and
	lto-4c.o.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
(cherry picked from commit 939eb467b2)
2025-07-16 07:53:02 -07:00
Alan Modra
78a230e080 Re: gas: Move gas_sframe_check to binutils-common.exp
PR ld/33146

Correct TCL errors trying to access error output file in commit
ef7a634dc0.  In fact, get rid of the output file test entirely since
gas exit status is sufficient.

Also there is no need to firstly check for ELF support.

Set check_as_sframe_result, and remove ld-lib.exp check_as_sframe.

(cherry picked from commit a57a3a169e)
2025-07-16 07:52:40 -07:00
Nick Clifton
cfa55064f4 Fix compile time warning message about optarg parameter shadowing global variable 2025-07-13 11:35:28 +01:00
Nick Clifton
0a86694dfa Update version number on 2.45 branch 2025-07-13 08:57:43 +01:00
Nick Clifton
5c778308bd Add markers for 2.45 branch 2025-07-13 08:35:45 +01:00
Indu Bhagat
b9b7bbb466 ld/aarch64elf: add support for DT_AARCH64_MEMTAG_STACK dynamic tag
Add new command line option -z memtag-stack for aarch64 elf.  This
option instructs the linker to generate the necessary dynamic tag
DT_AARCH64_MEMTAG_STACK, which the dynamic loader can then use to
protect the stack memory with PROT_MTE.  Linker issues an
'unrecognized option' error when -z memtag-stack is specified for
non-aarch64 based emulations.

readelf displays the dynamic tag when present:

$ readelf -d <exectutable>
Dynamic section at offset 0xfdd8 contains XX entries:
Tag        Type                         Name/Value
0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
0x000000000000000c (INIT)               0x400520
0x000000000000000d (FINI)               0x400b64
0x0000000000000019 (INIT_ARRAY)         0x41fdc8
...                 ...                 ...
0x000000007000000c (AARCH64_MEMTAG_STACK) 0x1
...                 ...                 ...

ChangeLog:

        * bfd/elfnn-aarch64.c (elfNN_aarch64_late_size_sections): Emit
	DT_AARCH64_MEMTAG_STACK dynamic tag.
        * bfd/elfxx-aarch64.h (struct aarch64_memtag_opts): Add new
	member for tracking whether stack access uses MTE insns.
        * binutils/readelf.c (get_aarch64_dynamic_type): Handle
	DT_AARCH64_MEMTAG_STACK.
        * ld/emultempl/aarch64elf.em: Add new command line option.
        * ld/ld.texi: Add documentation for -z memtag-stack.
        * ld/testsuite/ld-aarch64/aarch64-elf.exp: Add new test.
        * ld/testsuite/ld-aarch64/dt-memtag-stack.d: New test.

include/ChangeLog:

        * elf/aarch64.h (DT_AARCH64_MEMTAG_STACK): New definition.
2025-07-12 11:33:25 +02:00
Indu Bhagat
97d71f2366 ld/aarch64elf: add support for DT_AARCH64_MEMTAG_MODE dynamic tag
Add new command line option -z memtag-mode=<mode> to aarch64 elf,
where <mode> can be one of none, sync, or async.  For mode of sync or
async, a DT_AARCH64_MEMTAG_MODE dynamic tag with a value of 0 or 1
respectively is emitted.

readelf displays the dynamic tag when present:

$ readelf -d <exectutable>
Dynamic section at offset 0xfdd8 contains XX entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000c (INIT)               0x400520
 0x000000000000000d (FINI)               0x400b64
 0x0000000000000019 (INIT_ARRAY)         0x41fdc8
 ...                 ...                 ...
 0x0000000070000009 (AARCH64_MEMTAG_MODE) 0x1
 ...                 ...                 ...

Note that this patch doesn't add support for the "asymm" MTE mode,
which is an Armv8.7 extension.

ChangeLog:

        * bfd/elfnn-aarch64.c (struct elf_aarch64_link_hash_table): Add
	new member for memtag properties.
        (bfd_elfNN_aarch64_set_options): New argument to pass memtag
	properties.
	(elfNN_aarch64_late_size_sections): Emit DT_AARCH64_MEMTAG_MODE
	dynamic tag.
        * bfd/elfxx-aarch64.h: New definition for the various memtag
	properties.
        * binutils/readelf.c (get_aarch64_dynamic_type): Handle
	DT_AARCH64_MEMTAG_MODE.
        * ld/emultempl/aarch64elf.em: Likewise.
        * ld/ld.texi: Add documentation for the new option
	-z memtag-mode.
        * ld/testsuite/ld-aarch64/aarch64-elf.exp: New test.
        * ld/testsuite/ld-aarch64/dt-memtag.d: New test.
        * ld/testsuite/ld-aarch64/dt-memtag-mode.s: New test.

include/ChangeLog:

        * elf/aarch64.h (DT_AARCH64_MEMTAG_MODE): New definition.
2025-07-12 11:33:25 +02:00
Indu Bhagat
427363b461 ld: aarch64: make EH Frame parsing aware of augmentation char 'G'
As per the DWARF for the Arm 64-bit Architecture (AArch64)
specification, the augmentation char 'G' indicates that associated
frames may modify MTE tags on the stack space they use.

Add knowledge of the 'G' augmentation char to the EH Frame parsing
code.

ChangeLog:

        * bfd/elf-eh-frame.c (_bfd_elf_parse_eh_frame): Accommodate
	augmentation char 'G'.
        * ld/testsuite/ld-aarch64/aarch64-elf.exp: New test.
        * ld/testsuite/ld-aarch64/mte-tagged-frame-bar.s: New test.
        * ld/testsuite/ld-aarch64/mte-tagged-frame-foo.s: New test.
        * ld/testsuite/ld-aarch64/mte-tagged-frame.d: New test.
2025-07-12 11:33:25 +02:00
Indu Bhagat
6ab3f09a68 gas: elf: binutils: add new section type SHT_GNU_SFRAME
So far, SFrame sections were of type SHT_PROGBITS.

As per ELF specification, SHT_PROGBITS indicates that the section holds
information defined by the program, whose format and meaning are
determined solely by the program.

On the linker side, SHT_PROGBITS should be reserved for the simple "cat
contents after applying relocs" semantics.

Currently, the only way to know that a section contains SFrame stack
trace data is if consumer checks for section name.  Such a check for
section name is not quite conformant to ELF principles.

Some of this was discussed here
https://sourceware.org/pipermail/binutils/2025-March/140181.html

With this change, the SFrame sections generated by gas, ld will have
section type set to SHT_GNU_SFRAME.   The new section type is defined in
the SHT_LOOS/SHT_HIOS space.  The SFrame parsing routine
_bfd_elf_parse_sframe () now admits sections only when the the section
type is SHT_GNU_SFRAME.

No special handling / validation is done at the moment for the case of
manual creation of SFrame sections via obj_elf_section ().  Add function
level comments for now to add a note about this.

Although the default handling for (sh_type >= SHT_LOOS && sh_type <=
SHT_HIOS) is sufficient when SHT_GNU_SFRAME is in that range, it makes
sense to add it as a case of its own.

bfd/
	* elf-sframe.c (_bfd_elf_parse_sframe): Check if section type is
	SHT_GNU_SFRAME.
	(_bfd_elf_set_section_sframe): Set SHT_GNU_SFRAME for output
	SFrame section.
	* elflink.c (obj_elf_section): Use section type for check
	instead of section name.
	* elfxx-x86.c: Set SHT_GNU_SFRAME for SFrame sections for
	.plt* sections.
	* elf.c (bfd_section_from_shdr): Add case for SHT_GNU_SFRAME.
binutils/
	* readelf.c (get_os_specific_section_type_name): Add
	SHT_GNU_SFRAME.
gas/
	* NEWS: Announce emitted SFrame sections have SHT_GNU_SFRAME
	set.
	* config/obj-elf.c (obj_elf_attach_to_group): Add comments to
	indicate no special handling for SFrame yet.
	* dw2gencfi.c (cfi_finish): Set SHT_GNU_SFRAME for emitted
	SFrame section.
ld/
	* NEWS: Announce emitted SFrame sections have SHT_GNU_SFRAME
	set.
gas/testsuite/
	* gas/cfi-sframe/cfi-sframe.exp: Add new test.
	* gas/cfi-sframe/cfi-sframe-common-1b.d: New test.
	* gas/cfi-sframe/cfi-sframe-common-1b.s: New test.
include/
	* elf/common.h (SHT_GNU_SFRAME): Add new section type for SFrame
	stack trace information.
libsframe/doc/
	* sframe-spec.texi: Add expected ELF section type.
2025-07-11 23:32:58 -07:00
WANG Xuerui
8b0a598853 {binutils, gas, ld}/NEWS: Announce LoongArch changes in 2.45
Signed-off-by: WANG Xuerui <git@xen0n.name>
2025-07-12 10:36:10 +08:00
WANG Xuerui
792e4d23c9 LoongArch: Un-skip cross-segment alignment compensation during relax pass 2
It turned out wrong to skip compensating for segment alignment if the
current section is closed for deletion, as my recent system update with
binutils trunk revealed link failures of many high-profile packages such
as ffmpeg, numpy and wxGTK -- the dreaded "relocation truncated to fit"
errors regarding improperly produced R_LARCH_PCREL20_S2.

As it's near 2.45 branching time, revert the problematic change and
XFAIL the original test case for now.

Suggested-by: Xi Ruoyao <xry111@xry111.site>
Signed-off-by: WANG Xuerui <git@xen0n.name>
2025-07-12 10:36:10 +08:00
Alan Modra
7ea90d9316 MIPS: Fix linker for REL TLS HI16/LO16 relocs
With REL targets TLS HI16/LO16 relocations need to combine the low part
with the high part just as all the remaining HI16/LO16 relocations, so
as to determine the borrow in calculation correctly.

2025-07-12  Alan Modra  <amodra@gmail.com>

bfd/
	PR 19977
	* elfxx-mips.c (tls_hi16_reloc_p): New function.
	(mips_elf_add_lo16_rel_addend): Handle tls relocs.
	(_bfd_mips_elf_relocate_section): Likewise.

2025-07-12  Maciej W. Rozycki  <macro@orcam.me.uk>

ld/
	PR 19977
	* testsuite/ld-mips-elf/pr19977.d: New test.
	* testsuite/ld-mips-elf/pr19977-mips16.d: New test.
	* testsuite/ld-mips-elf/pr19977-micromips.d: New test.
	* testsuite/ld-mips-elf/pr19977-r.d: New test.
	* testsuite/ld-mips-elf/pr19977-r-mips16.d: New test.
	* testsuite/ld-mips-elf/pr19977-r-micromips.d: New test.
	* testsuite/ld-mips-elf/pr19977-r.s: New test source.
	* testsuite/ld-mips-elf/pr19977.ld: New test linker script.
	* testsuite/ld-mips-elf/mips-elf.exp: Run the new tests.
2025-07-12 01:25:53 +01:00
Maciej W. Rozycki
68f5cb38c2 PR 19977: MIPS: Add missing pairing for REL PCHI/PCLO relocations
Just as with all HI/LO 16-bit partial relocations the newly-introduced
MIPSr6 PC-relative R_MIPS_PCHI16 and R_MIPS_PCLO16 relocations require
pairing for correct borrow propagation from the low part to the high
part with REL targets, another case for PR 19977.

Unlike with absolute relocation, there is a complication here in that
both parts represent a calculation that is relative to the PC at the
individual relocation's location rather than both referring to the
location of the R_MIPS_PCHI16 relocation, normally applied to an AUIPC
instruction, the location of which is used for the run-time calculation
executed by hardware.

To take this semantics into account, the addend of the R_MIPS_PCLO16
relocation matching a given R_MIPS_PCHI16 relocation is expected to be
adjusted in the source assembly file for the distance between the two
relocations in a single pair, so that once both relocations have been
calculated by the linker, the expression calculated at run time is such
as if the combined 32-bit immediate was added at the location of the
AUIPC instruction.

So for matching R_MIPS_PCHI16 and R_MIPS_PCLO16 relocations into pairs
GAS needs to check for the distance between the two relocations to be
equal to the difference between the addends supplied, and then the
linker has to subtract the low part of the distance between the two
relocations from the low part in calculating the high part, so as to
factor in any borrow.

A further complication is that `_bfd_mips_elf_lo16_reloc' handler is
supplied with the addend differently depending on whether it has been
called by GAS via `bfd_install_relocation', or by the generic linker via
`bfd_perform_relocation'.  In the former case the addend is supplied
with the relocation itself while in the latter one it comes from the
field being relocated.

We currently ignore the addend supplied with the relocation and it works
for calculating absolute high-part relocations, because the same addend
has been previously supplied with them when `_bfd_mips_elf_hi16_reloc'
was called, however this approach does not work for the PC-relative case
because as noted above the low-part addend is different and we need to
consistently apply the distance adjustment both with GAS and LD.

Since the supplied addend and one retrieved from field being relocated
won't ever be both nonzero, just use the sum of the two values.

The low-part addend in `mips_elf_add_lo16_rel_addend' always comes from
the field being relocated, so there's no complication there, we just
need to apply the same adjustment.

New linker test cases verify that the same ultimate machine code is
produced both for ELF and S-record output formats, ensuring that the
both the MIPS/ELF linker and the generic linker behave in the correct
way, consistent with each other.
2025-07-12 01:25:53 +01:00
Maciej W. Rozycki
31b86e2ff9 MIPS/LD/testsuite: Remove duplicate HI/LO relocation test dump files
There are only nonessential differences between corresponding o32 and
n32 HI/LO relocation test dump files, so reduce the number of files by
reusing the same dump between the two ABIs.  Adjust test naming, also
for the n64 ABI, for consistency with other tests.
2025-07-12 01:25:53 +01:00
Jens Remus
22472454fa s390: Add SFrame stack trace information for .plt section
Enable SFrame stack tracing through PLT entries.  Based on x86-64.

On s390x both PLT0 and PLTn entries are 32-bytes in size.  Their code
neither alters the stack pointer (SP), frame pointer (FP), nor return
address (RA) registers.  Therefore the PLT0 can be represented using
a SFrame FDE of type PCINC with a single SFrame FRE and the PLTn can
be represented using a SFrame FDE of type PCMASK, with a repetition
block size of 32 (PLTn size), and a single SFrame FRE.

Note that as both the PLT0 entry and the PLTn entries have equal size
and could both be represented using the identical SFrame FRE, the whole
.plt section on s390x could be represented using a single SFrame FDE of
type PCMASK, with a repetition block size of 32 (PLT0 and PLTn size),
and a single SFrame FRE.  Keep the x86-64 logic with separate SFrame
FDEs for PLT0 and PLTn, to ease potential generalization of the .sframe
for .plt generation logic among architectures.

bfd/
	* elf64-s390.c: Include sframe.h and sframe-api.h.
	(PLT_SFRAME_FDE_START_OFFSET, SFRAME_PLT0_MAX_NUM_FRES,
	SFRAME_PLTN_MAX_NUM_FRES, elf_s390x_sframe_plt_fre,
	elf_s390x_sframe_plt): New .sframe template for .plt section.
	(elf_s390_link_hash_table): Add plt_cfe_ctx, plt_sframe, and
	sframe_plt fields.
	(_bfd_s390_elf_create_sframe_plt): New function.  Fill in
	.sframe section for .plt section.
	(_bfd_s390_elf_write_sframe_plt): New function.  Write .sframe
	section.
	(elf_s390_create_dynamic_sections): Create .sframe section for
	.plt section.
	(elf_s390_late_size_sections): Call
	_bfd_s390_elf_create_sframe_plt and
	_bfd_s390_elf_write_sframe_plt.
	(elf_s390_finish_dynamic_sections): Write .plt section start
	into .sframe FDE covering .plt section.  Call
	_bfd_elf_merge_section_sframe on htab->plt_sframe.

ld/
	* NEWS: Add news entry.

ld/testsuite/
	* ld-s390/s390.exp: Add new test.
	* ld-s390/sframe-plt-1.d: New linker-generated .sframe for .plt
	test.
	* ld-s390/sframe-simple-1.d: Adjust expected test output due to
	linker-generated .sframe for .plt.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-07-11 10:29:40 +02:00
Jens Remus
d27d82f560 s390: Initial support to generate .sframe from CFI directives in assembler
This introduces initial support to generate .sframe from CFI directives
in assembler on s390 64-bit (s390x).  Due to SFrame V2 format
limitations it has the following limitations, some of them getting
addressed by subsequent patches, which cause generation of SFrame FDE
to be skipped:

- SFrame FP/RA tracking only supports register contents being saved on
  the stack (i.e. .cfi_offset).  It does not support FP/RA register
  contents being saved in other registers (i.e. .cfi_register).  GCC on
  s390x can be observed to save the FP/RA register contents in floating-
  point registers, but only in leaf functions.
  This issue is detailed further and resolved in the subsequent commit
  "s390: Represent FP/RA saved in register in SFrame".

- SFrame FP/RA tracking cannot represent FP without RA saved.  This is
  because the format assumes SFrame FDE offset2 to be the RA offset, if
  there are two offsets, and offset3 to be the FP offset, if there are
  three offsets.  There is no mean to distinguish whether offset2 is the
  RA or FP offset, if there are only two offsets.
  This issue is detailed further and resolved in the subsequent commit
  "s390: Represent FP without RA saved in SFrame".

- SFrame assumes a dedicated FP register number.  The s390x ELF ABI [1]
  does only designate register 11 as preferred FP register number.  In
  general GCC and Clang on s390x use register 11 as frame pointer.
  GCC on s390x can be observed to use register 14 as frame pointer in
  the stack clash protector in the function prologue.
  glibc on s390x contains hand-written assembler code that uses
  register 12 as frame pointer.

This s390x support is largely based on the AArch64 support from commit
b52c4ee466 ("gas: generate .sframe from CFI directives").

The SFrame ABI/arch identifier SFRAME_ABI_S390X_ENDIAN_BIG is introduced
for s390x and added to the SFrame format specification.

The s390x ELF ABI [1] specifies the following C calling conventions for
s390x architecture:
- Register 15 is the stack pointer (SP).
- Register 14 contains the return address (RA) at function entry.
- There is no dedicated frame pointer register.  Register 11 is the
  preferred frame pointer (FP). [2]  GCC and Clang in general use
  register 11 as frame pointer.
- The CFA is defined as SP at call site +160. [3]  The SP at call site
  can therefore be derived from the CFA using a SP value offset from CFA
  of -160.

The s390x ELF ABI [1] does not assign any standard save slot to each
register in the register save area of a stack frame.  Neither the
return address (RA, r14) nor preferred frame pointer (FP, r11)
necessarily need to be saved.  Therefore SFrame RA and FP tracking is
used.

Support for SFrame on s390 is only enabled for the 64-bit s390x ELF ABI
(z/Architecture with 64-bit addressing mode).  It is disabled for the
32-bit s390 ELF ABI (ESA/390 or z/Architecture with 32-bit addressing
mode).

s390x-specific SFrame assembler and linker tests are added, including
error tests for use of a non-preferred frame pointer (FP) register and
specification of a non-default return address (RA) register.

[1]: s390x ELF ABI, https://github.com/IBM/s390x-abi/releases
[2]: s390x ELF ABI, commit f00421825979 ("Add information about the frame
     pointer register"),
     https://github.com/IBM/s390x-abi/commit/f00421825979
[3]: s390x ELF ABI, commit 4e38ad9c8a88 ("Document the CFA"),
     https://github.com/IBM/s390x-abi/commit/4e38ad9c8a88

include/
	* sframe.h: Add reference to s390x architecture in comments.
	(SFRAME_ABI_S390X_ENDIAN_BIG): Define SFrame ABI/arch identifier
	for s390x.
	(SFRAME_S390X_SP_VAL_OFFSET): Define s390x-specific SP value
	offset from CFA.

libsframe/
	* sframe.c (need_swapping): Add SFRAME_ABI_S390X_ENDIAN_BIG.
	* doc/sframe-spec.texi (SFRAME_ABI_S390X_ENDIAN_BIG, s390x,
	SFRAME_S390X_SP_VAL_OFFSET): Document SFrame ABI/arch identifier
	for s390x, add references to s390x architecture, and document
	s390x-specifics, such as the SP value offset from CFA of -160.

gas/
	* config/tc-s390.h: s390x support to generate .sframe from CFI
	directives in assembler.
	(support_sframe_p): Define.
	(SFRAME_CFA_SP_REG, SFRAME_CFA_FP_REG, SFRAME_CFA_RA_REG):
	Define.
	(sframe_ra_tracking_p): Define.
	(sframe_cfa_ra_offset): Define.
	(sframe_get_abi_arch): Define.
	* config/tc-s390.c: s390x support to generate .sframe from CFI
	directives in assembler.
	(s390_sframe_cfa_sp_reg, s390_sframe_cfa_fp_reg,
	s390_sframe_cfa_ra_reg): New.  Initialize to DWARF register
	numbers of stack pointer (SP, r15), preferred frame pointer
	(FP, r11), and return address (RA, r14) registers.
	(s390_support_sframe_p): New function.  Return true if s390x.
	(s390_sframe_ra_tracking_p): New function.  Return true.
	(s390_sframe_cfa_ra_offset): New function.  Return
	SFRAME_CFA_FIXED_RA_INVALID.
	(s390_sframe_get_abi_arch): New function.  Return
	SFRAME_ABI_S390X_ENDIAN_BIG if s390x, otherwise zero.
	* gen-sframe.c: Add reference to s390x architecture in comments.
	(sframe_xlate_do_val_offset): Add support for s390x-specific
	SFRAME_S390X_SP_VAL_OFFSET.
	* NEWS: Add news entry.

gas/testsuite/
	* gas/cfi-sframe/cfi-sframe.exp: Enable common SFrame tests for
	s390x.  Add s390x-specific SFrame (error) tests.
	* gas/cfi-sframe/cfi-sframe-s390x-1.d: New s390x-specific SFrame
	test.
	* gas/cfi-sframe/cfi-sframe-s390x-1.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-2.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-err-1.d: New s390x-specific
	SFrame error test that uses a non-default frame-pointer register
	as CFA base register.
	* gas/cfi-sframe/cfi-sframe-s390x-err-1.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-err-2.d: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-err-2.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-err-3.d: New s390x-specific
	SFrame error test that uses a non-default return address
	register.
	* gas/cfi-sframe/cfi-sframe-s390x-err-3.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-1.d: New s390x-
	specific SFrame test that saves RA and FP individually on the
	stack.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-1.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-err-1.d: New
	s390x-specific SFrame error test that saves FP and RA
	individually, to trigger FP without RA saved.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-err-1.s: Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-1.d: New
	s390x-specific SFrame error test that saves FP and RA
	individually in registers.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-1.s:
	Likewise.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-2.d: New
	s390x-specific SFrame error test that saves RA and FP
	individually in registers.
	* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-2.s:
	Likewise.

ld/testsuite/
	* ld-s390/s390.exp: Add simple SFrame test.
	* ld-s390/sframe-simple-1.d: New simple SFrame test.
	* ld-s390/sframe-bar.s: Likewise.
	* ld-s390/sframe-foo.s: Likewise.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2025-07-11 10:29:40 +02:00
Jens Remus
1b1ff68e4c s390: Explicitly list linker dump tests
Generating the linker dump test list using file globbing makes it
difficult to exclude specific tests under certain circumstances.  List
them explicitly instead.  This enables to add tests in the future that
can be excluded.  While at it reorganize how s390 linker tests get
run for s390x.

ld/testsuite/
	* ld-s390/s390.exp: Reorganize and explicitly list linker dump
	tests.

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
Mark Goncharov
6589a725f0 RISC-V: Fix libpath_suffix selection for ldscript
When building a cross-compiler ld for RISC-V Linux systems, you can specify
target=riscv64*-linux* to create a linker that supports both 32-bit
(-march=rv32*) and 64-bit (-march=rv64*) architectures.  The specified -march
value populates the EMULATION_NAME variable, which determines the default
linker script selection.  For proper riscv64 target support, the build process
must prepare both elf32lriscv* and elf64lriscv* linker scripts.  These should
align with the standard RISC-V Linux sysroot directory structure.

Signed-off-by: Mark Goncharov <mark.goncharov@syntacore.com>
2025-07-08 18:35:19 +08:00
Linsen Zhou
39c7793ba8 RISC-V: Bind defined symbol locally in PIE
Reference commit 1dcb9720d6

bfd/
	* elfnn-riscv.c (RISCV_COPY_INPUT_RELOC): Bind defined symbol
	locally in PIE.

ld/
	* testsuite/ld-riscv-elf/pie-bind-locally-a.s: New test source.
	* testsuite/ld-riscv-elf/pie-bind-locally-b.s: Likewise.
	* testsuite/ld-riscv-elf/pie-bind-locally-rv32.d: New testcase.
	* testsuite/ld-riscv-elf/pie-bind-locally-rv64.d: Likewise.

Signed-off-by: Linsen Zhou <i@lin.moe>
2025-07-08 11:10:25 +08:00
WANG Xuerui
392f8c40f0 LoongArch: Allow to relax instructions into NOPs after handling alignment
Right now, LoongArch linker relaxation is 2-pass, since after alignment
is done, byte deletion can no longer happen. However, as the alignment
pass also shrinks text sections, new relaxation chances may well be
created after alignment is done. Although at this point we can no longer
delete unused instructions without disturbing alignment, we can still
replace them with NOPs; popular LoongArch micro-architectures can
eliminate NOPs during execution, so we can expect a (very) slight
performance improvement from those late-created relaxation chances.

To achieve this, the number of relax passes is raised to 3 for
LoongArch, and every relaxation handler except loongarch_relax_align is
migrated to a new helper loongarch_relax_delete_or_nop, that either
deletes bytes or fills the bytes to be "deleted" with NOPs, depending on
whether the containing section already has undergone alignment. Also,
since no byte can be deleted during this relax pass, in the pass the
pending_delete_ops structure is no longer allocated, and
loongarch_calc_relaxed_addr(x) degrades to the trivial "return x" in
this case.

In addition, previously when calculating distances to symbols, an
extra segment alignment must be considered, because alignment may
increase distance between sites. However in the newly added 3rd pass
code size can no longer increase for "closed" sections, so we can skip
the adjustment for them to allow for a few more relaxation chances.

A simple way to roughly measure this change's effectiveness is to check
how many pcalau12i + addi.d pairs are relaxed into pcaddi's. Taking a
Firefox 140.0.2 test build of mine as an example:

Before: 47842 pcaddi's in libxul.so
After: 48089

This is a 0.5% increase, which is kind of acceptable for a peephole
optimization like this; of which 9 are due to the "relax"ed symbol
distance treatment.

Signed-off-by: WANG Xuerui <git@xen0n.name>
2025-07-07 18:09:20 +08:00
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
0924a1ca2e ld: bfd: sframe: fix incorrect r_offset in RELA entries
PR/32666  Incorrect .rela.sframe when using ld -r

Input SFrame sections are merged using _bfd_elf_merge_section_sframe (),
which clubs all SFrame FDEs together in one blob and all SFrame FREs in
another.  This, of course, means the offset of an SFrame FDE in the output
section cannot be simply derived from the output_offset of the sections.

Fix this by providing _bfd_elf_sframe_section_offset () which returns
the new offset of the SFrame FDE in the merged SFrame section.

Unlike EH_Frame sections, which also use the _bfd_elf_section_offset (),
to update the r_offset, SFrame sections have distinct merging semantics.
In case of SFrame, the SFrame FDE will not simply sit at location
"sec->output_offset + offset of SFrame FDE in sec".  Recall that information
layout in an SFrame section is as follows:
   SFrame Header
   SFrame FDE 1
   SFrame FDE 2
   ...
   SFrame FDEn
   SFrame FREs (Frame Row Entries)
Note how the SFrame FDEs and SFrame FREs are clubber together in groups
of their own.

Next, also note how the elf_link_input_bfd () does a:
            irela->r_offset += o->output_offset;
This, however, needs to be avoided for SFrame sections because the
placement of all FDEs is at the beginning of the section.  So, rather than
conditionalizing this as follows:
          if (o->sec_info_type != SEC_INFO_TYPE_SFRAME)
            irela->r_offset += o->output_offset;
the implementation in _bfd_elf_sframe_section_offset () does a reverse
adjustment, so that the generic parts of the linking process in
elf_link_input_bfd () are not made to do SFrame specific adjustments.

Add a new enum to track the current state of the SFrame input section
during the linking process (SFRAME_SEC_DECODED, SFRAME_SEC_MERGED) for
each input SFrame section.  This is then used to assert an assumption
that _bfd_elf_sframe_section_offset () is being used on an input SFrame
sections which have not been merged (via
_bfd_elf_merge_section_sframe ()) yet.

bfd/
        * elf-bfd.h: New declaration.
        * elf-sframe.c (_bfd_elf_sframe_section_offset): New definition.
        * elf.c (_bfd_elf_section_offset): Adjust offset if SFrame
	section.
ld/testsuite/
        * ld-x86-64/x86-64.exp: New test.
        * ld-x86-64/sframe-reloc-1.d: New test.
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
Maciej W. Rozycki
7030f7a030 MIPS/LD/testsuite: Remove empty pic-and-nonpic-1-r6.s file
It was never used, pushed by mistake along with pic-and-nonpic-1a-r6.s.
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
ce08b3bb19 MIPS/BFD: Fix RELA handling of borrow in the generic linker
Fix an issue with `_bfd_mips_elf_generic_reloc' not taking into account
any borrow from the lower part in the handling of relocations of the
HI/LO kind and resulting in incorrect calculations made for RELA targets
in the generic used for non-ELF output such as S-records.  This doesn't
trigger for REL targets because they call `_bfd_mips_elf_generic_reloc'
indirectly from `_bfd_mips_elf_lo16_reloc' so as to obtain a complete
32-bit addend from relocation pairs and in calculating the addend the
latter function uses a hack to work around the lack of borrow handling
in the former function.

The MIPS/ELF linker is unaffected as it uses its own calculations.

Correct the calculation of the relevant partial relocations made in
`_bfd_mips_elf_generic_reloc' then to take the borrow into account and
remove the hack from `_bfd_mips_elf_lo16_reloc' as no longer needed.

Add generic linker test cases accordingly expecting the same disassembly
from srec output produced as from ELF output produced by the MIPS/ELF
linker.
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
ae236b71ea MIPS/testsuite: Expand GAS and LD HI/LO relocation coverage
Expand test coverage for HI/LO relocation handling and add conventional
MIPS and microMIPS GAS tests as well as conventional MIPS, microMIPS,
and MIPS16e2 LD tests, covering R_MIPS_HI16, R_MIPS_LO16, R_MIPS16_HI16,
R_MIPS16_LO16, R_MICROMIPS_HI16, and R_MICROMIPS_LO16 relocations, as
well as 64-bit R_MIPS_HIGHEST, R_MIPS_HIGHER, R_MICROMIPS_HIGHEST, and
R_MICROMIPS_HIGHER relocations.

Modify the linker script so as to retain the `.MIPS.abiflags' section so
as to disassemble MIPS16e2 code correctly, as MIPS16e2 ASE information
is only carried in that section and not in ELF file header's `e_flags'.

MIPS16e2 and microMIPS code requires at least the MIPS32r2 ISA (or the
MIPS64r2 one for the n32 and n64 ABIs), which is incompatible with the
`mips:5900' linker output architecture and causes link failures such as:

./ld-new: tmpdir/mips-hilo1.o: linking mips:isa32r2 module with previous mips:5900 modules
./ld-new: failed to merge target specific data of file tmpdir/mips-hilo1.o

Therefore exclude `mips*el-ps2-elf*' targets from microMIPS and MIPS16e2
LD testing.
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
a30fb6667a MIPS/LD/testsuite: Switch mips16-hilo tests to new disassembly format
Switch the o32 and n32 mips16-hilo MIPS LD tests to the new disassembly
format, to reduce discrepancies in output in preparation to reuse for
generic linker tests.

Taking the first line of disassembly output as an example the difference
is:

00500000 <stuff> 6c00      	li	a0,0

vs:

0x0000000000500000 6c00      	li	a0,0

for ELF and srec input respectively with the currently used older format
requested with `--prefix-addresses', but with the new disassembly format
it is exactly the same between the two input formats and no information
that we need is lost in the transition:

  500000:	6c00      	li	a0,0
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
fcb6b96aa3 MIPS/LD/testsuite: Remove symbol table output from mips16-hilo tests
The o32 and n32 mips16-hilo MIPS LD tests request symbol table output
only to discard it in matching.  The symbol table is not relevant to
these tests, so remove it from output requested and adjust matching
patterns accordingly.
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
293e937452 MIPS/testsuite: Fix %hi usage across MIPS16 GAS/LD tests
Fix a couple of places in MIPS GAS and LD R_MIPS16_HI16/R_MIPS16_LO16
relocation tests where the %hi operator has been incorrectly used, but
the %lo operator is expected to complement the preceding %hi operation.
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
51309ac47b MIPS/LD/testsuite: Fix mips16-hilo IRIX 6 emulation failures
IRIX 6 emulations place external small common symbols in the regular
common section instead of the small common section.  With mips16-hilo
test this leads to a different symbol assignment to memory locations
between o32 and n32 ABIs, as follows:

--- o32.map
+++ n32.map
@@ -46,23 +46,22 @@
  *(.sdata)
                 0x00765430                        . = 0x765430

-.bss            0x00765430      0x7d8
+.bss            0x00765430      0x7d9
  *(.bss)
  .bss           0x00765430      0x3f0 tmpdir/mips16-hilo.o
  .bss           0x00765820        0x0 tmpdir/mips16-hilo1.o
  *(COMMON)
- COMMON         0x00765820      0x3e8 tmpdir/mips16-hilo.o
+ COMMON         0x00765820      0x3e9 tmpdir/mips16-hilo.o
                 0x00765820                big_external_common
+                0x00765c08                small_external_common

-.sbss           0x00765c08        0x2
+.sbss           0x00765c09        0x1
  *(.sbss)
- .sbss          0x00765c08        0x1 tmpdir/mips16-hilo.o
+ .sbss          0x00765c09        0x1 tmpdir/mips16-hilo.o
  *(.scommon)
- .scommon       0x00765c09        0x1 tmpdir/mips16-hilo.o
-                0x00765c09                small_external_common

 /DISCARD/
  *(*)
 LOAD tmpdir/mips16-hilo.o
 LOAD tmpdir/mips16-hilo1.o
-OUTPUT(tmpdir/dump elf32-bigmips)
+OUTPUT(tmpdir/dump elf32-nbigmips)

which in turn causes a testsuite regression.  Since the specific mapping
of symbols does not matter for the scope of the test, reorder the small
common section ahead of SBSS, so that the `small_external_common' symbol
ends up in the same place regardless of whether via the regular common
section or the small common section.  Adjust embedded addresses in the
disassembly expected accordingly, removing the regression concerned:

mips-sgi-irix6  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs n32
mips64el-ps2-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs n32
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
990398eea0 MIPS/LD/testsuite: Unify o32/n32 mips16-hilo test output
The mips16-hilo MIPS LD test case is supposed to produce the same final
linked output regardless of whether the o32 or n32 ABI has been chosen
for assembly.  Reuse o32 output for the n32 test then.
2025-07-06 19:22:49 +01:00
Maciej W. Rozycki
6a4b69e3aa MIPS/LD/testsuite: Set architecture for MIPS16 HI/LO tests
Remove regressions across MIPSr6 targets with the MIPS16 HI/LO tests,
which are incompatible with the default architecture of these targets:

mips-img-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mips-img-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mips64-img-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mips64-img-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs n32
mips64el-img-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mips64el-img-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs n32
mipsel-img-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsel-img-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa32r6-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa32r6-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa32r6el-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa32r6el-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa64r6-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa64r6-linux-gnuabi64  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa64r6-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa64r6el-elf  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa64r6el-linux-gnuabi64  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
mipsisa64r6el-linux  -FAIL: R_MIPS16_HI16 and R_MIPS16_LO16 relocs
2025-07-06 19:22:49 +01:00
Jan Beulich
52be9c1ba3 cris/testsuite: don't use --em=
Using such abbreviations is fine when written on an interactive command
line by a human. In scripts and alike, doing so risks colliding with
later option additions, as is about to occur for gas: Shortly there'll
be --emit-local-absolute.
2025-07-04 10:40:31 +02:00
Nelson Chu
1c391a084f ld/NEWS,binutils/NEWS: Updated supports for RISC-V zicfiss and zicfilp 2025-06-24 18:15:14 +08:00
Nelson Chu
29cd835cb9 RISC-V: Fxied failed testsuites when building rv32-linux 2025-06-24 18:14:48 +08:00
Kito Cheng
9b4b518ece RISC-V: Support for unlabeled landing pad PLT generation
This patch adds support for generating unlabeled landing pad PLT entries
for the RISC-V architecture. Unlabeled landing pad will place a LPAD
instruction at the PLT entry and PLT header, also PLT header will have
few changes due to the offset is different from the original one.

Ref: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/417
2025-06-24 18:14:45 +08:00
Kito Cheng
84eb7d284b RISC-V: Implment the merge logic for GNU_PROPERTY_RISCV_FEATURE_1_AND
GNU_PROPERTY_RISCV_FEATURE_1_AND will perform a bitwise AND operation
on the properties of the input files.
2025-06-24 18:14:42 +08: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