[1/1] s390: Un-XFAIL some non-PIC load offset ELF visibility tests

Message ID 20260313151119.3918323-2-jremus@linux.ibm.com
State New
Headers
Series s390: Un-XFAIL some non-PIC load offset ELF visibility tests |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed

Commit Message

Jens Remus March 13, 2026, 3:11 p.m. UTC
  Some of the ELF visibility tests that use a non-PIC shared library with
load offset (first load segment has a non-zero virtual address) XPASS on
s390 64-bit (s390x):

  PASS: visibility (hidden) (non PIC, load offset)
  XFAIL: visibility (hidden_normal) (non PIC, load offset)
  PASS: visibility (hidden_undef) (non PIC, load offset)
  PASS: visibility (hidden_undef_def) (non PIC, load offset)
  XPASS: visibility (hidden_weak) (non PIC, load offset)
  XPASS: visibility (protected) (non PIC, load offset)
  PASS: visibility (protected_undef) (non PIC, load offset)
  XPASS: visibility (protected_undef_def) (non PIC, load offset)
  XPASS: visibility (protected_weak) (non PIC, load offset)
  XFAIL: visibility (normal) (non PIC, load offset)

This is due to Alan Modra's commit 125c64931b97 from 2006, which moved
overriddenvar, shlib_overriddencall2, and shared_data from sh1.c to
sh2.c, if the shared library is build non-PIC.  This prevents GCC from
treating them as local symbols, preventing the executable from
overriding them, causing the tests to fail because interposition did
not work.

This actually only became visible due to H.J. Lu's commit fd7728c8a4aa
("ld: Update function prototypes for compilers defaulting to -std=gnu23")
from 2025, that fixed the ELF visibility test's function prototypes.
Previously all of the "visibility" tests would appear as UNSUPPORTED, as
the prerequisite compile of main.c would fail due to the function
prototypes not matching with their definitions.

In general creating shared libraries from non-PIC compiled code is not
supported on s390 64-bit (s390x).  This is because shared libraries are
inherently position independent.  The Glibc dynamic loader common code
passes the virtual address from the first load segment as hint to
mmap().  As a result a shared library with "load offset" may be loaded
at the virtual address used at link-time, but this is not guaranteed.

The following ELF visibility tests using a non-PIC shared library with
load offset XPASS, if the non-PIC shared library is loaded at its link-
time "load offset".  This causes the tests to PASS by chance.  Un-XFAIL
them.

  XPASS: visibility (hidden_weak) (non PIC, load offset)
  XPASS: visibility (protected) (non PIC, load offset)
  XPASS: visibility (protected_undef_def) (non PIC, load offset)
  XPASS: visibility (protected_weak) (non PIC, load offset)

The following ELF visibility tests using a non-PIC shared library with
load offset still XFAIL:

  XFAIL: visibility (hidden_normal) (non PIC, load offset)
  XFAIL: visibility (normal) (non PIC, load offset)

This is because visibility_var is local in sh1.c, preventing the
executable from overriding it, causing the tests to fail because
interposition does not work.

Note that all of the ELF visibility tests using a non-PIC shared library
without load offset XFAIL, as they are loaded at a random address, which
is incompatible with non-PIC code.

ld/testsuite/
	* ld-vsb/vsb.exp: Un-XFAIL some non-PIC load offset ELF
	visibility tests on s390 64-bit (s390x).

Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
 ld/testsuite/ld-vsb/vsb.exp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Alan Modra March 14, 2026, 12:01 a.m. UTC | #1
On Fri, Mar 13, 2026 at 04:11:19PM +0100, Jens Remus wrote:
> In general creating shared libraries from non-PIC compiled code is not
> supported on s390 64-bit (s390x).

Then don't run what are senseless tests for s390.  It really isn't
worth wasting time trying to make these tests work.  Even x86 (which
is where this non-pic shared library nonsense originated) xfails a
bunch of the non-pic shared tests.

In my opinion they all ought to be removed unless they use assembly
source files, because there is a fundamental gcc conflation of two
separate concepts: "compile for a shared library" and "compile
non-pic".  Yes, non-pic shared libraries can be supported via dynamic
text relocations if you control your gag reflex, but you surely want
"compile for a shared library" in shared library tests.  Thus the
compiled non-pic shared library ld tests are all invalid.
  
Jens Remus March 16, 2026, 10:07 a.m. UTC | #2
On 3/14/2026 1:01 AM, Alan Modra wrote:
> On Fri, Mar 13, 2026 at 04:11:19PM +0100, Jens Remus wrote:
>> In general creating shared libraries from non-PIC compiled code is not
>> supported on s390 64-bit (s390x).
> 
> Then don't run what are senseless tests for s390.  It really isn't
> worth wasting time trying to make these tests work.  Even x86 (which
> is where this non-pic shared library nonsense originated) xfails a
> bunch of the non-pic shared tests.

I simply did not dare.  Given many targets run those tests I felt like
there must be a hidden sense that I just did not realize yet.

Thanks for your feedback!  I'll send a v2 that skips the non-PIC shared
library visibility tests on s390 64-bit (s390x).

> In my opinion they all ought to be removed unless they use assembly
> source files, because there is a fundamental gcc conflation of two
> separate concepts: "compile for a shared library" and "compile
> non-pic".  Yes, non-pic shared libraries can be supported via dynamic
> text relocations if you control your gag reflex, but you surely want
> "compile for a shared library" in shared library tests.  Thus the
> compiled non-pic shared library ld tests are all invalid.

Regards,
Jens
  

Patch

diff --git a/ld/testsuite/ld-vsb/vsb.exp b/ld/testsuite/ld-vsb/vsb.exp
index 03bfd1b241fa..b48e6353eb07 100644
--- a/ld/testsuite/ld-vsb/vsb.exp
+++ b/ld/testsuite/ld-vsb/vsb.exp
@@ -370,11 +370,14 @@  proc visibility_run {visibility} {
 		 || [ string match $visibility "protected_weak" ]
 		 || [ string match $visibility "normal" ] } {
 		setup_xfail "powerpc-*-linux*"
-		setup_xfail "s390x-*-linux*"
 		if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
 		    setup_xfail "sparc*-*-linux*"
 		}
 	    }
+	    if { [ string match $visibility "hidden_normal" ]
+		 || [ string match $visibility "normal" ] } {
+		setup_xfail "s390x-*-linux*"
+	    }
 	    if { ![ string match $visibility "hidden_undef" ]
 		 && ![ string match $visibility "protected_undef" ] } {
 		setup_xfail "ia64-*-linux*"