diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2017-08-08 08:41:08 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2017-08-08 08:43:15 -0700 |
commit | 086df229eef36041cae4a633c6fde6150f18d75e (patch) | |
tree | 47dff30e27b32d6a0b472bfe76e36aa08bf7baa7 /sysdeps/generic/startup.h | |
parent | fc5ad7024c620cdfe9b76e94638aac83b99c5bf8 (diff) | |
download | glibc-086df229eef36041cae4a633c6fde6150f18d75e.zip glibc-086df229eef36041cae4a633c6fde6150f18d75e.tar.gz glibc-086df229eef36041cae4a633c6fde6150f18d75e.tar.bz2 |
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.
Diffstat (limited to 'sysdeps/generic/startup.h')
-rw-r--r-- | sysdeps/generic/startup.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/sysdeps/generic/startup.h b/sysdeps/generic/startup.h new file mode 100644 index 0000000..a961e27 --- /dev/null +++ b/sysdeps/generic/startup.h @@ -0,0 +1,23 @@ +/* Generic definitions of functions used by static libc main startup. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + <http://www.gnu.org/licenses/>. */ + +/* Targets should override this file if the default definitions below + will not work correctly very early before TLS is initialized. */ + +/* Use macro instead of inline function to avoid including <stdio.h>. */ +#define _startup_fatal(message) __libc_fatal ((message)) |