olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1292018-6.patch

00db10
commit b9eb92ab05204df772eb4929eccd018637c9f3e9
00db10
Author: H.J. Lu <hjl.tools@gmail.com>
00db10
Date:   Wed Oct 21 14:44:23 2015 -0700
00db10
00db10
    Add Prefer_MAP_32BIT_EXEC to map executable pages with MAP_32BIT
00db10
    
00db10
    According to Silvermont software optimization guide, for 64-bit
00db10
    applications, branch prediction performance can be negatively impacted
00db10
    when the target of a branch is more than 4GB away from the branch.  Add
00db10
    the Prefer_MAP_32BIT_EXEC bit so that mmap will try to map executable
00db10
    pages with MAP_32BIT first.  NB: MAP_32BIT will map to lower 2GB, not
00db10
    lower 4GB, address.  Prefer_MAP_32BIT_EXEC reduces bits available for
00db10
    address space layout randomization (ASLR), which is always disabled for
00db10
    SUID programs and can only be enabled by setting environment variable,
00db10
    LD_PREFER_MAP_32BIT_EXEC.
00db10
    
00db10
    On Fedora 23, this patch speeds up GCC 5 testsuite by 3% on Silvermont.
00db10
    
00db10
        [BZ #19367]
00db10
        * sysdeps/unix/sysv/linux/wordsize-64/mmap.c: New file.
00db10
        * sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h: Likewise.
00db10
        * sysdeps/unix/sysv/linux/x86_64/64/mmap.c: Likewise.
00db10
        * sysdeps/x86/cpu-features.h (bit_Prefer_MAP_32BIT_EXEC): New.
00db10
        (index_Prefer_MAP_32BIT_EXEC): Likewise.
00db10
00db10
Index: glibc-2.17-c758a686/sysdeps/unix/sysv/linux/wordsize-64/mmap.c
00db10
===================================================================
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/wordsize-64/mmap.c
00db10
@@ -0,0 +1,40 @@
00db10
+/* Linux mmap system call.  64-bit version.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public License as
00db10
+   published by the Free Software Foundation; either version 2.1 of the
00db10
+   License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include <sys/types.h>
00db10
+#include <sys/mman.h>
00db10
+#include <errno.h>
00db10
+#include <sysdep.h>
00db10
+
00db10
+/* An architecture may override this.  */
00db10
+#ifndef MMAP_PREPARE
00db10
+# define MMAP_PREPARE(addr, len, prot, flags, fd, offset)
00db10
+#endif
00db10
+
00db10
+__ptr_t
00db10
+__mmap (__ptr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
00db10
+{
00db10
+  MMAP_PREPARE (addr, len, prot, flags, fd, offset);
00db10
+  return (__ptr_t) INLINE_SYSCALL (mmap, 6, addr, len, prot, flags,
00db10
+				   fd, offset);
00db10
+}
00db10
+
00db10
+weak_alias (__mmap, mmap)
00db10
+weak_alias (__mmap, mmap64)
00db10
+weak_alias (__mmap, __mmap64)
00db10
Index: glibc-2.17-c758a686/sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h
00db10
===================================================================
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/x86_64/64/dl-librecon.h
00db10
@@ -0,0 +1,44 @@
00db10
+/* Optional code to distinguish library flavours.  x86-64 version.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#ifndef _DL_LIBRECON_H
00db10
+
00db10
+#include <sysdeps/unix/sysv/linux/dl-librecon.h>
00db10
+
00db10
+/* Recognizing extra environment variables.  For 64-bit applications,
00db10
+   branch prediction performance may be negatively impacted when the
00db10
+   target of a branch is more than 4GB away from the branch.  Add the
00db10
+   Prefer_MAP_32BIT_EXEC bit so that mmap will try to map executable
00db10
+   pages with MAP_32BIT first.  NB: MAP_32BIT will map to lower 2GB,
00db10
+   not lower 4GB, address.  Prefer_MAP_32BIT_EXEC reduces bits available
00db10
+   for address space layout randomization (ASLR).  Prefer_MAP_32BIT_EXEC
00db10
+   is always disabled for SUID programs and can be enabled by setting
00db10
+   environment variable, LD_PREFER_MAP_32BIT_EXEC.  */
00db10
+#define EXTRA_LD_ENVVARS \
00db10
+  case 21:							      \
00db10
+    if (memcmp (envline, "PREFER_MAP_32BIT_EXEC", 21) == 0)	      \
00db10
+      GLRO(dl_x86_cpu_features).feature[index_Prefer_MAP_32BIT_EXEC]  \
00db10
+	= bit_Prefer_MAP_32BIT_EXEC;				      \
00db10
+    break;
00db10
+
00db10
+/* Extra unsecure variables.  The names are all stuffed in a single
00db10
+   string which means they have to be terminated with a '\0' explicitly.  */
00db10
+#define EXTRA_UNSECURE_ENVVARS \
00db10
+  "LD_PREFER_MAP_32BIT_EXEC\0"
00db10
+
00db10
+#endif /* dl-librecon.h */
00db10
Index: glibc-2.17-c758a686/sysdeps/unix/sysv/linux/x86_64/64/mmap.c
00db10
===================================================================
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/x86_64/64/mmap.c
00db10
@@ -0,0 +1,37 @@
00db10
+/* Linux mmap system call.  x86-64 version.
00db10
+   Copyright (C) 2015 Free Software Foundation, Inc.
00db10
+
00db10
+   This file is part of the GNU C Library.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public License as
00db10
+   published by the Free Software Foundation; either version 2.1 of the
00db10
+   License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include <ldsodefs.h>
00db10
+
00db10
+/* If the Prefer_MAP_32BIT_EXEC bit is set, try to map executable pages
00db10
+   with MAP_32BIT first.  */
00db10
+#define MMAP_PREPARE(addr, len, prot, flags, fd, offset)		\
00db10
+  if ((addr) == NULL							\
00db10
+      && ((prot) & PROT_EXEC) != 0					\
00db10
+      && HAS_ARCH_FEATURE (Prefer_MAP_32BIT_EXEC))			\
00db10
+    {									\
00db10
+      __ptr_t ret = (__ptr_t) INLINE_SYSCALL (mmap, 6, (addr), (len),	\
00db10
+					      (prot),			\
00db10
+					      (flags) | MAP_32BIT,	\
00db10
+					      (fd), (offset));		\
00db10
+      if (ret != MAP_FAILED)						\
00db10
+	return ret;							\
00db10
+    }
00db10
+
00db10
+#include <sysdeps/unix/sysv/linux/wordsize-64/mmap.c>
00db10
Index: glibc-2.17-c758a686/sysdeps/x86/cpu-features.h
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/sysdeps/x86/cpu-features.h
00db10
+++ glibc-2.17-c758a686/sysdeps/x86/cpu-features.h
00db10
@@ -32,6 +32,7 @@
00db10
 #define bit_AVX_Fast_Unaligned_Load	(1 << 11)
00db10
 #define bit_AVX512F_Usable		(1 << 12)
00db10
 #define bit_AVX512DQ_Usable		(1 << 13)
00db10
+#define bit_Prefer_MAP_32BIT_EXEC	(1 << 16)
00db10
 
00db10
 /* CPUID Feature flags.  */
00db10
 
00db10
@@ -91,6 +92,7 @@
00db10
 # define index_AVX_Fast_Unaligned_Load	FEATURE_INDEX_1*FEATURE_SIZE
00db10
 # define index_AVX512F_Usable		FEATURE_INDEX_1*FEATURE_SIZE
00db10
 # define index_AVX512DQ_Usable		FEATURE_INDEX_1*FEATURE_SIZE
00db10
+# define index_Prefer_MAP_32BIT_EXEC	FEATURE_INDEX_1*FEATURE_SIZE
00db10
 
00db10
 # if defined (_LIBC) && !IS_IN (nonlib)
00db10
 #  ifdef __x86_64__
00db10
@@ -267,6 +269,7 @@ extern const struct cpu_features *__get_
00db10
 # define index_AVX_Fast_Unaligned_Load	FEATURE_INDEX_1
00db10
 # define index_AVX512F_Usable		FEATURE_INDEX_1
00db10
 # define index_AVX512DQ_Usable		FEATURE_INDEX_1
00db10
+# define index_Prefer_MAP_32BIT_EXEC	FEATURE_INDEX_1
00db10
 
00db10
 #endif	/* !__ASSEMBLER__ */
00db10