]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
ld: Pass $NOPIE_CFLAGS and $NOPIE_LDFLAGS to more ELF visibility tests
authorJens Remus <jremus@linux.ibm.com>
Fri, 28 Mar 2025 14:27:11 +0000 (15:27 +0100)
committerJens Remus <jremus@linux.ibm.com>
Fri, 28 Mar 2025 14:27:11 +0000 (15:27 +0100)
Some distributions configure GCC with --enable-default-pie, so that it
defaults to compile with -fPIE and link with -pie, which is unexpected
by the test.  Therefore compile the non-PIC sources with $NOPIE_CFLAGS
and link the test programs with $NOPIE_LDFLAGS.

Commit 922109c71828 ("Pass $NOPIE_CFLAGS to ELF visibility tests") added
$NOPIE_CFLAGS when compiling sh1np.o and sh2np.o.  It missed to add it
to mainnp.o.

ld/testsuite/
PR ld/21090
* ld-vsb/vsb.exp (visibility_test): Add support for optional
ldflags argument and use it when linking the test program.
(mainnp.o): Compile with $NOPIE_CFLAGS.
(vnp, vp, vmpnp, vmpp): Link with $NOPIE_LDFLAGS.

Fixes: 922109c71828 ("Pass $NOPIE_CFLAGS to ELF visibility tests")
Bug: https://sourceware.org/PR21090
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
ld/testsuite/ld-vsb/vsb.exp

index 9a61e9d90fe68cb423938662d3192290ccceecf0..e44ac398b040b5ffc2dc842aa612b97eaa5112e2 100644 (file)
@@ -134,6 +134,7 @@ proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
     global tmpdir
 
     if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
+    if { [llength $args] >= 2 } { set ldflags [lindex $args 1] } else { set ldflags "" }
 
     # Build the shared library.
     set shared -shared
@@ -169,7 +170,7 @@ proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
        set rpath /lib:$tmpdir
        set exportflag " -Wl,-bexpall"
     }
-    if ![ld_link $CC_FOR_TARGET $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so $exportflag"] {
+    if ![ld_link $CC_FOR_TARGET $tmpdir/$progname "-Wl,-rpath,$rpath $ldflags $tmpdir/$main $tmpdir/$progname.so $exportflag"] {
        if { [ string match $visibility "hidden" ]
             && [regexp "undefined reference to \`\.?visibility\'" $link_output]
             && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
@@ -235,6 +236,7 @@ proc visibility_run {visibility} {
     global shared_needs_pic
     global PLT_CFLAGS
     global NOPIE_CFLAGS
+    global NOPIE_LDFLAGS
     global COMPRESS_LDFLAG
     global NOSANITIZE_CFLAGS
     global NOLTO_CFLAGS
@@ -284,7 +286,7 @@ proc visibility_run {visibility} {
     } else {
     # Compile the main program.  Make sure that PLT is used since PLT
     # is expected.
-    if ![ld_compile "$CC_FOR_TARGET -g $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
+    if ![ld_compile "$CC_FOR_TARGET -g $NOPIE_CFLAGS $PLT_CFLAGS $SHCFLAG $VSBCFLAG $NOSANITIZE_CFLAGS $NOLTO_CFLAGS" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
        unsupported "visibility ($visibility) (non PIC)"
        unsupported "visibility ($visibility)"
     } else {
@@ -343,7 +345,7 @@ proc visibility_run {visibility} {
                setup_xfail "*-*-beos*"
            }
 
-           visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o $datfile
+           visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o $datfile "" $NOPIE_LDFLAGS
 
            # Test ELF shared library relocations with a non-zero load
            # address for the library.  Near as I can tell, the R_*_RELATIVE
@@ -395,7 +397,7 @@ proc visibility_run {visibility} {
            if { ![is_xcoff_format] } {
                visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \
                    mainnp.o sh1np.o sh2np.o $datfile \
-                   "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv"
+                   "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv" $NOPIE_LDFLAGS
            }
        }
 
@@ -411,7 +413,7 @@ proc visibility_run {visibility} {
                    setup_xfail $target_triplet
                }
            }
-           visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o $datfile $COMPRESS_LDFLAG
+           visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o $datfile $COMPRESS_LDFLAG $NOPIE_LDFLAGS
        }
     }}
 
@@ -466,7 +468,7 @@ proc visibility_run {visibility} {
                setup_xfail "*-*-beos*"
            }
 
-           visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o $datfile
+           visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o $datfile "" $NOPIE_LDFLAGS
        } else {
            unsupported "visibility (PIC main, non PIC so)"
        }
@@ -488,7 +490,7 @@ proc visibility_run {visibility} {
                setup_xfail "*-*-beos*"
            }
 
-           visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o $datfile
+           visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o $datfile "" $NOPIE_LDFLAGS
        } else {
            unsupported "visibility ($visibility) (PIC main)"
        }