]> git.ipfire.org Git - thirdparty/binutils-gdb.git/log
thirdparty/binutils-gdb.git
2 weeks agogas: elf: binutils: add new section type SHT_GNU_SFRAME
Indu Bhagat [Sat, 12 Jul 2025 06:32:58 +0000 (23:32 -0700)] 
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.

2 weeks agogas: sframe: guard block with support_sframe_p
Indu Bhagat [Sat, 12 Jul 2025 06:31:50 +0000 (23:31 -0700)] 
gas: sframe: guard block with support_sframe_p

SFrame is generated for ELF targets only.  Guard the block with
support_sframe_p like others for consistency.

Also, in a later commit, we would like to do a:
  elf_section_type (sframe_seg) = SHT_GNU_SFRAME;

This cannot be done for non-ELF targets, hence the need to guard with
some pre-processor conditional to enable it for only OBJ_ELF.  Guarding
with support_sframe_p works for now, because those targets that support
SFrame define support_sframe_p:
  - x86_64 and aarch64 define support_sframe_p when OBJ_ELF is defined
  - s390x has no non-LEF target.

We continue to issue an error on targets where SFrame is not supported:
    .sframe not supported for target

gas/
* dw2gencfi.c (cfi_finish): Guard with support_sframe_p.
(support_sframe_p): Remove stub to define to false for backends
not supporting SFrame.

2 weeks ago{binutils, gas, ld}/NEWS: Announce LoongArch changes in 2.45
WANG Xuerui [Fri, 11 Jul 2025 07:49:08 +0000 (15:49 +0800)] 
{binutils, gas, ld}/NEWS: Announce LoongArch changes in 2.45

Signed-off-by: WANG Xuerui <git@xen0n.name>
2 weeks agoLoongArch: Un-skip cross-segment alignment compensation during relax pass 2
WANG Xuerui [Fri, 11 Jul 2025 07:49:07 +0000 (15:49 +0800)] 
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>
2 weeks agoMIPS: Fix linker for REL TLS HI16/LO16 relocs
Alan Modra [Sat, 12 Jul 2025 00:25:53 +0000 (01:25 +0100)] 
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.

2 weeks agoMIPS: Correct HI/LO rel reloc howto special_function entries
Alan Modra [Sat, 12 Jul 2025 00:25:53 +0000 (01:25 +0100)] 
MIPS: Correct HI/LO rel reloc howto special_function entries

This corrects the DTPREL_HI16/LO16 and TPREL_HI16/LO16 howtos to use
_bfd_mips_elf_{hi,lo}16_reloc special functions, in order to support
addends outside the range [0,32767] on these relocations.

R_MIPS_GOT_HI16, R_MIPS_GOT_LO16, R_MIPS_CALL_HI16 and R_MIPS_CALL_LO16
are left alone as it seems that we (quite reasonably) only support
zero addends for those relocs.

PR 19977
bfd/
* elf32-mips.c (elf_mips_howto_table_rel): Set special_function
to _bfd_mips_elf_hi16_reloc for R_MIPS_TLS_DTPREL_HI16 and
R_MIPS_TLS_TPREL_HI16.  Set special_function to
_bfd_mips_elf_lo16_reloc for R_MIPS_TLS_DTPREL_LO16 and
R_MIPS_TLS_TPREL_LO16
(elf_mips16_howto_table_rel): Likewise for
R_MIPS16_TLS_DTPREL_HI16, R_MIPS16_TLS_DTPREL_LO16,
R_MIPS16_TLS_TPREL_HI16 and R_MIPS16_TLS_TPREL_LO16.
(elf_micromips_howto_table_rel): Likewise for
R_MICROMIPS_TLS_DTPREL_HI16, R_MICROMIPS_TLS_DTPREL_LO16,
R_MICROMIPS_TLS_TPREL_HI16 and R_MICROMIPS_TLS_TPREL_LO16.
* elf64-mips.c (mips_elf64_howto_table_rel): Similarly.
(mips16_elf64_howto_table_rel): Similarly.
(micromips_elf64_howto_table_rel): Similarly.
* elfn32-mips.c: As for elf64-mips.c.
gas/
* testsuite/gas/mips/pr19977.d,
* testsuite/gas/mips/pr19977.s: New test.
* testsuite/gas/mips/mips.exp: Run it.

2 weeks agoPR 19977: MIPS: Add missing pairing for REL PCHI/PCLO relocations
Maciej W. Rozycki [Sat, 12 Jul 2025 00:25:53 +0000 (01:25 +0100)] 
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.

2 weeks agoMIPS/BFD: Use helper function for LO relocation sign-extension
Maciej W. Rozycki [Sat, 12 Jul 2025 00:25:53 +0000 (01:25 +0100)] 
MIPS/BFD: Use helper function for LO relocation sign-extension

