]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR sanitizer/84761 (AddressSanitizer is not compatible with glibc 2...
authorRichard Biener <rguenther@suse.de>
Mon, 15 Oct 2018 13:43:09 +0000 (13:43 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 15 Oct 2018 13:43:09 +0000 (13:43 +0000)
2018-10-15  Richard Biener  <rguenther@suse.de>

Backport from mainline
2018-03-19  Jakub Jelinek  <jakub@redhat.com>

PR sanitizer/84761
* sanitizer_common/sanitizer_linux_libcdep.cc (__GLIBC_PREREQ):
Define if not defined.
(DL_INTERNAL_FUNCTION): Don't define.
(InitTlsSize): For __i386__ if not compiled against glibc 2.27+
determine at runtime whether to use regparm(3), stdcall calling
convention for older glibcs or normal calling convention for
newer glibcs for call to _dl_get_tls_static_info.

From-SVN: r265164

libsanitizer/ChangeLog
libsanitizer/sanitizer_common/sanitizer_linux_libcdep.cc

index ae4f170dc418bd5b93639084028500324f337b58..40e8b6de966b6620b53934d08b7568d0b40e6701 100644 (file)
@@ -1,3 +1,17 @@
+2018-10-15  Richard Biener  <rguenther@suse.de>
+
+       Backport from mainline
+       2018-03-19  Jakub Jelinek  <jakub@redhat.com>
+
+       PR sanitizer/84761
+       * sanitizer_common/sanitizer_linux_libcdep.cc (__GLIBC_PREREQ):
+       Define if not defined.
+       (DL_INTERNAL_FUNCTION): Don't define.
+       (InitTlsSize): For __i386__ if not compiled against glibc 2.27+
+       determine at runtime whether to use regparm(3), stdcall calling
+       convention for older glibcs or normal calling convention for
+       newer glibcs for call to _dl_get_tls_static_info.
+
 2017-09-23  Matthias Klose  <doko@ubuntu.com>
 
        Backported from the gcc-7-branch:
index ff69664e7b9912eb0fd95878504b6a3e34be389f..5fb75d638b8a7ccf9e91858bde722168654e04a5 100644 (file)
@@ -154,14 +154,12 @@ bool SanitizerGetThreadName(char *name, int max_len) {
 #endif
 }
 
-#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
-static uptr g_tls_size;
+#ifndef __GLIBC_PREREQ
+#define __GLIBC_PREREQ(x, y) 0
 #endif
 
-#ifdef __i386__
-# define DL_INTERNAL_FUNCTION __attribute__((regparm(3), stdcall))
-#else
-# define DL_INTERNAL_FUNCTION
+#if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
+static uptr g_tls_size;
 #endif
 
 #if defined(__mips__) || defined(__powerpc64__)
@@ -186,16 +184,33 @@ void InitTlsSize() {
 #if !SANITIZER_FREEBSD && !SANITIZER_ANDROID && !SANITIZER_GO
 // all current supported platforms have 16 bytes stack alignment
   const size_t kStackAlign = 16;
-  typedef void (*get_tls_func)(size_t*, size_t*) DL_INTERNAL_FUNCTION;
-  get_tls_func get_tls;
-  void *get_tls_static_info_ptr = dlsym(RTLD_NEXT, "_dl_get_tls_static_info");
-  CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
-  internal_memcpy(&get_tls, &get_tls_static_info_ptr,
-                  sizeof(get_tls_static_info_ptr));
-  CHECK_NE(get_tls, 0);
   size_t tls_size = 0;
   size_t tls_align = 0;
-  get_tls(&tls_size, &tls_align);
+  void *get_tls_static_info_ptr = dlsym(RTLD_NEXT, "_dl_get_tls_static_info");
+#if defined(__i386__) && !__GLIBC_PREREQ(2, 27)
+  /* On i?86, _dl_get_tls_static_info used to be internal_function, i.e.
+     __attribute__((regparm(3), stdcall)) before glibc 2.27 and is normal
+     function in 2.27 and later.  */
+  if (!dlvsym(RTLD_NEXT, "glob", "GLIBC_2.27")) {
+    typedef void (*get_tls_func)(size_t*, size_t*)
+      __attribute__((regparm(3), stdcall));
+    get_tls_func get_tls;
+    CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
+    internal_memcpy(&get_tls, &get_tls_static_info_ptr,
+                    sizeof(get_tls_static_info_ptr));
+    CHECK_NE(get_tls, 0);
+    get_tls(&tls_size, &tls_align);
+  } else
+#endif
+  {
+    typedef void (*get_tls_func)(size_t*, size_t*);
+    get_tls_func get_tls;
+    CHECK_EQ(sizeof(get_tls), sizeof(get_tls_static_info_ptr));
+    internal_memcpy(&get_tls, &get_tls_static_info_ptr,
+                    sizeof(get_tls_static_info_ptr));
+    CHECK_NE(get_tls, 0);
+    get_tls(&tls_size, &tls_align);
+  }
   if (tls_align < kStackAlign)
     tls_align = kStackAlign;
   g_tls_size = RoundUpTo(tls_size, tls_align);