00db10
Index: glibc-2.17-c758a686/elf/rtld.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/elf/rtld.c
00db10
+++ glibc-2.17-c758a686/elf/rtld.c
00db10
@@ -2478,6 +2478,11 @@ process_envvars (enum mode *modep)
00db10
   GLRO(dl_profile_output)
00db10
     = &"/var/tmp\0/var/profile"[INTUSE(__libc_enable_secure) ? 9 : 0];
00db10
 
00db10
+  /* RHEL 7 specific change:
00db10
+     Without the tunables farmework we simulate tunables only for
00db10
+     use with enabling transactional memory.  */
00db10
+  _dl_process_tunable_env_entries ();
00db10
+
00db10
   while ((envline = _dl_next_ld_env_entry (&runp)) != NULL)
00db10
     {
00db10
       size_t len = 0;
00db10
Index: glibc-2.17-c758a686/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c
00db10
+++ glibc-2.17-c758a686/nptl/sysdeps/unix/sysv/linux/x86/elision-conf.c
00db10
@@ -68,8 +68,18 @@ elision_init (int argc __attribute__ ((u
00db10
 {
00db10
   int elision_available = HAS_CPU_FEATURE (RTM);
00db10
 #ifdef ENABLE_LOCK_ELISION
00db10
-  __pthread_force_elision = __libc_enable_secure ? 0 : elision_available;
00db10
-  __rwlock_rtm_enabled = __libc_enable_secure ? 0 : elision_available;
00db10
+  if (!__libc_enable_secure && elision_available)
00db10
+    {
00db10
+      /* RHEL 7 specific change: Check if elision is enabled for the
00db10
+	 process.  */
00db10
+      __pthread_force_elision = GLRO(dl_elision_enabled);
00db10
+      __rwlock_rtm_enabled = GLRO(dl_elision_enabled);
00db10
+    }
00db10
+  else
00db10
+    {
00db10
+      __pthread_force_elision = 0;
00db10
+      __rwlock_rtm_enabled = 0;
00db10
+    }
00db10
 #endif
00db10
 }
00db10
 
00db10
Index: glibc-2.17-c758a686/sysdeps/generic/ldsodefs.h
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/sysdeps/generic/ldsodefs.h
00db10
+++ glibc-2.17-c758a686/sysdeps/generic/ldsodefs.h
00db10
@@ -557,6 +557,9 @@ struct rtld_global_ro
00db10
      platforms.  */
00db10
   EXTERN uint64_t _dl_hwcap2;
00db10
 
00db10
+  /* RHEL 7 specific change: Is elision enabled for this process?  */
00db10
+  EXTERN bool _dl_elision_enabled;
00db10
+
00db10
 #ifdef SHARED
00db10
   /* We add a function table to _rtld_global which is then used to
00db10
      call the function instead of going through the PLT.  The result
00db10
@@ -893,6 +896,10 @@ extern void _dl_show_auxv (void) interna
00db10
    other.  */
00db10
 extern char *_dl_next_ld_env_entry (char ***position) internal_function;
00db10
 
00db10
+/* RHEL 7 specific change:
00db10
+   Manually process RHEL 7-specific tunable entries.  */
00db10
+extern void _dl_process_tunable_env_entries (void) internal_function;
00db10
+
00db10
 /* Return an array with the names of the important hardware capabilities.  */
00db10
 extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
00db10
 							size_t paltform_len,
00db10
Index: glibc-2.17-c758a686/elf/dl-support.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/elf/dl-support.c
00db10
+++ glibc-2.17-c758a686/elf/dl-support.c
00db10
@@ -123,6 +123,10 @@ size_t _dl_phnum;
00db10
 uint64_t _dl_hwcap __attribute__ ((nocommon));
00db10
 uint64_t _dl_hwcap2 __attribute__ ((nocommon));
00db10
 
00db10
+/* RHEL 7-specific change: Is elision enabled for the process?
00db10
+   Static library definition.  */
00db10
+bool _dl_elision_enabled;
00db10
+
00db10
 /* This is not initialized to HWCAP_IMPORTANT, matching the definition
00db10
    of _dl_important_hwcaps, below, where no hwcap strings are ever
00db10
    used.  This mask is still used to mediate the lookups in the cache
00db10
@@ -289,6 +293,9 @@ _dl_non_dynamic_init (void)
00db10
     _dl_profile_output
00db10
       = &"/var/tmp\0/var/profile"[__libc_enable_secure ? 9 : 0];
00db10
 
00db10
+  /* RHEL 7 specific change: Process tunables at startup.  */
00db10
+  _dl_process_tunable_env_entries ();
00db10
+
00db10
   if (__libc_enable_secure)
00db10
     {
00db10
       static const char unsecure_envvars[] =
00db10
Index: glibc-2.17-c758a686/sysdeps/x86_64/multiarch/strstr-c.c
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/sysdeps/x86_64/multiarch/strstr-c.c
00db10
+++ glibc-2.17-c758a686/sysdeps/x86_64/multiarch/strstr-c.c
00db10
@@ -17,6 +17,10 @@
00db10
    License along with the GNU C Library; if not, see
00db10
    <http://www.gnu.org/licenses/>.  */
00db10
 
00db10
+/* RHEL 7-specific: Define multiple versions only for the definition in
00db10
+   libc.  Don't define multiple versions for strstr in static library
00db10
+   since we need strstr before initialization has happened.  */
00db10
+#if defined SHARED && IS_IN (libc)
00db10
 /* Redefine strstr so that the compiler won't complain about the type
00db10
    mismatch with the IFUNC selector in strong_alias, below.  */
00db10
 #undef  strstr
00db10
@@ -30,9 +34,11 @@
00db10
 # define libc_hidden_builtin_def(name) \
00db10
   __hidden_ver1 (__strstr_sse2, __GI_strstr, __strstr_sse2);
00db10
 #endif
00db10
+#endif
00db10
 
00db10
 #include "string/strstr.c"
00db10
 
00db10
+#if defined SHARED && IS_IN (libc)
00db10
 extern __typeof (__redirect_strstr) __strstr_sse42 attribute_hidden;
00db10
 extern __typeof (__redirect_strstr) __strstr_sse2_unaligned attribute_hidden;
00db10
 extern __typeof (__redirect_strstr) __strstr_sse2 attribute_hidden;
00db10
@@ -48,3 +54,5 @@ libc_ifunc (__libc_strstr, HAS_CPU_FEATU
00db10
 
00db10
 #undef strstr
00db10
 strong_alias (__libc_strstr, strstr)
00db10
+#endif
00db10
+
00db10
Index: glibc-2.17-c758a686/elf/Makefile
00db10
===================================================================
00db10
--- glibc-2.17-c758a686.orig/elf/Makefile
00db10
+++ glibc-2.17-c758a686/elf/Makefile
00db10
@@ -35,6 +35,10 @@ dl-routines	= $(addprefix dl-,load looku
00db10
 ifeq (yes,$(use-ldconfig))
00db10
 dl-routines += dl-cache
00db10
 endif
00db10
+
00db10
+# RHEL 7-specific change: Add rudimentary tunables support.
00db10
+dl-routines += dl-tunables
00db10
+
00db10
 all-dl-routines = $(dl-routines) $(sysdep-dl-routines)
00db10
 # But they are absent from the shared libc, because that code is in ld.so.
00db10
 elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
00db10
Index: glibc-2.17-c758a686/elf/dl-tunables.c
00db10
===================================================================
00db10
--- /dev/null
00db10
+++ glibc-2.17-c758a686/elf/dl-tunables.c
00db10
@@ -0,0 +1,60 @@
00db10
+/* RHEL 7-specific rudimentary tunables handling.
00db10
+   Copyright (C) 2017 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
+#include <string.h>
00db10
+#include <unistd.h>
00db10
+#include <ldsodefs.h>
00db10
+#include <elision-conf.h>
00db10
+
00db10
+/* RHEL 7 specific change:
00db10
+   Manually process RHEL 7-specific tunable entries.  */
00db10
+void
00db10
+internal_function
00db10
+_dl_process_tunable_env_entries (void)
00db10
+{
00db10
+#if HAVE_ELISION
00db10
+  char **ep;
00db10
+  const char *envname = { "RHEL_GLIBC_TUNABLES" };
00db10
+# define TUNABLE_ELISION 0
00db10
+# define TUNABLE_MAX 1
00db10
+  const char *tunables[TUNABLE_MAX] = { "glibc.elision.enable=1" };
00db10
+
00db10
+  ep = __environ;
00db10
+  while (*ep != NULL)
00db10
+    {
00db10
+      size_t cnt = 0;
00db10
+
00db10
+      while ((*ep)[cnt] == envname[cnt] && envname[cnt] != '\0')
00db10
+        ++cnt;
00db10
+
00db10
+      if (envname[cnt] == '\0' && (*ep)[cnt] == '=')
00db10
+        {
00db10
+          /* Found it.  */
00db10
+          char *found;
00db10
+          found = strstr (*ep, tunables[TUNABLE_ELISION]);
00db10
+          /* Process TUNABLE_ELISION:
00db10
+             Note: elision-conf.c applies security checks.  */
00db10
+          if (found != NULL)
00db10
+	    GLRO(dl_elision_enabled) = true;
00db10
+          /* Continue the loop in case NAME appears again.  */
00db10
+        }
00db10
+
00db10
+      ++ep;
00db10
+    }
00db10
+#endif
00db10
+}