[PATCH] s390: Adjust configure check for static-pie support.
Stefan Liebler
stli@linux.ibm.com
Mon May 11 13:22:11 GMT 2026
With the previous approach, the configure check fails for lld in version >=19.
While binutils and lld 18 is placing the R_390_IRELATIVE relocation in .rela.plt
and emits DT_JMPREL pointing to it, newer lld versions puts the R_390_IRELATIVE
relocation in .rela.dyn and therefore there is also no DT_JMPREL entry and the
configure check claims that lld does not support static-pie.
The R_390_IRELATIVE relocation is also processed fine in .rela.dyn, thus the
configure check is adjusted. Now the configure checks that it exists a
R_390_IRELATIVE relocation at all. If the R_390_IRELATIVE relocation lands in
.rela.plt, it ensures that there is DT_JMPREL pointing to it. Otherwise there
should be a .rela.dyn section.
=====================================================
Questions which won't be added to the commit-message:
=====================================================
With this adjustment, SUPPORT_STATIC_PIE is defined for binutils and lld.
SUPPORT_STATIC_PIE is not defined when using gold (as it lacks --no-dynamic-linker
which is automatically added with gcc -static-pie)
If building with gold, SUPPORT_STATIC_PIE is not defined, but ENABLE_STATIC_PIE
is defined, which leads to linking e.g. test-run-command with -static-pie and it
fails unless we configure with --disable-default-pie.
In the main-configure.ac, there are those checks:
AC_MSG_CHECKING(if we can build static PIE programs)
libc_cv_static_pie_supported=$libc_cv_pie_supported
if test "x$libc_cv_pie_supported" != xno \
-a "$libc_cv_no_dynamic_linker" = yes; then
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[#ifndef SUPPORT_STATIC_PIE
<#>error static PIE is not supported
<#>endif]])], [libc_cv_static_pie_supported=yes],
[libc_cv_static_pie_supported=no])
fi
AC_MSG_RESULT($libc_cv_static_pie_supported)
<#> Enable static-pie only if it is available and glibc isn't configured
<#> with --disable-default-pie.
if test "x$default_pie" = xno; then
libc_cv_static_pie=no
else
libc_cv_static_pie=$libc_cv_static_pie_supported
fi
if test "$libc_cv_static_pie" = "yes"; then
AC_DEFINE(ENABLE_STATIC_PIE)
fi
LIBC_CONFIG_VAR([enable-static-pie], [$libc_cv_static_pie])
Thus if SUPPORT_STATIC_PIE is not defined it can/could disable ENABLE_STATIC_PIE.
In case of gold this does not happen as it lacks --no-dynamic-linker and it falls
back to libc_cv_static_pie_supported=$libc_cv_pie_supported. Is this the intended
behaviour?
Currently, if I'm testing glibc with lld, "make check" stops with an error (x86_64 and s390x):
ld.lld: error: build/elf/tst-execstack-prog-static-tunable.o: requires an executable stack, but -z execstack is not specified
For gold, "make check" also stops with an error when linking tst-thp-size-mod.so (x86_64 and s390x):
/usr/bin/ld.gold: noseparate-code: unknown -z option
Should those tests somehow guarded?
---
sysdeps/s390/configure | 30 +++++++++++++++++++++++++-----
sysdeps/s390/configure.ac | 13 +++++++++----
2 files changed, 34 insertions(+), 9 deletions(-)
diff --git a/sysdeps/s390/configure b/sysdeps/s390/configure
index e21a5ba3a7..8731f182bb 100644
--- a/sysdeps/s390/configure
+++ b/sysdeps/s390/configure
@@ -310,8 +310,10 @@ EOF
libc_cv_s390x_staticpie_req_runtime=no
# Check if the static linker does not generate dynamic TLS relocs in PIE
# (binutils PR ld/22263), if it accepts --no-dynamic-linker
- # (by using -static-pie), and if it adds a DT_JMPREL pointing to .rela.iplt
- # with static pie.
+ # (by using -static-pie).
+ # If the R_390_IRELATIVE relocation lands in .rela.plt, ensure that there is
+ # DT_JMPREL pointing to it (binutils). Otherwise there should be a .rela.dyn
+ # without DT_JMPREL (lld>=19).
if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest1.c -o conftest1.o'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
@@ -336,16 +338,34 @@ EOF
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; } \
- && { ac_try='LC_ALL=C $READELF -Wd conftest | grep JMPREL >&5'
+ && { ac_try='LC_ALL=C $READELF -Wr conftest | grep R_390_IRELATIVE >&5'
{ { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
(eval $ac_try) 2>&5
ac_status=$?
printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
- test $ac_status = 0; }; }
+ test $ac_status = 0; }; } \
+ && ( { ac_try='LC_ALL=C $READELF -Wr conftest | grep \.rela\.plt >&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; } \
+ && { ac_try='LC_ALL=C $READELF -Wd conftest | grep JMPREL >&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; } \
+ || { ac_try='LC_ALL=C $READELF -Wr conftest | grep \.rela\.dyn >&5'
+ { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ printf "%s\n" "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; } )
then
libc_cv_s390x_staticpie_req_runtime=yes
fi
- rm -rf conftest.* ;;
+ rm -rf conftest* ;;
esac
fi
eval ac_res=\$\
diff --git a/sysdeps/s390/configure.ac b/sysdeps/s390/configure.ac
index 3c384f9670..acbd8ebe11 100644
--- a/sysdeps/s390/configure.ac
+++ b/sysdeps/s390/configure.ac
@@ -169,17 +169,22 @@ EOF
libc_cv_s390x_staticpie_req_runtime=no
# Check if the static linker does not generate dynamic TLS relocs in PIE
# (binutils PR ld/22263), if it accepts --no-dynamic-linker
- # (by using -static-pie), and if it adds a DT_JMPREL pointing to .rela.iplt
- # with static pie.
+ # (by using -static-pie).
+ # If the R_390_IRELATIVE relocation lands in .rela.plt, ensure that there is
+ # DT_JMPREL pointing to it (binutils). Otherwise there should be a .rela.dyn
+ # without DT_JMPREL (lld>=19).
if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest1.c -o conftest1.o]) \
&& AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest2.c -o conftest2.o]) \
&& AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostartfiles -nostdlib -fPIE -o conftest conftest1.o conftest2.o]) \
&& AC_TRY_COMMAND([! LC_ALL=C $READELF -Wr conftest | grep R_390_TLS_TPOFF] >&AS_MESSAGE_LOG_FD) \
- && AC_TRY_COMMAND([LC_ALL=C $READELF -Wd conftest | grep JMPREL >&AS_MESSAGE_LOG_FD])
+ && AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep R_390_IRELATIVE] >&AS_MESSAGE_LOG_FD) \
+ && ( AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep \.rela\.plt >&AS_MESSAGE_LOG_FD]) \
+ && AC_TRY_COMMAND([LC_ALL=C $READELF -Wd conftest | grep JMPREL >&AS_MESSAGE_LOG_FD]) \
+ || AC_TRY_COMMAND([LC_ALL=C $READELF -Wr conftest | grep \.rela\.dyn >&AS_MESSAGE_LOG_FD]) )
then
libc_cv_s390x_staticpie_req_runtime=yes
fi
- rm -rf conftest.*])
+ rm -rf conftest*])
if test $libc_cv_s390x_staticpie_req_runtime = yes; then
# Some kernels might fail with /proc/sys/kernel/randomize_va_space set to 0
--
2.52.0
More information about the Libc-alpha
mailing list