[PATCH v2] s390: Do not use canonical PLT if pointer equality is not needed

Jens Remus jremus@linux.ibm.com
Tue Mar 17 09:27:29 GMT 2026


On 3/16/2026 6:07 PM, Jens Remus wrote:
> Require pointer equality in executables for symbols with non-PLT
> PC-relative relocations, that are likely in address taken context, and
> direct relocations, that are likely in function reference context. Do so
> for IFUNC symbols defined in a non-shared object.  Clear value of PLT
> undefined symbols if pointer equality is not needed and do not hash them
> in '.gnu.hash' section.

> ld/testsuite/
> 	PR ld/29655
> 	* ld-elf/shared.exp: Add new pr29655 test.
> 	* ld-elf/pr29655a.c: New file.  Based on Rui's sample in PR.
> 	* ld-elf/pr29655b.c: Likewise.
> 	* ld-s390/plt_64-1.wf: Adjust expected test output to change in
> 	.gnu.hash due to omitted PLT undefined symbols that do not need
> 	pointer equality.
> 	* ld-s390/plt_64-1_eh.wf: Likewise.
> 
> Bug: https://sourceware.org/PR29655
> Co-authored-by: Andreas Krebbel <krebbel@linux.ibm.com>
> Signed-off-by: Jens Remus <jremus@linux.ibm.com>

> diff --git a/ld/testsuite/ld-elf/pr29655a.c b/ld/testsuite/ld-elf/pr29655a.c
> new file mode 100644

> @@ -0,0 +1,20 @@
> +#include <stdio.h>
> +
> +typedef void Fn();
> +
> +void __attribute__((visibility("hidden")))
> +fun (void)
> +{}
> +
> +extern void fun_public() __attribute__((alias("fun")));
> +
> +void
> +call_callback (Fn *callback)
> +{
> +  if (callback == fun)
> +    printf("PASS\n");
> +  else
> +    printf("FAIL\n");
> +
> +  callback ();
> +}

> diff --git a/ld/testsuite/ld-elf/pr29655b.c b/ld/testsuite/ld-elf/pr29655b.c
> new file mode 100644

> @@ -0,0 +1,15 @@
> +#ifndef __PIC__
> +#error "this file must be compiled with -fPIC"
> +#endif
> +
> +typedef void Fn();
> +void fun_public(void);
> +void call_callback(Fn *callback);
> +
> +int
> +main ()
> +{
> +  fun_public ();
> +  call_callback (fun_public);
> +  return 0;
> +}

> diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp

> @@ -1863,3 +1863,33 @@ run_ld_link_tests [list \
>  	"pr23658-2" \
>      ] \
>  ]
> +
> +# PR 29655
> +run_cc_link_tests [list \
> +    [list \
> +	"Build pr29655.so" \
> +	"-shared" \
> +	"-fPIC" \
> +	{ pr29655a.c } \
> +	{} \
> +	"pr29655.so" \
> +    ] \
> +]
> +# PR 29655 (cont.): Check that in PIC code linked as PDE taking the address
> +# of a function defined in a DSO results in the function address (from GOT)
> +# and not the "canonical PLT" address from the PDE.
> +# This is just an optimization and both is valid, although libraries may
> +# depend on this specific behavior, so do not complain loudly.
> +setup_xfail *-*-*
> +clear_xfail i?86-*-* powerpc*-*-* s390x-*-* x86_64-*-*

This needs arm*-*-* aarch64-*-* to be added according to the
Linaro-TCWG-CI.

Nick, Alan, Jan, any thoughts whether adding a common test makes sense
or whether should I better make this a s390-specific test (in ld-s390)?

Given this test requires to be run, I cannot verify for other targets.

> +run_ld_link_exec_tests [list \
> +    [list \
> +	"Run pr29655" \
> +	"$NOPIE_LDFLAGS -Wl,--no-as-needed,-rpath,tmpdir tmpdir/pr29655.so" \
> +	"" \
> +	{ pr29655b.c } \
> +	"pr29655" \
> +	"pass.out" \
> +	"-fPIC" \
> +    ] \
> +]
Thanks and regards,
Jens
-- 
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