diff options
author | Jens Remus <jremus@linux.ibm.com> | 2025-03-28 15:27:11 +0100 |
---|---|---|
committer | Jens Remus <jremus@linux.ibm.com> | 2025-03-28 15:27:11 +0100 |
commit | 58ed43f97879e80392710030161410534ef57016 (patch) | |
tree | db9a8e8c7ab6bffbd8fb6f138df24e9ec528940d | |
parent | 07468ded302ecaec1114f2d5c4d94e05c631f2ac (diff) | |
download | binutils-58ed43f97879e80392710030161410534ef57016.zip binutils-58ed43f97879e80392710030161410534ef57016.tar.gz binutils-58ed43f97879e80392710030161410534ef57016.tar.bz2 |
ld: Pass $NOPIE_CFLAGS and $NOPIE_LDFLAGS to even more ELF shared tests
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 9d1c54ed7f3a ("Pass $NOPIE_CFLAGS and $NOPIE_LDFLAGS to more ELF
tests") added $NOPIE_CFLAGS when compiling sh1np.o. It missed to add it
to sh2np.o and mainnp.o.
ld/testsuite/
PR ld/21090
* ld-shared/shared.exp (shared_test): Add support for optional
ldflags argument and use it when linking the test program.
(sh2np.o, mainnp.o): Compile with $NOPIE_CFLAGS.
(shnp, shp, shmpnp, shmpp): Link with $NOPIE_LDFLAGS.
Fixes: 9d1c54ed7f3a ("Pass $NOPIE_CFLAGS and $NOPIE_LDFLAGS to more ELF tests")
Bug: https://sourceware.org/PR21090
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
-rw-r--r-- | ld/testsuite/ld-shared/shared.exp | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp index bdbe9a9..a8ddac2 100644 --- a/ld/testsuite/ld-shared/shared.exp +++ b/ld/testsuite/ld-shared/shared.exp @@ -121,6 +121,7 @@ proc shared_test { 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 @@ -146,7 +147,7 @@ proc shared_test { 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"] { fail "$testname" return } @@ -205,7 +206,9 @@ if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then { verbose "Using $picflag to compile PIC code" # Compile the main program. -if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] { +global PLT_CFLAGS NOPIE_CFLAGS NOPIE_LDFLAGS +verbose "Using $NOPIE_CFLAGS to compile and $NOPIE_LDFLAGS to link non PIC code" +if ![ld_compile "$CC_FOR_TARGET $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] { unsupported "shared (non PIC)" unsupported "shared" } else { @@ -215,12 +218,11 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp. # will need to do more relocation work. However, note that not # using -fpic will cause some of the tests to return different # results. Make sure that PLT is used since PLT is expected. - global PLT_CFLAGS NOPIE_CFLAGS if { ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o] - || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } { + || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } { unsupported "shared (non PIC)" } else { if { [is_xcoff_format] } { - shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff + shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o xcoff "" $NOPIE_LDFLAGS } else { # Solaris defaults to -z text. setup_xfail "*-*-solaris2*" @@ -243,7 +245,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp. setup_xfail "arm*-*-linux*" } setup_xfail "aarch64*-*-linux*" - shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared + shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared "" $NOPIE_LDFLAGS # Test ELF shared library relocations with a non-zero load # address for the library. Near as I can tell, the R_*_RELATIVE @@ -273,7 +275,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp. setup_xfail "*-*-solaris2*" shared_test shnp "shared (non PIC, load offset)" \ mainnp.o sh1np.o sh2np.o shared \ - "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv" + "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv" $NOPIE_LDFLAGS } } # Now compile the code using -fpic. @@ -283,13 +285,13 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp. unsupported "shared" } else { if { [is_xcoff_format] } { - shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff + shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff "" $NOPIE_LDFLAGS } else { - shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared - ld_compile "$CC_FOR_TARGET -DSYMBOLIC_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o + shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared "" $NOPIE_LDFLAGS + ld_compile "$CC_FOR_TARGET $NOPIE_CFLAGS -DSYMBOLIC_TEST $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o ld_compile "$CC_FOR_TARGET -DSYMBOLIC_TEST $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o - shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic" - ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o + shared_test shp "shared -Bsymbolic" mainnp.o sh1p.o sh2p.o symbolic "-Bsymbolic" $NOPIE_LDFLAGS + ld_compile "$CC_FOR_TARGET $NOPIE_CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o } } @@ -302,7 +304,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi } else { if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } { if { [is_xcoff_format] } { - shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff + shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff "" $NOPIE_LDFLAGS } else { # Solaris defaults to -z text. setup_xfail "*-*-solaris2*" @@ -325,7 +327,7 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi setup_xfail "arm*-*-linux*" } setup_xfail "aarch64*-*-linux*" - shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared + shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared "" $NOPIE_LDFLAGS } } else { unsupported "shared (PIC main, non PIC so)" @@ -333,9 +335,9 @@ if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } { if { [is_xcoff_format] } { - shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff + shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff "" $NOPIE_LDFLAGS } else { - shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared + shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared "" $NOPIE_LDFLAGS } } else { unsupported "shared (PIC main)" |