[PATCH] s390: Add linker tests for references in discarded sections

Jens Remus jremus@linux.ibm.com
Thu Nov 12 12:09:19 GMT 2026


Hello Andreas,

thank you for the review and feedback!

Meanwhile I realized that I should have done better research:  This
started out as porting the aarch64 relr-discard-* tests for my WIP
s390 support for DT_RELR, where the PIE test ran into the assertion.
I then ported the related RISC-V discard-* tests which confirmed the
PIE tests would also fail.  Remembering my WIP work to port the x86-64
split of check_relocs into check_relocs and scan_relocs I verified that
both fails and the superfluous NONE and GLOB_DAT relocations would go
away.  So I intended to use this patch to document the underlying issue
is unrelated to DT_RELR and would get resolved by the check_relocs
split.

I now looked into the RISC-V commit that introduced the tests (which I
should have done first) that fixes the issue that triggers the
assertion (not the superfluous NONE and GLOB_DAT relocations) and also
found the likewise x86-64 commit.

The tests from this patch are now part of my new patch that ports the
x86-64 fix, that I just sent for review:

[PATCH] s390: Do not force symbol dynamic unless it is undefined weak
https://inbox.sourceware.org/binutils/20261112115654.1527835-2-jremus@linux.ibm.com/

Regards,
Jens

On 11/5/2026 12:48 PM, Andreas Krebbel wrote:
> Hi Jens,
> 
> this ok, thanks!
> 
> Just two minor nits. Feel free to ignore:
> 
> - discard-pie.d doesn't seem to include the expected output. So it would not turn into an XPASS automatically in case the problem goes away, right?
> - Should we, in discard-shared.d, document that the outcome is not what we want but rather what it is today?
> 
> Andreas
> 
> 
> On 10/2/26 4:52 PM, Jens Remus wrote:
> 
>> Add test cases verifying the behavior when linking with references to
>> symbols in discarded sections.
>>
>> Linking as PIE with a discarded section that contains a GOT reference
>> triggers a BFD assertion ((h->got.offset & 1) != 0) because the GOT
>> entry is allocated but never initialized.  Mark the PIE test as XFAIL.
>> The PDE test passes because no dynamic relocations are needed.  The
>> shared library test passes but documents the spurious R_390_NONE
>> relocations emitted for GOT and data references in discarded sections.
>>
>> Inspired by aarch64 relr-discard-* and riscv discard-* tests.
>>
>> ld/testsuite/
>>     * ld-s390/s390.exp: Run new discard-* tests.
>>     * ld-s390/discard.ld: New linker script.
>>     * ld-s390/discard.s: New test source.
>>     * ld-s390/discard-pde.d: New test for discarded sections in
>>     a position-dependent executable (PDE).
>>     * ld-s390/discard-pie.d: New test for discarded sections in
>>     a position-independent executable (PIE). (XFAIL)
>>     * ld-s390/discard-shared.d: New test for discarded sections in
>>     a shared library.
>>
>> Signed-off-by: Jens Remus <jremus@linux.ibm.com>
>> ---
>>
>> Notes (jremus):
>>      The plan is to address the XFAIL and superfluous R_390_NONE
>>      relocations with a future patch, implementing x86-64's solution
>>      using check_relocs and scan_relocs from x86 commit 3747999c6bd4
>>      ("ld: Extract _bfd_elf_link_iterate_on_relocs").
>>
>>   ld/testsuite/ld-s390/discard-pde.d    |  6 +++
>>   ld/testsuite/ld-s390/discard-pie.d    | 13 ++++++
>>   ld/testsuite/ld-s390/discard-shared.d | 13 ++++++
>>   ld/testsuite/ld-s390/discard.ld       | 14 ++++++
>>   ld/testsuite/ld-s390/discard.s        | 61 +++++++++++++++++++++++++++
>>   ld/testsuite/ld-s390/s390.exp         |  6 +++
>>   6 files changed, 113 insertions(+)
>>   create mode 100644 ld/testsuite/ld-s390/discard-pde.d
>>   create mode 100644 ld/testsuite/ld-s390/discard-pie.d
>>   create mode 100644 ld/testsuite/ld-s390/discard-shared.d
>>   create mode 100644 ld/testsuite/ld-s390/discard.ld
>>   create mode 100644 ld/testsuite/ld-s390/discard.s

-- 
Jens Remus
Linux on Z Development (D3303)
jremus@de.ibm.com / jremus@linux.ibm.com

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Ehningen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/



More information about the Binutils mailing list