I think __sbrk is called in __libc_setup_tls before setting up %gs/TLS properly. Causes early SIGSEGV at startup. Noticed SIGSEGV when tried to install glibc-git in i386: Crash happens at stage when 'elf/sln' is called (at 'make install' phase): $ gdb --args elf/sln elf/symlink.list Program received signal SIGSEGV, Segmentation fault. __brk (addr=0x0) at ../sysdeps/unix/sysv/linux/i386/brk.c:35 35 void *newbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr); (gdb) bt #0 __brk (addr=0x0) at ../sysdeps/unix/sysv/linux/i386/brk.c:35 #1 0x08074589 in __sbrk (increment=3392) at sbrk.c:43 #2 0x08049bd8 in __libc_setup_tls () at libc-tls.c:145 #3 0x080494a2 in __libc_start_main (main=0x80482c0 <main>, argc=2, argv=0xffffc094, init=0x8049d70 <__libc_csu_init>, fini=0x8049e20 <__libc_csu_fini>, rtld_fini=0x0, stack_end=0xffffc08c) at ../csu/libc-start.c:197 #4 0x08048a73 in _start () at ../sysdeps/i386/start.S:109 (gdb) disassemble Dump of assembler code for function __brk: 0x08097d50 <+0>: call 0x805aeee <__x86.get_pc_thunk.cx> 0x08097d55 <+5>: add $0x402ab,%ecx 0x08097d5b <+11>: push %ebx 0x08097d5c <+12>: mov $0x2d,%eax 0x08097d61 <+17>: sub $0x8,%esp 0x08097d64 <+20>: mov 0x10(%esp),%ebx => 0x08097d68 <+24>: call *%gs:0x10 0x08097d6f <+31>: mov %eax,%edx 0x08097d71 <+33>: mov %eax,0x1a64(%ecx) 0x08097d77 <+39>: xor %eax,%eax 0x08097d79 <+41>: cmp %edx,%ebx 0x08097d7b <+43>: jbe 0x8097d89 <__brk+57> 0x08097d7d <+45>: mov $0xfffffff4,%eax 0x08097d82 <+50>: mov %ecx,%ebx 0x08097d84 <+52>: call 0x80499b0 <__syscall_error> 0x08097d89 <+57>: add $0x8,%esp 0x08097d8c <+60>: pop %ebx 0x08097d8d <+61>: ret End of assembler dump. (gdb) list 30 31 int 32 __brk (void *addr) 33 { 34 INTERNAL_SYSCALL_DECL (err); 35 void *newbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr); 36 __curbrk = newbrk; 37 if (newbrk < addr) 38 return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOMEM); 39 return 0; Note that for INTERNAL_SYSCALL 'call *%gs:0x10' is used. AFAIU gs is supposed to be initialized by glibc itself for main thread. But __sbrk system call is used before tls area is set.
This change looks relevant: https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=627c69c838e75d69f46a7cc7dd2bafca03adbf60 as it allows sysenter to be used for static binaries as well.
Reverting 627c69c838e75d69f46a7cc7dd2bafca03adbf60 helped. Note --enable-default-pie in gcc configuration: $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/7.1.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /tmp/portage-tmpdir/portage/sys-devel/gcc-7.1.0-r1/work/gcc-7.1.0/configure --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/7.1.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.1.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.1.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/7.1.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.0/include/g++-v7 --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/7.1.0/python --enable-languages=c,c++,fortran --enable-obsolete --enable-secureplt --disable-werror --with-system-zlib --enable-nls --without-included-gettext --enable-checking=release --with-bugurl=https://bugs.gentoo.org/ --with-pkgversion='Gentoo 7.1.0-r1 p1.1' --disable-esp --enable-libstdcxx-time --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-multilib --with-multilib-list=m32,m64 --disable-altivec --disable-fixed-point --enable-targets=all --disable-libgcj --enable-libgomp --disable-libmudflap --disable-libssp --disable-libcilkrts --disable-libmpx --enable-vtable-verify --enable-libvtv --enable-lto --without-isl --enable-libsanitizer --enable-default-pie --enable-default-ssp Thread model: posix gcc version 7.1.0 (Gentoo 7.1.0-r1 p1.1)
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pr21913 has been created at 5b4dd7f1b6694f49d5773ff131986cd619c13c9d (commit) - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5b4dd7f1b6694f49d5773ff131986cd619c13c9d commit 5b4dd7f1b6694f49d5773ff131986cd619c13c9d Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Jul 19 14:32:42 2017 -0700 i386: Add _startup_sbrk and _startup_fatal [BZ #21913] On Linux/x86, there are 3 ways to make a system call: 1. call *%gs:SYSINFO_OFFSET. This requires TLS initialization. 2. call *_dl_sysinfo. This requires relocation of _dl_sysinfo. 3. int $0x80. This works everywhere. When an object file is compiled with PIC, #1 is prefered since it is faster than #3 and doesn't require relocation of _dl_sysinfo. For dynamic executables, ld.so initializes TLS. However, for static executables, before TLS is initialized by __libc_setup_tls, #3 should be used for syscalls. This patch adds _startup_sbrk and _startup_fatal to be used in static executables before __libc_setup_tls is called. By default, they are defined to __sbrk and __libc_fatal, respectively. On x86, a special _startup_sbrk is provided and _startup_fatal is turned into ABORT_INSTRUCTION. [BZ #21913] * csu/libc-tls.c: Include <startup.h>. (__libc_setup_tls): Call _startup_sbrk instead of __sbrk. Call _startup_fatal instead of __libc_fatal. * elf/dl-tunables.c: Include <startup.h>. (tunables_strdup): Call _startup_sbrk instead of __sbrk. * sysdeps/generic/startup.h: New file. * sysdeps/unix/sysv/linux/i386/startup.h: Likewise. * sysdeps/unix/sysv/linux/i386/startup_sbrk.c: Likewise. * sysdeps/unix/sysv/linux/i386/Makefile (sysdep_routine): Add startup_sbrk if default to PIC. (static-only-routines): Likewise. -----------------------------------------------------------------------
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pie/static has been created at bdf68a2a6f8a53684378b4d495d05a4db2d3b16e (commit) - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bdf68a2a6f8a53684378b4d495d05a4db2d3b16e commit bdf68a2a6f8a53684378b4d495d05a4db2d3b16e Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Jul 18 10:42:48 2017 -0700 Use hidden visibility for libc.a with PIC Size comparison of static PIE elf/ldconfig: On x86-64: text data bss dec hex Before: 866113 22952 6336 895401 da9a9 After : 865921 22952 6336 895209 da8e9 On i686: text data bss dec hex Before: 782692 12296 3748 798736 c3010 After : 781153 12280 3748 797181 c29fd https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5c2d331c8b1be24ccefa6ec47df969557e7fb609 commit 5c2d331c8b1be24ccefa6ec47df969557e7fb609 Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 13:53:52 2017 -0700 Add _dl_relocate_static_pie https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=3c7e37d0fefe01fc851a7bf9a685ca67013ac54e commit 3c7e37d0fefe01fc851a7bf9a685ca67013ac54e Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 08:54:40 2017 -0700 Define pie-default/default-pie-ldflag for --enable-static-pie 1. Add $(pie-default) to CFLAGS-.o and CFLAGS-.op. 2. Add $(default-pie-ldflag) to +link-static-before-libc. 3. Define +prectorT/+postctorT to $(+prectorS)/$(+postctorS). https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=e32bbfdf481a485cd7e177c8949032d013016657 commit e32bbfdf481a485cd7e177c8949032d013016657 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Jul 18 05:58:21 2017 -0700 x86-64: Check if linker supports static PIE Need the linker with fix for: https://sourceware.org/bugzilla/show_bug.cgi?id=21782 Binutils 2.29 is OK. https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=ebf1796e7d7f476ab16f0cf7de56874d3504dd1f commit ebf1796e7d7f476ab16f0cf7de56874d3504dd1f Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 08:36:45 2017 -0700 Add --enable-static-pie https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=d93968ee86681ceae8e114173561f120e05f3ba2 commit d93968ee86681ceae8e114173561f120e05f3ba2 Author: H.J. Lu <hjl.tools@gmail.com> Date: Sun Jul 23 05:26:26 2017 -0700 Check if -static and -pie work together https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=5548e9d5ae48c2401f23e446feacd4255017a54a commit 5548e9d5ae48c2401f23e446feacd4255017a54a Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Jul 21 05:07:19 2017 -0700 Check if -static-pie works https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=070ec388ccc29f0d2c86d4113d7abacd7bbd76ab commit 070ec388ccc29f0d2c86d4113d7abacd7bbd76ab Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 08:17:32 2017 -0700 Check if linker supports --no-dynamic-linker https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7f7ff317da23e4e3010698e49321143190104c83 commit 7f7ff317da23e4e3010698e49321143190104c83 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Jul 19 14:32:42 2017 -0700 i386: Add _startup_sbrk and _startup_fatal [BZ #21913] [BZ #21913] * csu/libc-tls.c: Include <startup.h>. (__libc_setup_tls): Call _startup_sbrk instead of __sbrk. Call _startup_fatal instead of __libc_fatal. * elf/dl-tunables.c: Include <startup.h>. (tunables_strdup): Call _startup_sbrk instead of __sbrk. * sysdeps/generic/startup.h: New file. * sysdeps/unix/sysv/linux/i386/startup.h: Likewise. * sysdeps/unix/sysv/linux/i386/startup_sbrk.c: Likewise. * sysdeps/unix/sysv/linux/i386/Makefile (sysdep_routine): Add startup_sbrk if default to PIC. (static-only-routines): Likewise. -----------------------------------------------------------------------
A patch is posted at https://sourceware.org/ml/libc-alpha/2017-08/msg00201.html
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pr21913 has been deleted was 5b4dd7f1b6694f49d5773ff131986cd619c13c9d - Log ----------------------------------------------------------------- 5b4dd7f1b6694f49d5773ff131986cd619c13c9d i386: Add _startup_sbrk and _startup_fatal [BZ #21913] -----------------------------------------------------------------------
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pr21913 has been created at aaddc88d7aafc1965cb2a3aa3c17da4dd53ddd21 (commit) - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=aaddc88d7aafc1965cb2a3aa3c17da4dd53ddd21 commit aaddc88d7aafc1965cb2a3aa3c17da4dd53ddd21 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Jul 19 14:32:42 2017 -0700 i386: Add _startup_sbrk and _startup_fatal [BZ #21913] On Linux/x86, there are 3 ways to make a system call: 1. call *%gs:SYSINFO_OFFSET. This requires TLS initialization. 2. call *_dl_sysinfo. This requires relocation of _dl_sysinfo. 3. int $0x80. This is slower than #2 and #3, but works everywhere. When an object file is compiled with PIC, #1 is prefered since it is faster than #3 and doesn't require relocation of _dl_sysinfo. For dynamic executables, ld.so initializes TLS. However, for static executables, before TLS is initialized by __libc_setup_tls, #3 should be used for syscalls. This patch adds _startup_sbrk and _startup_fatal to be used in static executables before __libc_setup_tls is called. By default, they are defined to __sbrk and __libc_fatal, respectively. On x86, a special _startup_sbrk is provided and _startup_fatal is turned into ABORT_INSTRUCTION. [BZ #21913] * csu/libc-tls.c: Include <startup.h>. (__libc_setup_tls): Call _startup_sbrk instead of __sbrk. Call _startup_fatal instead of __libc_fatal. * elf/dl-tunables.c: Include <startup.h>. (tunables_strdup): Call _startup_sbrk instead of __sbrk. * sysdeps/generic/startup.h: New file. * sysdeps/unix/sysv/linux/i386/startup.h: Likewise. * sysdeps/unix/sysv/linux/i386/startup_sbrk.c: Likewise. * sysdeps/unix/sysv/linux/i386/Makefile (sysdep_routine): Add startup_sbrk if default to PIC. (static-only-routines): Likewise. -----------------------------------------------------------------------
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pr21913 has been deleted was aaddc88d7aafc1965cb2a3aa3c17da4dd53ddd21 - Log ----------------------------------------------------------------- aaddc88d7aafc1965cb2a3aa3c17da4dd53ddd21 i386: Add _startup_sbrk and _startup_fatal [BZ #21913] -----------------------------------------------------------------------
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pr21913/master has been created at 99dd28489e425c6f654126871f89d514331aa69f (commit) - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=99dd28489e425c6f654126871f89d514331aa69f commit 99dd28489e425c6f654126871f89d514331aa69f Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Jul 19 14:32:42 2017 -0700 i386: Add <startup.h> [BZ #21913] On Linux/i386, there are 3 ways to make a system call: 1. call *%gs:SYSINFO_OFFSET. This requires TLS initialization. 2. call *_dl_sysinfo. This requires relocation of _dl_sysinfo. 3. int $0x80. This is slower than #2 and #3, but works everywhere. When an object file is compiled with PIC, #1 is prefered since it is faster than #3 and doesn't require relocation of _dl_sysinfo. For dynamic executables, ld.so initializes TLS. However, for static executables, before TLS is initialized by __libc_setup_tls, #3 should be used for syscalls. This patch adds <startup.h> which defines _startup_fatal and defaults it to __libc_fatal. It replaces __libc_fatal with _startup_fatal in static executables where it is called before __libc_setup_tls is called. This header file is included in all files containing functions which are called before __libc_setup_tls is called. On Linux/i386, when PIE is enabled by default, _startup_fatal is turned into ABORT_INSTRUCTION and I386_USE_SYSENTER is defined to 0 so that "int $0x80" is used for system calls before __libc_setup_tls is called. [BZ #21913] * config.h.in (BUILD_PIE_DEFAULT): New. * csu/libc-tls.c: Include <startup.h>. * elf/dl-tunables.c: Likewise. * sysdeps/unix/sysv/linux/i386/brk.c: Likewise. * csu/libc-tls.c: Include <startup.h>. (__libc_setup_tls): Call _startup_fatal instead of __libc_fatal. * sysdeps/generic/startup.h: New file. * sysdeps/unix/sysv/linux/i386/startup.h: Likewise. -----------------------------------------------------------------------
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, hjl/pie/static has been created at 6a41eb77cc1bb9926c1edcb41f934ad96b43a9d1 (commit) - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=6a41eb77cc1bb9926c1edcb41f934ad96b43a9d1 commit 6a41eb77cc1bb9926c1edcb41f934ad96b43a9d1 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Jul 18 10:42:48 2017 -0700 Use hidden visibility for libc.a with PIC Size comparison of static PIE elf/ldconfig: On x86-64: text data bss dec hex Before: 866113 22952 6336 895401 da9a9 After : 865921 22952 6336 895209 da8e9 On i686: text data bss dec hex Before: 782692 12296 3748 798736 c3010 After : 781153 12280 3748 797181 c29fd https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=db2e81b0bb258f9b0b92930bbdf1cbe7bd87c2cd commit db2e81b0bb258f9b0b92930bbdf1cbe7bd87c2cd Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 13:53:52 2017 -0700 Add _dl_relocate_static_pie https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=bff6385dd7f7548290cdf099438153bcae45d93a commit bff6385dd7f7548290cdf099438153bcae45d93a Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 08:54:40 2017 -0700 Define pie-default/default-pie-ldflag for --enable-static-pie 1. Add $(pie-default) to CFLAGS-.o and CFLAGS-.op. 2. Add $(default-pie-ldflag) to +link-static-before-libc. 3. Define +prectorT/+postctorT to $(+prectorS)/$(+postctorS). https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=65a3c646b5cf6c8f0ea5804274e6167f397a1206 commit 65a3c646b5cf6c8f0ea5804274e6167f397a1206 Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Jul 18 05:58:21 2017 -0700 x86-64: Check if linker supports static PIE Need the linker with fix for: https://sourceware.org/bugzilla/show_bug.cgi?id=21782 Binutils 2.29 is OK. https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=66af3e71af2583d41a4eaa77781bd99110723384 commit 66af3e71af2583d41a4eaa77781bd99110723384 Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 08:36:45 2017 -0700 Add --enable-static-pie https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=319fc7c7e5fa501263e4408673d63288a846d5d7 commit 319fc7c7e5fa501263e4408673d63288a846d5d7 Author: H.J. Lu <hjl.tools@gmail.com> Date: Sun Jul 23 05:26:26 2017 -0700 Check if -static and -pie work together https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c5cf3025294f43c1f8fd6d28fd4faf3504d81047 commit c5cf3025294f43c1f8fd6d28fd4faf3504d81047 Author: H.J. Lu <hjl.tools@gmail.com> Date: Fri Jul 21 05:07:19 2017 -0700 Check if -static-pie works https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=add31350f0d488372cfd6a426e434856db613584 commit add31350f0d488372cfd6a426e434856db613584 Author: H.J. Lu <hjl.tools@gmail.com> Date: Mon Jul 17 08:17:32 2017 -0700 Check if linker supports --no-dynamic-linker https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=66ee1f78e0bab3f3720bb99ae2a05c000bbefac6 commit 66ee1f78e0bab3f3720bb99ae2a05c000bbefac6 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Jul 19 14:32:42 2017 -0700 i386: Add _startup_sbrk and _startup_fatal [BZ #21913] On Linux/i386, there are 3 ways to make a system call: 1. call *%gs:SYSINFO_OFFSET. This requires TLS initialization. 2. call *_dl_sysinfo. This requires relocation of _dl_sysinfo. 3. int $0x80. This is slower than #2 and #3, but works everywhere. When an object file is compiled with PIC, #1 is prefered since it is faster than #3 and doesn't require relocation of _dl_sysinfo. For dynamic executables, ld.so initializes TLS. However, for static executables, before TLS is initialized by __libc_setup_tls, #3 should be used for syscalls. This patch adds _startup_sbrk and _startup_fatal to be used in static executables before __libc_setup_tls is called. By default, they are defined to __sbrk and __libc_fatal, respectively. On Linux/i386, a special _startup_sbrk is provided and _startup_fatal is turned into ABORT_INSTRUCTION. [BZ #21913] * csu/libc-tls.c: Include <startup.h>. (__libc_setup_tls): Call _startup_sbrk instead of __sbrk. Call _startup_fatal instead of __libc_fatal. * elf/dl-tunables.c: Include <startup.h>. (tunables_strdup): Call _startup_sbrk instead of __sbrk. * sysdeps/generic/startup.h: New file. * sysdeps/unix/sysv/linux/i386/startup.h: Likewise. * sysdeps/unix/sysv/linux/i386/startup_sbrk.c: Likewise. * sysdeps/unix/sysv/linux/i386/Makefile (sysdep_routine): Add startup_sbrk if default to PIE. (static-only-routines): Likewise. -----------------------------------------------------------------------
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "GNU C Library master sources". The branch, master has been updated via 086df229eef36041cae4a633c6fde6150f18d75e (commit) from fc5ad7024c620cdfe9b76e94638aac83b99c5bf8 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=086df229eef36041cae4a633c6fde6150f18d75e commit 086df229eef36041cae4a633c6fde6150f18d75e Author: H.J. Lu <hjl.tools@gmail.com> Date: Tue Aug 8 08:41:08 2017 -0700 i386: Add <startup.h> [BZ #21913] On Linux/i386, there are 3 ways to make a system call: 1. call *%gs:SYSINFO_OFFSET. This requires TLS initialization. 2. call *_dl_sysinfo. This requires relocation of _dl_sysinfo. 3. int $0x80. This is slower than #2 and #3, but works everywhere. When an object file is compiled with PIC, #1 is prefered since it is faster than #3 and doesn't require relocation of _dl_sysinfo. For dynamic executables, ld.so initializes TLS. However, for static executables, before TLS is initialized by __libc_setup_tls, #3 should be used for system calls. This patch adds <startup.h> which defines _startup_fatal and defaults it to __libc_fatal. It replaces __libc_fatal with _startup_fatal in static executables where it is called before __libc_setup_tls is called. This header file is included in all files containing functions which are called before __libc_setup_tls is called. On Linux/i386, when PIE is enabled by default, _startup_fatal is turned into ABORT_INSTRUCTION and I386_USE_SYSENTER is defined to 0 so that "int $0x80" is used for system calls before __libc_setup_tls is called. Tested on i686 and x86-64. Without this patch, all statically-linked tests will fail on i686 when the compiler defaults to -fPIE. [BZ #21913] * csu/libc-tls.c: Include <startup.h> first. (__libc_setup_tls): Call _startup_fatal instead of __libc_fatal. * elf/dl-tunables.c: Include <startup.h> first. * include/libc-symbols.h (BUILD_PIE_DEFAULT): New. * sysdeps/generic/startup.h: New file. * sysdeps/unix/sysv/linux/i386/startup.h: Likewise. * sysdeps/unix/sysv/linux/i386/brk.c [BUILD_PIE_DEFAULT != 0] (I386_USE_SYSENTER): New. Defined to 0. ----------------------------------------------------------------------- Summary of changes: ChangeLog | 12 +++++++ csu/libc-tls.c | 3 +- elf/dl-tunables.c | 1 + include/libc-symbols.h | 8 +++++ .../huge_val_flt128.h => sysdeps/generic/startup.h | 10 +++--- sysdeps/unix/sysv/linux/i386/brk.c | 5 +++ .../linux/{open_by_handle_at.c => i386/startup.h} | 31 +++++++++---------- 7 files changed, 48 insertions(+), 22 deletions(-) copy bits/huge_val_flt128.h => sysdeps/generic/startup.h (69%) copy sysdeps/unix/sysv/linux/{open_by_handle_at.c => i386/startup.h} (60%)
Fixed.