A calculation for LO relocations has been recently fixed with commit
ce08b3bb19b3 ("MIPS/BFD: Fix RELA handling of borrow in the generic
linker"), however it was missed that for the updated arithmetic we
already have a helper function available, `_bfd_mips_elf_sign_extend'.

Replace the open-coded statement then with an equivalent call to said
function.  No functional change.

2 weeks agoMIPS/LD/testsuite: Remove duplicate HI/LO relocation test dump files
Maciej W. Rozycki [Sat, 12 Jul 2025 00:25:53 +0000 (01:25 +0100)] 
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.

2 weeks agoAutomatic date update in version.in
GDB Administrator [Sat, 12 Jul 2025 00:00:54 +0000 (00:00 +0000)] 
Automatic date update in version.in

2 weeks agolibsframe: testsuite: fix PR libsframe/33140
Indu Bhagat [Fri, 11 Jul 2025 16:39:24 +0000 (09:39 -0700)] 
libsframe: testsuite: fix PR libsframe/33140

Commit 0d4d5a2633f missed some necessary adjustments to the testcase
after rebase.  SFrame FDE function start address data is now an offset
in PCREL encoding; reflect with a new flag SFRAME_F_FDE_START_ADDR_PCREL
in the header.

Adjust the newly added testcase.

PR libsframe/33140 SFrame test failures on x86-64

libsframe/testsuite/
* libsframe.find/plt-findfre-2.c: Adjust for the new FDE func
start addr encoding.

2 weeks agogdb: remove two unused includes of gdbcore.h
Simon Marchi [Fri, 11 Jul 2025 16:50:03 +0000 (12:50 -0400)] 
gdb: remove two unused includes of gdbcore.h

clangd claims they are unused.

Change-Id: I3c5e16279ff3b59679b8262a9d24a6e515a718f5

2 weeks agogdb: fix formatting in solib.c
Simon Marchi [Fri, 11 Jul 2025 16:45:59 +0000 (12:45 -0400)] 
gdb: fix formatting in solib.c

There are many instances of `_ (...)` that should be `_(...)`, fix them.

Change-Id: I9715019c9b62b72208b4849f3cfd531964480dd2

2 weeks agogdb/solib-svr4: use program space from solib in find_debug_base_for_solib
Simon Marchi [Wed, 9 Jul 2025 14:18:46 +0000 (10:18 -0400)] 
gdb/solib-svr4: use program space from solib in find_debug_base_for_solib

Instead of using the current global program space, I think it makes
sense to fetch the program space from the solib.  The comment for
solib::objfile indicates that it may be nullptr (which is true), but in
this case, the callers (all in
svr4_iterate_over_objfiles_in_search_order) find the solib from an
objfile, so we know that solib::objfile (the link in the opposite
direction) is set for these solibs at this point.

Change-Id: I75037d0b2c39ab1b3a3792432be134e200438efe
Approved-by: Kevin Buettner <kevinb@redhat.com>
2 weeks agogdb/record: Add support for more vmov-style instructions
Guinevere Larsen [Tue, 17 Jun 2025 12:35:03 +0000 (09:35 -0300)] 
gdb/record: Add support for more vmov-style instructions

This commit adds support for a few more vmov instructions:
* VMOV[LH|HL]PS
* VMOVLPD
* VMOVHP[S|D]
* VMOVDDUP

And associated tests. The testsuite had some minor re-working, adding a
function to zero buffers, to make later tests less fragile.

2 weeks agogdb/record: add support for AVX conversion instructions.
Guinevere Larsen [Fri, 13 Jun 2025 17:39:50 +0000 (14:39 -0300)] 
gdb/record: add support for AVX conversion instructions.

WIP

This commit adds support for instructions to convert from one type to
another, which are in the form:
* VCVTDQ2[PS|PD]
* VCVTPS2[DQ|PD]
* VCVTPD2[PS|DQ]
* VCVTSD2[SI|SS]
* VCVTSI2[SS|SD]
* VCVTSS2[SD|SI]
* VCVTTP[S|D]2DQ
* VCVTTS[S|D]2SI

It also adds support to vpsadbw, since it was trivial and only one
instruction. Finally, I have slightly reorder the case statements to
keep them in numerical order.

2 weeks agogdb/record: add support for 'pack' AVX instructions
Guinevere Larsen [Fri, 13 Jun 2025 16:47:11 +0000 (13:47 -0300)] 
gdb/record: add support for 'pack' AVX instructions

This commit adds support for the following instructions VPACK[S|U]S[WB|DW] and associated tests.

2 weeks agogdb/record: add support for comis instructions
Guinevere Larsen [Fri, 13 Jun 2025 13:09:19 +0000 (10:09 -0300)] 
gdb/record: add support for comis instructions

This commit adds support for the following instructions:
* VCOMIS[S|D]
* VUCOMIS[S|D]

And associanted tests.

2 weeks agogdb/record: add support for AVX blend instructions
Guinevere Larsen [Thu, 12 Jun 2025 19:55:28 +0000 (16:55 -0300)] 
gdb/record: add support for AVX blend instructions

This commit supports for the following instructions:
* VBLENDP[S|D]
* VBLENDVP[S|D]
* VPBLEND[D|W|VB]

and test them.

2 weeks agogdb/record: add support to vinsert and vextract instructions
Guinevere Larsen [Tue, 10 Jun 2025 14:28:25 +0000 (11:28 -0300)] 
gdb/record: add support to vinsert and vextract instructions

This patch adds support for the following instructions:
* VEXTRACT[F128|I128|PS]
* VINSERT[F128|I128|PS]
* VPEXTR[B|W|D|Q]

And associated test. For some reason, it seems that the extract
instructions deal with the output register as though it was the first
source register, so they use ModRM.r/m and VEX.B, instead of the usual
ModRM.reg and VEX.R. This meant that the opcode collision with
vbroadcastsd wasn't trivial. It can be easily solved by checking the
VEX.map_select field, so soslving it was very easy.

The VPEXTR instructions had several complicated collisions, and notably,
vpextrw to a register works completely different to any other
instruction in the family, so the code is messy, but it should be
correct.

2 weeks agogdb/record: add support for more AVX broadcast instructions
Guinevere Larsen [Wed, 11 Jun 2025 19:09:28 +0000 (16:09 -0300)] 
gdb/record: add support for more AVX broadcast instructions

This commit adds support for 3 instructions:
* VBROADCASTSS
* VBROADCASTSD
* VBROADCASTF128

and extends the function vpbroadcast_test to include these.

2 weeks agogdb/record: add support for permutation instructions
Guinevere Larsen [Wed, 11 Jun 2025 18:20:43 +0000 (15:20 -0300)] 
gdb/record: add support for permutation instructions

This commit adds recording support for the following instructions:
* VPERM2[I|F]128
* VPERM[D|Q|PD|PS]
* VPERMILP[S|D]

And associated tests.

2 weeks agogdb/record: add support for AVX/AVX2 shuffle instructions
Guinevere Larsen [Mon, 9 Jun 2025 20:25:00 +0000 (17:25 -0300)] 
gdb/record: add support for AVX/AVX2 shuffle instructions

This commit adds support for the following instructions:
* VPSHUF[B|D|HW|LW]
* VSHUFP[S|D]

and the associated test.

2 weeks agogdb/record: Add support for AVX/AVX2 shift instructions
Guinevere Larsen [Mon, 9 Jun 2025 19:04:48 +0000 (16:04 -0300)] 
gdb/record: Add support for AVX/AVX2 shift instructions

This commit adds record-full support to the following instructions:

* VPSLL[W|D|Q|DQ]
* VPSRL[W|D|Q|DQ]
* VPSRA[W|D]

With both dynamic and constant shifts, and the associated tests.
Notably, vpsraq is not available for AVX or AVX2 instruction sets, only
AVX512. vpsradq does not seem to be available with any instruction set.

2 weeks agogdb/record: support more AVX arithmetic instructions
Guinevere Larsen [Wed, 26 Feb 2025 19:15:33 +0000 (16:15 -0300)] 
gdb/record: support more AVX arithmetic instructions

This commit adds support to the following AVX/AVX2 instructions:
* VPADD[B|W|D|Q]
* VPMUL[LW|LD|HW|HUW|UDQ]
* VXORP[S|D]
* VPAND[|N]

This required some reworking on the loop that processes instruction
prefixes, because the opcode for VPMULLD overlapped with a valid
instruction prefix. To fix that, rather than using "goto out_prefixes",
this commit changes the infinite loop to only run while we don't find
another VEX prefix. That should be OK, as the intel manual (page 526 on
the March 2024 edition) says that the VEX prefix is always the last one.

2 weeks agoaarch64: Support for FEAT_SVE_AES2
Ezra Sitorus [Thu, 15 May 2025 11:33:39 +0000 (12:33 +0100)] 
aarch64: Support for FEAT_SVE_AES2

FEAT_SVE_AES2 implements the SVE multi-vector Advanced Encryption
Standard and 128-bit destination element polynomial multiply long
instructions, when the PE is not in Streaming SVE mode.

2 weeks agoaarch64: Support for FEAT_LSUI
Ezra Sitorus [Wed, 9 Jul 2025 15:41:54 +0000 (16:41 +0100)] 
aarch64: Support for FEAT_LSUI

FEAT_LSUI introduces unprivileged variants of load and store instructions so
that clearing PSTATE.PAN is never required in privileged software.

2 weeks agoaarch64: Support for FEAT_PCDPHINT
Ezra Sitorus [Mon, 7 Jul 2025 14:10:00 +0000 (15:10 +0100)] 
aarch64: Support for FEAT_PCDPHINT

FEAT_PCDPHINT - Producer-consumer data placement hints - is an optional
ISA extension that provides hint instructions to indicate:
- a store in the current execution thread is generating data at a specific
location, which a thread of execution on one or more other observers is
waiting on.
- the thread of execution on the current PE will read a location that may not
yet have been written with the value to be consumed.

This extension introduces:
- STSHH, a hint instruction, with operands (policies) keep and strm
- PRFM *IR*, a new prefetch memory operand.

2 weeks agos390: Announce s390 64-bit (s390x) SFrame V2 support in binutils
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
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>
2 weeks agos390: sframe: Test handling of .cfi_def_cfa_register
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
s390: sframe: Test handling of .cfi_def_cfa_register

Port x86-64 test for handling of .cfi_def_cfa_register from commit
3602da6fa285 ("gas: sframe: fix handling of .cfi_def_cfa_register")
to s390x.

gas/testsuite/
PR gas/32879
* gas/cfi-sframe/cfi-sframe.exp: Add new test for handling of
.cfi_def_cfa_register on s390x.
* gas/cfi-sframe/cfi-sframe-s390x-3.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-3.s: Likewise.

Bug: https://sourceware.org/PR32879
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agos390: Store SFrame CFA offset adjusted and scaled down
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
s390: Store SFrame CFA offset adjusted and scaled down

In SFrame V2 the size of the offsets following an SFrame FRE can be
either signed 8-bit, 16-bit, or 32-bit integer, with the largest offset
determining their size:
  1. CFA offset from CFA base register
  2. RA (stack save slot) offset from CFA, usually -48 on s390x if saved
  3. FP (stack save slot) offset from CFA, usually -72 on s390x if saved
The FP and RA offsets from CFA, when FP/RA saved on the stack, usually
have fixed values that fit into signed 8-bit SFrame offsets.  Likewise
the DWARF register numbers on s390x of general registers (GR; 0-15) and
floating-point registers (FPR; 16-31), when FP/RA saved in registers.
With that the CFA offset from CFA base register has the greatest impact
on the signed SFrame offset size.

The s390x ELF ABI defines the stack pointer (SP) to be 8-byte aligned
[1] and the CFA as SP at call site + 160 [2].  The CFA offset from CFA
base register is therefore always a multiple of 8.

On s390x store the SFrame CFA offset from CFA base register scaled down
by the s390x-specific CFA alignment factor of 8, in addition to the
adjustment by the s390x-specific CFA adjustment of -160, to further
improve the use of signed 8-bit SFrame offsets.  This is similar to the
DWARF data alignment factor getting factored out from certain offsets
stored in DWARF CFI.

[1]: s390x ELF ABI, sections "Register Roles" and "Stack Frame
     Allocation", https://github.com/IBM/s390x-abi/releases
[2]: s390x ELF ABI, commit 4e38ad9c8a88 ("Document the CFA"),
     https://github.com/IBM/s390x-abi/commit/4e38ad9c8a88

include/
* sframe.h (SFRAME_S390X_CFA_OFFSET_ALIGNMENT_FACTOR): Define
s390x-specific CFA offset alignment factor.
(SFRAME_V2_S390X_CFA_OFFSET_ENCODE,
SFRAME_V2_S390X_CFA_OFFSET_DECODE): Scale down/up by
SFRAME_S390X_CFA_OFFSET_ALIGNMENT_FACTOR.

libsframe/
* doc/sframe-spec.texi (s390x,
SFRAME_S390X_CFA_OFFSET_ALIGNMENT_FACTOR): Document s390x-
specific CFA offset alignment factor.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agos390: Store SFrame CFA offset adjusted
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
s390: Store SFrame CFA offset adjusted

In SFrame V2 the size of the offsets following an SFrame FRE can be
either signed 8-bit, 16-bit, or 32-bit integer, with the largest offset
determining their size:
  1. CFA offset from CFA base register
  2. RA (stack save slot) offset from CFA, usually -48 on s390x if saved
  3. FP (stack save slot) offset from CFA, usually -72 on s390x if saved
The FP and RA offsets from CFA, when FP/RA saved on the stack, usually
have fixed values that fit into signed 8-bit SFrame offsets.  Likewise
the DWARF register numbers on s390x of general registers (GR; 0-15) and
floating-point registers (FPR; 16-31), when FP/RA saved in registers.
With that the CFA offset from CFA base register has the greatest impact
on the signed SFrame offset size.

The s390x ELF ABI [1] defines the CFA as stack pointer (SP) at call
site +160. [2]  Therefore the minimum CFA offset from CFA base register
on s390x is 160.  This does not fit into a signed 8-bit integer and
therefore effectively prevents any use of signed 8-bit SFrame offsets
on s390x.

For s390x store the CFA offset from CFA base register adjusted by -160
to enable the use of signed 8-bit SFrame offsets.

[1]: s390x ELF ABI, https://github.com/IBM/s390x-abi/releases
[2]: s390x ELF ABI, commit 4e38ad9c8a88 ("Document the CFA"),
     https://github.com/IBM/s390x-abi/commit/4e38ad9c8a88

include/
* sframe.h (SFRAME_S390X_CFA_OFFSET_ADJUSTMENT): Define
s390x-specific CFA offset adjustment.
(SFRAME_V2_S390X_CFA_OFFSET_ENCODE,
SFRAME_V2_S390X_CFA_OFFSET_DECODE): New s390x-specific
macros.  Use SFRAME_S390X_CFA_OFFSET_ADJUSTMENT to en-/decode
CFA offset.

bfd/
* elf64-s390.c (elf_s390x_sframe_plt_fre): Use
SFRAME_V2_S390X_CFA_OFFSET_ENCODE on CFA offset to store it
adjusted and switch to 8-bit offsets.

gas/
* gen-sframe.c (sframe_fre_set_cfa_offset): For s390x use
SFRAME_V2_S390X_CFA_OFFSET_ENCODE on CFA offset to store it
adjusted.
(sframe_fre_get_cfa_offset): New helper.  For s390x use
SFRAME_V2_S390X_CFA_OFFSET_DECODE on CFA offset to undo its
adjustment.
(sframe_xlate_do_def_cfa_register): Use new helper
sframe_fre_get_cfa_offset.

libsframe/
* sframe.c (sframe_fre_get_cfa_offset): For s390x use
SFRAME_V2_S390X_CFA_OFFSET_DECODE on CFA offset to undo its
adjustment.
* doc/sframe-spec.texi (s390x,
SFRAME_S390X_CFA_OFFSET_ADJUSTMENT,
SFRAME_V2_S390X_CFA_OFFSET_ENCODE,
SFRAME_V2_S390X_CFA_OFFSET_DECODE): Document s390x-specific
adjustment of CFA offset.

libsframe/testsuite/
* libsframe.find/plt-findfre-2.c (add_plt0_fde, add_pltn_fde):
Use SFRAME_V2_S390X_CFA_OFFSET_ENCODE to enable use of 1-byte
SFrame offsets.

Suggested-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agolibsframe: Add test for PLT0 and PLTN with only one FRE each
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
libsframe: Add test for PLT0 and PLTN with only one FRE each

On s390x the PLT0 and PLTN entries are described with one SFrame FRE
each.  Add a test case for this particularity.

libsframe/testsuite/
* libsframe.find/find.exp (plt-findfre-2): Add new test.
* libsframe.find/plt-findfre-2.c: New test for PLT0 and PLTN
with only one FRE each.
* libsframe.find/local.mk (plt-findfre-2): Add new test.

libsframe/
* Makefile.in: Regenerate.

2 weeks agos390: Add SFrame stack trace information for .plt section
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
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>
2 weeks agos390: Represent FP without RA saved in SFrame
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
s390: Represent FP without RA saved in SFrame

If an architecture uses both SFrame RA and FP tracking SFrame assumes
that the RA offset is the 2nd offset and the FP offset is the 3rd offset
following a SFrame FRE.  An architecture does not necessarily need to
save both on the stack (or in register) at the same time or even at all.
SFrame cannot represent FP without RA saved on stack (or in a register),
since it cannot distinguish whether the 2nd offset is the RA or FP
offset.

For s390x use an invalid SFrame RA offset from CFA value of zero as
padding to represent the FP being saved when the RA is not saved.  This
aligns with the existing invalid SFrame fixed RA offset from CFA value
of zero.  In a stack tracer this then also naturally falls into place,
as it can skip restoring the RA in the topmost frame, if both the fixed
RA offset (from SFrame header) and the RA offset (from FDE) are zero,
without any need to test architecture-specific flags.

include/
* sframe.h (SFRAME_FRE_RA_OFFSET_INVALID): New define.  Used as
padding offset.
* sframe-api.h (sframe_fre_get_ra_offset): Add comment that for
s390x an offset value of SFRAME_FRE_RA_OFFSET_INVALID indicates
that the RA is not saved.

gas/
* gen-sframe.c (get_fre_num_offsets): For s390x account padding
RA offset, if FP without RA saved.
(sframe_get_fre_offset_size): Likewise.
(output_sframe_row_entry): For s390x write a padding RA offset,
if FP without RA needs to be represented.
(sframe_do_fde): Enable FP without RA saved to be represented
on s390x.

libsframe/
* sframe.c (sframe_fre_get_ra_offset): Add comment that for
s390x an offset value of SFRAME_FRE_RA_OFFSET_INVALID indicates
that the RA is not saved.
* sframe-dump.c (dump_sframe_func_with_fres): Treat invalid
RA offsets as if they were undefined.  Display them as "U"
to distinguish them.
* doc/sframe-spec.texi (s390x): Document s390x-specific use of
SFRAME_FRE_RA_OFFSET_INVALID to represent FP without RA saved.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: Rename s390x-specific tests.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-err-1.s: Rename
to ...
* cfi-sframe/cfi-sframe-s390x-fpra-offset-err-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-2.s: This.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-offset-2.d: Likewise.
Update test verification pattern accordingly.
* cfi-sframe/cfi-sframe-s390x-fpra-register-err-1.s: Rename
to ...
* cfi-sframe/cfi-sframe-s390x-fpra-register-err-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-2.s: This.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-2.d: Likewise.
Update test verification pattern accordingly.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agos390: Represent FP/RA saved in register in SFrame
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
s390: Represent FP/RA saved in register in SFrame

GCC on s390x, when in a leaf function, can be observed to save the
frame pointer (FP) and/or return address (RA) register in a floating-
point registers (FPR) instead of on the stack.  This is declared using
the following CFI directive:

  .cfi_register <fp/ra-regnum>, <fpr-regnum>

SFrame cannot represent the FP and/or RA being saved in another
register.  It does only track the CFA base register (SP/FP), CFA offset
from CFA base register, and FP and RA save area offsets from CFA.

On s390x the FP and/or RA are only saved in another FPR when in a leaf
function.  That is a function that does not call any other function.
Therefore it can ever only be the topmost function in a call chain.
An unwinder by default has access to all registers of the function that
is the topmost on the call stack.  Therefore no further information
is required to restore FP/RA from the FPR.

Represent FP/RA saved in another register on s390x, by encoding the
DWARF register number shifted by one to the left with the least-
significant bit set in the offset as follows:

  offset = (regnum << 1) | 1

The use of the least-significant bit of the offset as indication is
possible, as the stack pointer (SP), the CFA, and any register save
area slots are 8-byte aligned according to the s390x ELF ABI:
- The stack pointer (SP) "shall maintain an 8-byte alignment". [1]
- The CFA is defined as SP at call site +160. [2]
- Pointers and 8-byte integers, such as general register values, must
  be 8-byte aligned. [3]
SFrame FP and RA stack offsets must therefore always be a multiple of
8 on s390x.  Note that for the same reason the DWARF data alignment
factor is -8 on s390x (see DWARF2_CIE_DATA_ALIGNMENT).

Add s390x-specific SFrame (error) tests for FP/RA saved in FPRs in leaf
function.

[1]: s390x ELF ABI, sections "Register Roles" and "Stack Frame
     Allocation", https://github.com/IBM/s390x-abi/releases
[2]: s390x ELF ABI, commit 4e38ad9c8a88 ("Document the CFA"),
     https://github.com/IBM/s390x-abi/commit/4e38ad9c8a88
[3]: s390x ELF ABI, section "Fundamental Types", table "Scalar types",
     https://github.com/IBM/s390x-abi/releases

include/
* sframe.h (SFRAME_V2_S390X_OFFSET_IS_REGNUM): New s390x-
specific macro to test whether an SFrame FP/RA offset is a DWARF
register number.
(SFRAME_V2_S390X_OFFSET_ENCODE_REGNUM): New s390x-specific macro
to encode a DWARF register number into an SFrame FP/RA offset.
(SFRAME_V2_S390X_OFFSET_DECODE_REGNUM): New s390x-specific macro
to decode an SFrame FP/RA offset into a DWARF register number.
* sframe-api.h (sframe_fre_get_fp_offset,
sframe_fre_get_fp_offset): Add comment that for s390x the offset
may be an encoded register number.

gas/
* gen-sframe.c (s390_sframe_xlate_do_register): New S390-
specific function.  Uses SFRAME_V2_S390X_OFFSET_ENCODE_REGNUM to
represent FP/RA saved in another register on s390x.
(sframe_xlate_do_register): Invoke s390_sframe_xlate_do_register
on s390x.

libsframe/
* sframe.c (sframe_fre_get_fp_offset, sframe_fre_get_fp_offset):
Add comment that for s390x the offset may be an encoded register
number.
* sframe-dump.c (is_sframe_abi_arch_s390x): New helper to test
whether ABI/arch is s390x.
(dump_sframe_func_with_fres): Use
SFRAME_V2_S390X_OFFSET_IS_REGNUM and
SFRAME_V2_S390X_OFFSET_DECODE_REGNUM to dump FP/RA saved in
another register on s390x.
* doc/sframe-spec.texi (s390x): Document s390x-specific
representation of FP/RA saved in another register.

gas/testsuite/
* gas/cfi-sframe/cfi-sframe.exp: Update s390x-specific SFrame
(error) tests.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-2.s: Rename
to ...
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-2.d:
Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-1.s: This.  Test
no longer triggers a warning, as SFrame can represent FP and RA
saved in registers.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-1.d: Likewise.
* gas/cfi-sframe/cfi-sframe-s390x-fpra-register-err-1.d: Test
now triggers a different warning, as SFrame can represent FP and
RA saved in registers, but not FP without RA saved in register.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agos390: Initial support to generate .sframe from CFI directives in assembler
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
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
b52c4ee46657 ("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>
2 weeks agos390: Explicitly list linker dump tests
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
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>
2 weeks agosframe: Ignore section padding when converting endianness
Jens Remus [Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)] 
sframe: Ignore section padding when converting endianness

The .sframe section may have a trailing padding due to the architecture-
specific default section alignment.  Do not treat this padding as error
when converting between target and host endianness.

This can be observed when building Binutils with SFrame s390x support on
x86-64 for s390x using configure option "--target=s390x-ibm-linux-gnu"
and running the GAS test suite.

While at it reuse the determined SFrame section header size.

libsframe/
* sframe.c (flip_sframe): Ignore .sframe section padding.  Reuse
SFrame header size.

Reported-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agoAutomatic date update in version.in
GDB Administrator [Fri, 11 Jul 2025 00:01:22 +0000 (00:01 +0000)] 
Automatic date update in version.in

2 weeks agoAM_PO_SUBDIRS
Alan Modra [Thu, 10 Jul 2025 21:25:43 +0000 (06:55 +0930)] 
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.

2 weeks agogas v850 md_convert_frag
Alan Modra [Thu, 10 Jul 2025 01:45:16 +0000 (11:15 +0930)] 
gas v850 md_convert_frag

The v850 md_convert_frag function oddly calls subseg_change twice
(commit 1cd986c58543).  Neither call is needed, because that is done
in size_seg.

Convert the fr_opcode fixup field back (to an opindex, not fx_r_type)
using a cast rather than a union, since we used casts when setting up
those values.  I guess the union was added to silence compiler
warnings about wrong-size casts, but unfortunately results in the
wrong value being retrieved on big-endian hosts.

Change "buffer" to a char* as there is no need to make it an
unsigned char*, and that way requires fewer casts.  Finally, fix
formatting and use uintptr_t when make the rs_machine_dependent frags.

Remove subseg_change calls from cr16, crx, mn10200, mn10300, and sh
md_convert_frag too.

2 weeks agounion alpha_macro_arg
Alan Modra [Wed, 9 Jul 2025 08:45:10 +0000 (18:15 +0930)] 
union alpha_macro_arg

Rename the old enum alpha_macro_arg to alpha_macro_argset, and create
a union alpha_macro_arg to use in all the alpha_macro.emit functions.
This avoids intptr_t casts on retrieving index values and void* casts
on storing them in the alpha_macros array.

2 weeks agosim: riscv: Fix build issue due to INSN_CLASS_C was changed to INSN_CLASS_ZCA
Nelson Chu [Thu, 10 Jul 2025 13:50:19 +0000 (21:50 +0800)] 
sim: riscv: Fix build issue due to INSN_CLASS_C was changed to INSN_CLASS_ZCA

2 weeks agolibiberty: sync with gcc
Matthieu Longo [Mon, 10 Feb 2025 11:24:57 +0000 (11:24 +0000)] 
libiberty: sync with gcc

Import the following commits from GCC as of r16-2170-g2f2e9bcfb0fd9c:
0fd98b6f9f2 libiberty: add routines to handle type-sensitive doubly linked lists

2 weeks agoRISC-V: Fixed wrong imply result for zce when -march=rv32id_zce
Nelson Chu [Wed, 9 Jul 2025 04:53:41 +0000 (12:53 +0800)] 
RISC-V: Fixed wrong imply result for zce when -march=rv32id_zce

The entry of "zce imply zcf" needs check_implicit_for_zcf, so it needs to be
placed after the entries of "whatever imply f".  Otherwise the implicit zcf
may be missed.  Also merge the march-implu-zce* testcases into imply testcases.

2 weeks agoRISC-V: Clarify the imply rule of c
Nelson Chu [Wed, 9 Jul 2025 04:53:40 +0000 (12:53 +0800)] 
RISC-V: Clarify the imply rule of c

This also fix the imply result for .option rvc.

Imply zcf when c and f and rv32
Imply zcd when c and d
Imply zca when c

Changed INSN_CLASS_C to INSN_CLASS_ZCA
Changed INSN_CLASS_F_AND_C to INSN_CLASS_ZCF
Changed INSN_CLASS_D_AND_C to INSN_CLASS_ZCD
Changed INSN_CLASS_ZIHINTNTL_AND_C to INSN_CLASS_ZIHINTNTL_AND_ZCA

2 weeks agoRISC-V: Deprecate ".option arch, -ext" for users due to its controversial use
Nelson Chu [Wed, 9 Jul 2025 02:47:02 +0000 (10:47 +0800)] 
RISC-V: Deprecate ".option arch, -ext" for users due to its controversial use

Before we figure out the whole remove situations for ".option arch, -ext", and
have any RISC-V public spec defines it, we should just deprecate it.

2 weeks agoAutomatic date update in version.in
GDB Administrator [Thu, 10 Jul 2025 00:01:08 +0000 (00:01 +0000)] 
Automatic date update in version.in

2 weeks agogas: ld: sframe: add new internal header
Indu Bhagat [Tue, 8 Jul 2025 19:10:04 +0000 (12:10 -0700)] 
gas: ld: sframe: add new internal header

for SFRAME_V2_GNU_AS_LD_ENCODING_FLAGS.

The intention of creating an abstraction like
SFRAME_V2_GNU_AS_LD_ENCODING_FLAGS is to address the concern that there
should be a central place to enforce harmonious flags between GNU as and
ld.  At the moment, the only flag that needs to be enforced is
SFRAME_F_FDE_FUNC_START_PCREL.

sframe.h and sframe-api.h are installed headers by libsframe for the
specification and implementation respectively.  Adding a definition like
SFRAME_V2_GNU_AS_LD_ENCODING_FLAGS does not fit in either.  Create a
new internal header instead to keep the definition uncoupled from
sframe.h and sframe-api.h.  Rename the previously added
SFRAME_F_LD_MUSTHAVE_FLAGS to define the new
SFRAME_V2_GNU_AS_LD_ENCODING_FLAGS.

bfd/
* elf-sframe.c (_bfd_elf_merge_section_sframe): Use the new
internal header and SFRAME_V2_GNU_AS_LD_ENCODING_FLAGS.
gas/
* gen-sframe.c (output_sframe_internal): Likewise.
include/
* sframe-api.h (SFRAME_F_LD_MUSTHAVE_FLAGS): Move from..
* sframe-internal.h: ..to here.  New file.

2 weeks agoMerge init_private_section_data with copy_private_section_data
Alan Modra [Tue, 8 Jul 2025 23:44:06 +0000 (09:14 +0930)] 
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.

2 weeks agogas remove assorted unnecessary casts
Alan Modra [Tue, 8 Jul 2025 23:43:51 +0000 (09:13 +0930)] 
gas remove assorted unnecessary casts

This continues the saga of removing unnecessary casts, and making
small code tidies in gas.  Hopefully this sees the last of K&R
anachronisms.

2 weeks agogas standardise md_section_align
Alan Modra [Tue, 8 Jul 2025 23:43:14 +0000 (09:13 +0930)] 
gas standardise md_section_align

The point here is that when valueT is 64 bits and int is 32 bits,
1 << align doesn't work for shifts larger than the size of int.  (Not
that anyone is likely to use such large alignments in real code.)

2 weeks agogas function arg casts
Alan Modra [Tue, 8 Jul 2025 23:42:53 +0000 (09:12 +0930)] 
gas function arg casts

This patch removes more unnecessary arg casts in various function
calls.

2 weeks agogas fixups
Alan Modra [Tue, 8 Jul 2025 23:42:45 +0000 (09:12 +0930)] 
gas fixups

Remove unnecessary arg casts in fix_new and similar calls.

2 weeks agogas char/unsigned char casts
Alan Modra [Tue, 8 Jul 2025 23:42:20 +0000 (09:12 +0930)] 
gas char/unsigned char casts

This patch removes many unneeded casts to char or unsigned char.  It's
worth noting that safe-ctype.h macros ISDIGIT and the like cope with
either signed or unsigned char.
In some cases a cast to unsigned char is replaced by anding with 0xff,
which accomplishes the same thing but doesn't rely on char being eight
bits.  The patch also removes pointer casts, and a few unsigned char
pointer variables.

2 weeks agogas alpha sign extension macros
Alan Modra [Tue, 8 Jul 2025 23:39:23 +0000 (09:09 +0930)] 
gas alpha sign extension macros

Use standard sign extend and range checking using unsigned
expressions that don't rely on implementation defined right shifts or
size of short and int.

2 weeks agogas md_number_to_chars
Alan Modra [Tue, 8 Jul 2025 23:35:12 +0000 (09:05 +0930)] 
gas md_number_to_chars

Calls to md_number_to_chars don't need to cast their value arg (*).
Remove those casts.  avr_output_property_recode made a call to
md_number_to_chars with size of 1.  Simplify that.  tc-bpf.c
md_convert_frag used write_insn_bytes that simply copied input to
output.  Dispense with that nonsense, and similarly in a couple of
other places where md_number_to_chars was called with size 1.

*) unless the value arg is an expression that needs a cast, eg. tic54x
   emit_insn where the shift left could trigger signed overflow UB
   without a cast.

2 weeks agoz8k opcode_entry_type
Alan Modra [Tue, 8 Jul 2025 23:34:47 +0000 (09:04 +0930)] 
z8k opcode_entry_type

z8k opcode_entry_type.func is never used as a function pointer, only
as a pointer to a pseudo_typeS.  Change it to a void*.

2 weeks agogas various other void* casts
Alan Modra [Tue, 8 Jul 2025 23:33:45 +0000 (09:03 +0930)] 
gas various other void* casts

This removes assorted unneeded casts of void* pointers, and casts when
passing args to void* parameters or storing to void* pointers.  The
patch also changes obj-coff.c stack_push to take a void* parameter,
and replaces an odd memcpy in tc-metag.c find_insn_templates with a
simple assignment.

2 weeks agogas various other const pointer changes
Alan Modra [Tue, 8 Jul 2025 23:33:08 +0000 (09:03 +0930)] 
gas various other const pointer changes

This removes a bunch of casts involving const pointers, in some cases
by making variables const pointers so a cast is not needed.  In a
couple of places the cast hid errors with "&array" written rather than
"array", see iq2000_macro_defs and s_pru_align.  tc-xgate.c cmp_opcode
is changed to be the standard qsort predicate to avoid a function
cast.

2 weeks agogas d30v_insn plus other non-const pointers
Alan Modra [Tue, 8 Jul 2025 23:32:43 +0000 (09:02 +0930)] 
gas d30v_insn plus other non-const pointers

d30v has a bunch of casts that are only needed due to various types
missing a const.  Fix that.

2 weeks agogas alloc casts
Alan Modra [Tue, 8 Jul 2025 23:32:28 +0000 (09:02 +0930)] 
gas alloc casts

All of the various memory allocation function return a "void *"
pointer, which needs no cast to assign to other pointer types.

2 weeks agogas bfd_put and bfd_get arg casts
Alan Modra [Tue, 8 Jul 2025 23:32:05 +0000 (09:02 +0930)] 
gas bfd_put and bfd_get arg casts

bfd_{h_,}put_* and bfd_{h_,}get_* have "void *" pointer params
nowadays.  We don't need casts on their pointer args.  We also don't
need to cast values passed to bfd_put.

2 weeks agogas NULL casts
Alan Modra [Tue, 8 Jul 2025 23:29:10 +0000 (08:59 +0930)] 
gas NULL casts

This removes many unnecessary NULL casts.  I'm also adding a few arg
casts in concat calls, to make the code consistent.  Advice from quite
a few years ago was that it's better to use the exact type for args
corresponding to function ellipses, in case NULL is defined as plain
0.  (I think that happened with some early 64-bit systems.  Plain NULL
ought to be OK nowadays.)

2 weeks agogas s3_FAIL and s7_FAIL
Alan Modra [Tue, 8 Jul 2025 23:28:52 +0000 (08:58 +0930)] 
gas s3_FAIL and s7_FAIL

s3_FAIL is defined as 0x80000000 which is unsigned, but everywhere it
is used it is cast to int.  Get rid of that silliness, and likewise
for s7_FAIL.

2 weeks agogas more enum casts
Alan Modra [Tue, 8 Jul 2025 23:28:31 +0000 (08:58 +0930)] 
gas more enum casts

Remove more unnecessary enum casts.

2 weeks agogas bfd_reloc_code_real_type
Alan Modra [Tue, 8 Jul 2025 23:28:11 +0000 (08:58 +0930)] 
gas bfd_reloc_code_real_type

Enumeration constants are integer types, so there should be no need to
cast such constants to int in expressions.  (Perhaps some older gccs
warned, I checked back to gcc-4.5.)  Remove some of those unnecessary
casts.  Also remove unnecessary casts to bfd_reloc_code_real_type.

2 weeks agogas add_ecoff_symbol
Alan Modra [Tue, 8 Jul 2025 23:27:49 +0000 (08:57 +0930)] 
gas add_ecoff_symbol

* ecoff.c: Remove unnecessary arg casts in add_ecoff_symbol
calls throughout file.

2 weeks agogas frag_var
Alan Modra [Tue, 8 Jul 2025 23:24:56 +0000 (08:54 +0930)] 
gas frag_var

Many frag_var calls have unnecessary casts on arguments, no doubt from
the days when binutils was written for K&R C.  (ie. functions were not
prototyped so you needed to cast anything that didn't match the
expected type after default promotions, as you still do for args
matching a function ellipsis.)  Remove those casts.

* config/tc-alpha.c (s_alpha_comm): Use offset_T for cur_size
to avoid need for casts.  Remove casts from frag_var args.
* config/tc-ia64.c (obj_elf_vms_common): Remove casts from
frag_var args.
* config/tc-m32r.c (m32r_scomm): Likewise.
* config/tc-m68hc11.c (build_jump_insn): Likewise.
(build_dbranch_insn): Likewise.
* config/tc-m68k.c (md_assemble): Likewise.
* config/tc-microblaze.c (microblaze_s_lcomm): Likewise.
* config/tc-mmix.c (s_loc): Likewise.
* config/tc-ppc.c (ppc_elf_lcomm, ppc_comm): Likewise.
* config/tc-score.c (s3_s_score_lcomm): Likewise.
* config/tc-score7.c (s7_s_score_lcomm): Likewise.
* config/tc-sh.c (sh_cons_align): Likewise.
* config/tc-sparc.c (s_reserve, s_common): Likewise.
(sparc_cons_align): Likewise.
* config/tc-tic4x.c (tic4x_seg_alloc, tic4x_bss): Likewise.
* config/tc-tic54x.c (tic54x_bss, tic54x_space): Likewise.
(tic54x_usect, tic54x_field): Likewise.
* config/tc-tic6x.c (s_tic6x_scomm): Likewise.
* config/tc-v850.c (v850_offset, v850_comm): Likewise.
* frags.c (frag_align, frag_align_pattern, frag_align_code): Likewise.
* gen-sframe.c (output_sframe_row_entry): Likewise.
(output_sframe_funcdesc): Likewise.
* read.c (s_fill, do_org, s_space, emit_leb128_expr): Likewise.
* symbols.c (colon)): Likewise.

2 weeks agogas pointer to int and vice versa
Alan Modra [Tue, 8 Jul 2025 23:24:24 +0000 (08:54 +0930)] 
gas pointer to int and vice versa

Use "intptr_t" or "uintptr_t" for these conversions, not "long" which
is wrong on LLP64 systems, or "size_t" which is better but still not
the correct type.

* config/tc-alpha.c (emit_ldXu, emit_ldX, emit_uldXu, emit_uldX),
(emit_stX, emit_ustX, emit_sextX): Use correct type when
converting vlgsize pointer to in.  Use "int" rather than
"long" for result.
* config/tc-ia64.c (generate_unwind_image): Use intptr_t cast
when passing personality_routine to frag_var.
* config/tc-ppc.c (ppc_frob_symbol <coff>): Use uintptr_t cast
when converting symbol pointer to valueT.
* config/tc-v850.c (md_assemble): Use intptr_t cast when
loading integer opindex.

2 weeks agoAutomatic date update in version.in
GDB Administrator [Wed, 9 Jul 2025 00:01:27 +0000 (00:01 +0000)] 
Automatic date update in version.in

2 weeks agoaarch64: Add support for FEAT_SVE2p2 and FEAT_SME2p2
Alice Carlotti [Tue, 3 Jun 2025 19:35:34 +0000 (20:35 +0100)] 
aarch64: Add support for FEAT_SVE2p2 and FEAT_SME2p2

2 weeks agoaarch64: Reorder virtual feature dependencies
Alice Carlotti [Tue, 8 Jul 2025 19:43:37 +0000 (20:43 +0100)] 
aarch64: Reorder virtual feature dependencies

This will improve readability when more combinations of "SVE* or SME*"
are added.

2 weeks agogdb/reverse: Add 2 AVX instructions VADDSUBPS and VADDSUBPD
First Last [Tue, 10 Jun 2025 13:34:50 +0000 (19:04 +0530)] 
gdb/reverse: Add 2 AVX instructions VADDSUBPS and VADDSUBPD

add support to recording 2 missing AVX instructions: vaddsubps and vaddsubpd, and add associated tests.

Approved-By: Guinevere Larsen <guinevere@redhat.com>
2 weeks agogprofng: support external debug info
Vladimir Mezentsev [Mon, 7 Jul 2025 18:56:22 +0000 (11:56 -0700)] 
gprofng: support external debug info

Use bfd_follow_gnu_debuglink() and bfd_follow_gnu_debugaltlink() to find files
with debug info.
If necessary, gprofng-archive copies these files to EXP/archives.

For each executable, gprofng creates the Elf class twice.
One of them was a memory leak.
Fixed this by adding a new argument to Stabs::Stabs().

gprofng/ChangeLog
2025-07-07  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

PR 32147
PR 30194
* src/Disasm.cc (get_funcname_in_plt): Use the executable file instead
of the debug information file.
* src/Dwarf.h: Define debug_alt_strSec.
* src/DwarfLib.cc: Add support for DW_FORM_GNU_ref_alt,
DW_FORM_GNU_strp_alt.
* src/Elf.h (find_gnu_debug_files, get_dwr_section): New functions.
* src/Elf.cc: Likewise.
* src/Experiment.cc (copy_file): Add the const qualifier.
* src/Experiment.h: Likewise.
* src/LoadObject.cc (get_elf, openDebugInfo): Find files with debug info.
* src/LoadObject.h: Remove unused variables.
* src/Module.cc: Remove an argument in openDebugInfo().
* src/Stabs.cc (Stabs::Stabs): Add the Elf* argument.
* src/Stabs.h: Likewise.
* src/gp-archive.cc: Archive files with debug info.
* src/gp-archive.h (archive_file): New function.

2 weeks agoFix wchar.exp test case per review
Tom Tromey [Tue, 8 Jul 2025 14:52:59 +0000 (08:52 -0600)] 
Fix wchar.exp test case per review

A recent patch of mine modified wchar.exp, but I failed to notice one
part of the review.  This patch updates the code to conform to the
review comments.

2 weeks agoNew Malay translation for bfd/ and new Spanish translation for gas/
Nick Clifton [Tue, 8 Jul 2025 12:27:56 +0000 (13:27 +0100)] 
New Malay translation for bfd/ and new Spanish translation for gas/

2 weeks agoRISC-V: Fix libpath_suffix selection for ldscript
Mark Goncharov [Tue, 1 Jul 2025 05:57:51 +0000 (08:57 +0300)] 
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>
2 weeks agoRISC-V: Fixed mapping symbol for .option norvc directive
Nelson Chu [Tue, 8 Jul 2025 09:07:24 +0000 (17:07 +0800)] 
RISC-V: Fixed mapping symbol for .option norvc directive

2 weeks agoRISC-V: Fixed dis-assembler to set correct xlen from mapping symbol
Nelson Chu [Fri, 4 Jul 2025 05:42:38 +0000 (13:42 +0800)] 
RISC-V: Fixed dis-assembler to set correct xlen from mapping symbol

2 weeks agoRISC-V: Fixed that .option push/pop won't recover the xlen
Nelson Chu [Fri, 4 Jul 2025 05:42:37 +0000 (13:42 +0800)] 
RISC-V: Fixed that .option push/pop won't recover the xlen

2 weeks agoRISC-V: Added testcase to show the current rvc and xlen problems
Nelson Chu [Fri, 4 Jul 2025 05:42:36 +0000 (13:42 +0800)] 
RISC-V: Added testcase to show the current rvc and xlen problems

2 weeks agoRISC-V: Bind defined symbol locally in PIE
Linsen Zhou [Mon, 7 Jul 2025 22:34:18 +0000 (06:34 +0800)] 
RISC-V: Bind defined symbol locally in PIE

Reference commit 1dcb9720d62cd053a72c31881b7724ce9f74332c

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>
2 weeks agoAutomatic date update in version.in
GDB Administrator [Tue, 8 Jul 2025 00:01:25 +0000 (00:01 +0000)] 
Automatic date update in version.in

2 weeks agogprofng: remove ElfReloc class and unused functions and declarations
Vladimir Mezentsev [Fri, 4 Jul 2025 21:49:18 +0000 (14:49 -0700)] 
gprofng: remove ElfReloc class and unused functions and declarations

class ElfReloc is not used after we started use libbfd.
Removed ElfReloc and other unused declarations.

gprofng/ChangeLog
2025-07-03  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* src/Disasm.cc: Remove unused functions and variables.
* src/Disasm.h: Likewise.
* src/Dwarf.cc: Likewise.
* src/DwarfLib.cc: Likewise.
* src/DwarfLib.h: Likewise.
* src/Elf.cc: Likewise.
* src/Elf.h: Likewise.
* src/Stabs.cc: Likewise.
* src/Stabs.h: Likewise.

2 weeks agoCorrectly handle L'\\'
Tom Tromey [Thu, 3 Jul 2025 18:35:11 +0000 (12:35 -0600)] 
Correctly handle L'\\'

Hannes filed a bug that pointed out that:

    print L'\\'

... did not work correctly.  The bug is in convert_escape, which
simply transcribes the backslash character, rather than convert it
between encodings.

This patch fixes the error.  I also turned a macro into a lambda to
clean up this code a little.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=33124
Reviewed-By: Tom de Vries <tdevries@suse.de>
Tested-By: Hannes Domani <ssbssa@yahoo.de>
2 weeks agoLoongArch: Allow to relax instructions into NOPs after handling alignment
WANG Xuerui [Sun, 6 Jul 2025 01:06:20 +0000 (09:06 +0800)] 
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>
2 weeks agoAutomatic date update in version.in
GDB Administrator [Mon, 7 Jul 2025 00:01:07 +0000 (00:01 +0000)] 
Automatic date update in version.in

2 weeks agold: bfd: sframe: Update section size also for relocatable links
Jens Remus [Sun, 6 Jul 2025 19:47:43 +0000 (12:47 -0700)] 
ld: bfd: sframe: Update section size also for relocatable links

For relocatable links the output .sframe section size may be wrong.
This can be observed when dumping the SFrame information from the x86-64
sframe-reloc-1 test:

Name              Address          Off    Size
.sframe           0000000000000000 000110 00007f

Offset            Type               Symbol's Value  Symbol's Name + Addend
000000000000001c  R_X86_64_PC32      0000000000000000 .text + 1c
0000000000000030  R_X86_64_PC32      0000000000000000 .text + 65

0x00000000 e2de0201 0300f800 02000000 08000000 ................
0x00000010 1e000000 00000000 28000000 00000000 ........(.......
0x00000020 35000000 00000000 04000000 00000000 5...............
0x00000030 00000000 25000000 0f000000 04000000 ....%...........
            offset 1st FRE---^^^^^^^^ ^^^^^^^^---number of FREs
0x00000040 00000000 00030801 0510f004 0410f034 ...............4
FDE info---^^      | begin of FDEs
0x00000050 0508f000 03080105 10f00404 10f02405 ..............$.
                 11111112222222223333333334444---FRE 1, 2, 3, 4
0x00000060 08f00000 00000000 00000000 00000000 ................
           4444^^^^...
0x00000070 00000000 00000000 00000000 000000   ...............
                                   ...^^^^^^---excessive section

When running the x86-64 test cross build on a big-endian system, such
as s390x, objdump and readelf fail to dump the SFrame information with
the following error message:

Error: SFrame decode failure: Buffer does not contain SFrame data.

This is because the following check in flip_sframe() fails, which gets
only invoked if the endianness of the SFrame data is different from the
host system one:

/* All FDEs and FREs must have been endian flipped by now.  */
if ((j != ihp->sfh_num_fres) || (bytes_flipped != (buf_size - hdrsz)))
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

With:
j=8, ihp->sfh_num_fres=8, bytes_flipped=70, buf_size=127, hdrsz=28

While at it, remove the incorrect code comment.  There is no
relationship between "do not update size" and the fact that the
"contents have not been relocated".

bfd/
* elf-sframe.c (_bfd_elf_write_section_sframe): Update section
size also for relocatable links.

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
2 weeks agoNEWS: sframe: mention new semantics for SFrame FDE function start addr
Indu Bhagat [Sun, 6 Jul 2025 19:47:31 +0000 (12:47 -0700)] 
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.

2 weeks agold: bfd: sframe: fix incorrect r_offset in RELA entries
Indu Bhagat [Sun, 6 Jul 2025 19:47:18 +0000 (12:47 -0700)] 
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.

2 weeks agobfd: gas: ld: libsframe: adopt new encoding for FDE func start addr field
Indu Bhagat [Sun, 6 Jul 2025 19:47:05 +0000 (12:47 -0700)] 
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.

2 weeks agoobjdump, readelf: sframe: apply relocations before textual dump
Indu Bhagat [Sun, 6 Jul 2025 19:46:53 +0000 (12:46 -0700)] 
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.

2 weeks agoinclude: sframe: doc: define new flag SFRAME_F_FDE_FUNC_START_PCREL
Indu Bhagat [Sun, 6 Jul 2025 19:46:43 +0000 (12:46 -0700)] 
include: sframe: doc: define new flag SFRAME_F_FDE_FUNC_START_PCREL

Add a new flag SFRAME_F_FDE_FUNC_START_PCREL to SFrame stack trace
format.  If set, this flag indicates that the function start address
field (sfde_func_start_address) is the offset to the function start
address from the SFrame FDE function start address field itself.

Such an encoding is friendlier to the exisitng PC-REL relocations
available in the ABIs supported in SFrame: AMD64 (R_X86_64_PC32) and
AArch64 (R_AARCH64_PREL32).  In subsequent patches, we will make the
implementation in gas and ld to both:
  - emit the values in the same (above-mentioned) encoding uniformly.
  - set the flag SFRAME_F_FDE_FUNC_START_PCREL in the SFrame header
    for consumers to be able to distinguish.

Define SFRAME_V2_F_ALL_FLAGS in sframe.h to help keep the implementation
less error-prone by keeping a set of all defined flags at a central
place.  Adjust the check in sframe_header_sanity_check_p () to use the
SFRAME_V2_F_ALL_FLAGS instead.

Add documentation for SFRAME_F_FDE_FUNC_START_PCREL.  Update the
documentation about the encoding of the sfde_func_start_address field.

Also, update the section "Changes from Version 1 to Version 2" to
include the specification of the new flag SFRAME_F_FDE_FUNC_START_PCREL
as an erratum to the SFrame Version 2 specification.

include/
        * sframe.h (SFRAME_F_FDE_FUNC_START_PCREL): New definition.
        (SFRAME_V2_F_ALL_FLAGS): Likewise.
libsframe/
* sframe-dump.c (dump_sframe_header_flags): Update to include
the new flag SFRAME_F_FDE_FUNC_START_PCREL.
* sframe.c (sframe_header_sanity_check_p): Use
SFRAME_V2_F_ALL_FLAGS.
libsframe/doc/
* sframe-spec.texi: Add details about the new flag.  Also update
the defails about the sfde_func_start_address encoding.

2 weeks agoinclude: libsframe: add APIs for offsetof FDE func start addr field
Indu Bhagat [Sun, 6 Jul 2025 19:46:33 +0000 (12:46 -0700)] 
include: libsframe: add APIs for offsetof FDE func start addr field

These APIs will be later used by the linker to arrange SFrame FDEs in
the output SFrame section.

include/
        * sframe-api.h (sframe_decoder_get_offsetof_fde_start_addr): New
declaration.
        (sframe_encoder_get_offsetof_fde_start_addr): Likewise.

libsframe/
        * libsframe.ver: List the new APIs.
        * sframe.c (sframe_decoder_get_offsetof_fde_start_addr): New
definition.
        (sframe_encoder_get_offsetof_fde_start_addr): Likewise.

2 weeks agolibsframe: refactor code for dumping section flags
Indu Bhagat [Sun, 6 Jul 2025 19:46:24 +0000 (12:46 -0700)] 
libsframe: refactor code for dumping section flags

To prepare code for accommodating new flag additions easily as the
format evolves.

libsframe/
        * sframe-dump.c (SFRAME_HEADER_FLAGS_STR_MAX_LEN): Remove.
        (dump_sframe_header_flags): .. to here. New definition.
        (PRINT_FLAG): New definition.
        (dump_sframe_header): Move some implementation from here ..

2 weeks agoinclude: libsframe: add APIs for SFrame header flags
Indu Bhagat [Sun, 6 Jul 2025 19:46:09 +0000 (12:46 -0700)] 
include: libsframe: add APIs for SFrame header flags

Add new APIs, one each for getting flags from the SFrame decoder and
SFrame encoder context objects respectively.

These will later be used by the linker to uniformly access the flags,
given the SFrame decoder and SFrame encoder objects.

Use the new API, where applicable, within libsframe.

include/
        * sframe-api.h (sframe_decoder_get_flags): New declaration.
        (sframe_encoder_get_flags): Likewise.
libsframe/
* libsframe.ver: List new APIs.
        * sframe.c (sframe_decoder_get_flags): New definition.
(sframe_encoder_get_flags): Likewise.
        (sframe_get_funcdesc_with_addr_internal): Use the new API.
        (sframe_encoder_get_flags): Likewise.
        (sframe_encoder_write_sframe): Likewise.

2 weeks agoMIPS/LD/testsuite: Remove empty pic-and-nonpic-1-r6.s file
Maciej W. Rozycki [Sun, 6 Jul 2025 18:22:49 +0000 (19:22 +0100)] 
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.

2 weeks agoMIPS: Correct HI/LO rela reloc howto special_function entries
Alan Modra [Sun, 6 Jul 2025 18:22:49 +0000 (19:22 +0100)] 
MIPS: Correct HI/LO rela reloc howto special_function entries

The patch corrects the mips16 and micromips rela tables to *not*
use _bfd_mips_elf_{hi,lo}16_reloc.  These special functions are
inappropriate for RELA relocs where addends are in the reloc rather
than in the section contents.  See corresponding rela R_MIPS howtos.

bfd/
* elf64-mips.c (mips16_elf64_howto_table_rela)
<R_MIPS16_HI16, R_MIPS16_LO16>: Use _bfd_mips_elf_generic_reloc
special_function.
(micromips_elf64_howto_table_rela)
<R_MICROMIPS_HI16, R_MICROMIPS_LO16>: Similarly.
* elfn32-mips.c: As for elf64-mips.c.