S390: Enable static PIE
[glibc.git] / sysdeps / s390 / s390-64 / configure
blob101c570d2e62da25f67eb3d3f617579bcd810438
1 # This file is generated from configure.ac by Autoconf.  DO NOT EDIT!
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 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for s390-specific static PIE requirements" >&5
8 $as_echo_n "checking for s390-specific static PIE requirements... " >&6; }
9 if { as_var=\
10 libc_cv_s390x_staticpie_req; eval \${$as_var+:} false; }; then :
11   $as_echo_n "(cached) " >&6
12 else
13     cat > conftest1.c <<EOF
14 __thread int * foo;
16 void
17 bar (void)
19   *foo = 1;
21 EOF
22   cat > conftest2.c <<EOF
23 extern __thread int *foo;
24 extern void bar (void);
25 static int x;
27 int
28 main ()
30   foo = &x;
31   return 0;
33 EOF
34   libc_cv_s390x_staticpie_req=no
35   if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest1.c -o conftest1.o'
36   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
37   (eval $ac_try) 2>&5
38   ac_status=$?
39   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
40   test $ac_status = 0; }; } \
41      && { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -fPIE -c conftest2.c -o conftest2.o'
42   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
43   (eval $ac_try) 2>&5
44   ac_status=$?
45   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
46   test $ac_status = 0; }; } \
47      && { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -o conftest conftest1.o conftest2.o'
48   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
49   (eval $ac_try) 2>&5
50   ac_status=$?
51   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
52   test $ac_status = 0; }; } \
53      && { ac_try='! readelf -Wr conftest | grep R_390_TLS_TPOFF'
54   { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
55   (eval $ac_try) 2>&5
56   ac_status=$?
57   $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
58   test $ac_status = 0; }; }
59   then
60     libc_cv_s390x_staticpie_req=yes
61   fi
62   rm -rf conftest.*
64 eval ac_res=\$\
65 libc_cv_s390x_staticpie_req
66                { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
67 $as_echo "$ac_res" >&6; }
68 if test $libc_cv_s390x_staticpie_req = yes; then
69    # Static PIE is supported only on 64bit.
70    # Ensure you also have those patches for:
71    # - binutils (ld)
72    #   - "[PR ld/22263] s390: Avoid dynamic TLS relocs in PIE"
73    #     https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=26b1426577b5dcb32d149c64cca3e603b81948a9
74    #     (Tested by configure check above)
75    #     Otherwise there will be a R_390_TLS_TPOFF relocation, which fails to
76    #     be processed in _dl_relocate_static_pie() as static TLS map is not setup.
77    #   - "s390: Add DT_JMPREL pointing to .rela.[i]plt with static-pie"
78    #     https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d942d8db12adf4c9e5c7d9ed6496a779ece7149e
79    #     (We can't test it in configure as we are not able to link a static PIE
80    #     executable if the system glibc lacks static PIE support)
81    #     Otherwise there won't be DT_JMPREL, DT_PLTRELA, DT_PLTRELASZ entries
82    #     and the IFUNC symbols are not processed, which leads to crashes.
83    #
84    # - kernel (the mentioned links to the commits belong to 5.19 merge window):
85    #   - "s390/mmap: increase stack/mmap gap to 128MB"
86    #     https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=f2f47d0ef72c30622e62471903ea19446ea79ee2
87    #   - "s390/vdso: move vdso mapping to its own function"
88    #     https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=57761da4dc5cd60bed2c81ba0edb7495c3c740b8
89    #   - "s390/vdso: map vdso above stack"
90    #     https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=9e37a2e8546f9e48ea76c839116fa5174d14e033
91    #   - "s390/vdso: add vdso randomization"
92    #     https://git.kernel.org/pub/scm/linux/kernel/git/s390/linux.git/commit/?h=features&id=41cd81abafdc4e58a93fcb677712a76885e3ca25
93    #   (We can't test the kernel of the target system)
94    #   Otherwise if /proc/sys/kernel/randomize_va_space is turned off (0),
95    #   static PIE executables like ldconfig will crash.  While startup sbrk is
96    #   used to enlarge the HEAP.  Unfortunately the underlying brk syscall fails
97    #   as there is not enough space after the HEAP.  Then the address of the TLS
98    #   image is invalid and the following memcpy in __libc_setup_tls() leads
99    #   to a segfault.
100    #   If /proc/sys/kernel/randomize_va_space is activated (default: 2), there
101    #   is enough space after HEAP.
102    #
103    # - glibc
104    #   - "Linux: Define MMAP_CALL_INTERNAL"
105    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=c1b68685d438373efe64e5f076f4215723004dfb
106    #   - "i386: Remove OPTIMIZE_FOR_GCC_5 from Linux libc-do-syscall.S"
107    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=6e5c7a1e262961adb52443ab91bd2c9b72316402
108    #   - "i386: Honor I386_USE_SYSENTER for 6-argument Linux system calls"
109    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=60f0f2130d30cfd008ca39743027f1e200592dff
110    #   - "ia64: Always define IA64_USE_NEW_STUB as a flag macro"
111    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=18bd9c3d3b1b6a9182698c85354578d1d58e9d64
112    #   - "Linux: Implement a useful version of _startup_fatal"
113    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=a2a6bce7d7e52c1c34369a7da62c501cc350bc31
114    #   - "Linux: Introduce __brk_call for invoking the brk system call"
115    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=b57ab258c1140bc45464b4b9908713e3e0ee35aa
116    #   - "csu: Implement and use _dl_early_allocate during static startup"
117    #     https://sourceware.org/git/?p=glibc.git;a=commit;h=f787e138aa0bf677bf74fa2a08595c446292f3d7
118    #   The mentioned patch series by Florian Weimer avoids the mentioned failing
119    #   sbrk syscall by falling back to mmap.
120    $as_echo "#define SUPPORT_STATIC_PIE 1" >>confdefs.h