This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch master updated. glibc-2.26-47-g086df22


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 -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;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.

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/unix/sysv/linux/i386/brk.c b/sysdeps/generic/startup.h
similarity index 51%
copy from sysdeps/unix/sysv/linux/i386/brk.c
copy to sysdeps/generic/startup.h
index 25ab101..a961e27 100644
--- a/sysdeps/unix/sysv/linux/i386/brk.c
+++ b/sysdeps/generic/startup.h
@@ -1,5 +1,5 @@
-/* brk system call for Linux/i386.
-   Copyright (C) 1995-2017 Free Software Foundation, Inc.
+/* 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
@@ -16,26 +16,8 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <unistd.h>
-#include <sysdep.h>
+/* Targets should override this file if the default definitions below
+   will not work correctly very early before TLS is initialized.  */
 
-/* This must be initialized data because commons can't have aliases.  */
-void *__curbrk = 0;
-
-/* Old braindamage in GCC's crtstuff.c requires this symbol in an attempt
-   to work around different old braindamage in the old Linux ELF dynamic
-   linker.  */
-weak_alias (__curbrk, ___brk_addr)
-
-int
-__brk (void *addr)
-{
-  INTERNAL_SYSCALL_DECL (err);
-  void *newbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr);
-  __curbrk = newbrk;
-  if (newbrk < addr)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOMEM);
-  return 0;
-}
-weak_alias (__brk, brk)
+/* 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/brk.c b/sysdeps/unix/sysv/linux/i386/startup.h
similarity index 51%
copy from sysdeps/unix/sysv/linux/i386/brk.c
copy to sysdeps/unix/sysv/linux/i386/startup.h
index 25ab101..b73565a 100644
--- a/sysdeps/unix/sysv/linux/i386/brk.c
+++ b/sysdeps/unix/sysv/linux/i386/startup.h
@@ -1,5 +1,5 @@
-/* brk system call for Linux/i386.
-   Copyright (C) 1995-2017 Free Software Foundation, Inc.
+/* 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
@@ -16,26 +16,21 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
-#include <errno.h>
-#include <unistd.h>
-#include <sysdep.h>
+#if BUILD_PIE_DEFAULT
+# include <abort-instr.h>
 
-/* This must be initialized data because commons can't have aliases.  */
-void *__curbrk = 0;
+/* Can't use "call *%gs:SYSINFO_OFFSET" during statup in static PIE.  */
+# define I386_USE_SYSENTER 0
 
-/* Old braindamage in GCC's crtstuff.c requires this symbol in an attempt
-   to work around different old braindamage in the old Linux ELF dynamic
-   linker.  */
-weak_alias (__curbrk, ___brk_addr)
-
-int
-__brk (void *addr)
+__attribute__ ((__noreturn__))
+static inline void
+_startup_fatal (const char *message __attribute__ ((unused)))
 {
-  INTERNAL_SYSCALL_DECL (err);
-  void *newbrk = (void *) INTERNAL_SYSCALL (brk, err, 1, addr);
-  __curbrk = newbrk;
-  if (newbrk < addr)
-    return INLINE_SYSCALL_ERROR_RETURN_VALUE (ENOMEM);
-  return 0;
+  /* This is only called very early during startup in static PIE.
+     FIXME: How can it be improved?  */
+  ABORT_INSTRUCTION;
+  __builtin_unreachable ();
 }
-weak_alias (__brk, brk)
+#else
+# include_next <startup.h>
+#endif

-----------------------------------------------------------------------

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%)


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]