aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--csu/libc-tls.c3
-rw-r--r--elf/dl-tunables.c1
-rw-r--r--include/libc-symbols.h8
-rw-r--r--sysdeps/generic/startup.h23
-rw-r--r--sysdeps/unix/sysv/linux/i386/brk.c5
-rw-r--r--sysdeps/unix/sysv/linux/i386/startup.h36
7 files changed, 87 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 5b30f0c..8308b53 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-08-08 H.J. Lu <hongjiu.lu@intel.com>
+
+ [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.
+
2017-08-08 Andreas Schwab <schwab@suse.de>
[BZ #21041]
diff --git a/csu/libc-tls.c b/csu/libc-tls.c
index 3c897bf..00138eb 100644
--- a/csu/libc-tls.c
+++ b/csu/libc-tls.c
@@ -16,6 +16,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <startup.h>
#include <errno.h>
#include <ldsodefs.h>
#include <tls.h>
@@ -193,7 +194,7 @@ __libc_setup_tls (void)
# error "Either TLS_TCB_AT_TP or TLS_DTV_AT_TP must be defined"
#endif
if (__builtin_expect (lossage != NULL, 0))
- __libc_fatal (lossage);
+ _startup_fatal (lossage);
/* Update the executable's link map with enough information to make
the TLS routines happy. */
diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 231fb8c..b964a09 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -18,6 +18,7 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#include <startup.h>
#include <stdint.h>
#include <stdbool.h>
#include <unistd.h>
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 3310e3a..fe3ab81 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -84,6 +84,14 @@
#include <config.h>
+/* When PIC is defined and SHARED isn't defined, we are building PIE
+ by default. */
+#if defined PIC && !defined SHARED
+# define BUILD_PIE_DEFAULT 1
+#else
+# define BUILD_PIE_DEFAULT 0
+#endif
+
/* Define this for the benefit of portable GNU code that wants to check it.
Code that checks with #if will not #include <config.h> again, since we've
already done it (and this file is implicitly included in every compile,
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))
diff --git a/sysdeps/unix/sysv/linux/i386/brk.c b/sysdeps/unix/sysv/linux/i386/brk.c
index 25ab101..d67b279 100644
--- a/sysdeps/unix/sysv/linux/i386/brk.c
+++ b/sysdeps/unix/sysv/linux/i386/brk.c
@@ -16,6 +16,11 @@
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
+#if BUILD_PIE_DEFAULT
+/* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE. */
+# define I386_USE_SYSENTER 0
+#endif
+
#include <errno.h>
#include <unistd.h>
#include <sysdep.h>
diff --git a/sysdeps/unix/sysv/linux/i386/startup.h b/sysdeps/unix/sysv/linux/i386/startup.h
new file mode 100644
index 0000000..b73565a
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/i386/startup.h
@@ -0,0 +1,36 @@
+/* Linux/i386 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/>. */
+
+#if BUILD_PIE_DEFAULT
+# include <abort-instr.h>
+
+/* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE. */
+# define I386_USE_SYSENTER 0
+
+__attribute__ ((__noreturn__))
+static inline void
+_startup_fatal (const char *message __attribute__ ((unused)))
+{
+ /* This is only called very early during startup in static PIE.
+ FIXME: How can it be improved? */
+ ABORT_INSTRUCTION;
+ __builtin_unreachable ();
+}
+#else
+# include_next <startup.h>
+#endif