s390: Improve static-pie configure tests
[glibc.git] / sysdeps / s390 / s390-64 / configure.ac
blobfd729e1496ceba1673e8f09686ca4e4ec32af552
1 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2 # Local configure fragment for sysdeps/s390/s390-64.
4 # Minimal checking for static PIE support in ld.
5 # Compare to ld testcase/bugzilla:
6 # <binutils-source>/ld/testsuite/ld-elf/pr22263-1.rd
7 AC_CACHE_CHECK([for s390-specific static PIE requirements (runtime check)], \
8 [libc_cv_s390x_staticpie_req_runtime], [dnl
9   cat > conftest1.c <<EOF
10 __thread int * foo;
12 void
13 bar (void)
15   *foo = 1;
18 void bar2 (void);
19 void* bar2_ifunc (void) __asm__ ("bar2");
20 __asm__ (".type bar2, %gnu_indirect_function");
21 void* bar2_ifunc (void) { return 0; }
22 EOF
23   cat > conftest2.c <<EOF
24 extern __thread int *foo;
25 extern void bar (void);
26 extern void bar2 (void);
27 static int x;
29 int
30 main ()
32   foo = &x;
33   bar2 ();
34   return 0;
36 EOF
37   libc_cv_s390x_staticpie_req_runtime=no
38   # Check if the static linker does not generate dynamic TLS relocs in PIE
39   # (binutils PR ld/22263), if it accepts --no-dynamic-linker
40   # (by using -static-pie), and if it adds a DT_JMPREL pointing to .rela.iplt
41   # with static pie.
42   if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest1.c -o conftest1.o]) \
43      && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest2.c -o conftest2.o]) \
44      && AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -static-pie -nostartfiles -nostdlib -fPIE -o conftest conftest1.o conftest2.o]) \
45      && AC_TRY_COMMAND([! LC_ALL=C $READELF -Wr conftest | grep R_390_TLS_TPOFF]) \
46      && AC_TRY_COMMAND([LC_ACLL=C $READELF -d conftest | grep JMPREL])
47   then
48     libc_cv_s390x_staticpie_req_runtime=yes
49   fi
50   rm -rf conftest.*])
52 if test $libc_cv_s390x_staticpie_req_runtime = yes; then
53    # Some kernels might fail with /proc/sys/kernel/randomize_va_space set to 0
54    # due not enough space for a brk call.  However, there is no reliable way to
55    # test it.
56    AC_DEFINE(SUPPORT_STATIC_PIE)