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