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