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