]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Cherry-pick r224315,221379 and r241487 from upstream.
authorMaxim Ostapenko <m.ostapenko@samsung.com>
Tue, 5 Apr 2016 11:52:34 +0000 (11:52 +0000)
committerMaxim Ostapenko <chefmax@gcc.gnu.org>
Tue, 5 Apr 2016 11:52:34 +0000 (14:52 +0300)
libsanitizer/

PR sanitizer/70474
* asan/asan_mac.cc (GetMacosVersionInternal): Cherry pick
upstream r241487, 221379 and r224315.
(void MaybeReexec): Cherry pick upstream r241487.
* asan/asan_mac.h (enum MacosVersion): Cherry pick upstream r224315.

From-SVN: r234744

libsanitizer/ChangeLog
libsanitizer/asan/asan_mac.cc
libsanitizer/asan/asan_mac.h

index 2352e94211cc8bf41d0e7ef9488e441599ef54b4..143dfd4b442bf55238d5b133fec0909c9fce246d 100644 (file)
@@ -1,3 +1,11 @@
+2016-04-05  Maxim Ostapenko  <m.ostapenko@samsung.com>
+
+       PR sanitizer/70474
+       * asan/asan_mac.cc (GetMacosVersionInternal): Cherry pick
+       upstream r241487, 221379 and r224315.
+       (void MaybeReexec): Cherry pick upstream r241487.
+       * asan/asan_mac.h (enum MacosVersion): Cherry pick upstream r224315.
+
 2015-06-26  Release Manager
 
        * GCC 4.9.3 released.
index 8d01843afafb7157e7e5b56614ee25ff50b9e7c6..36e287cdcaa04d560a9ceb5fa9820ec24aedd586 100644 (file)
@@ -70,7 +70,12 @@ MacosVersion GetMacosVersionInternal() {
         case '1': return MACOS_VERSION_LION;
         case '2': return MACOS_VERSION_MOUNTAIN_LION;
         case '3': return MACOS_VERSION_MAVERICKS;
-        default: return MACOS_VERSION_UNKNOWN;
+        case '4': return MACOS_VERSION_YOSEMITE;
+        default:
+          if (IsDigit(version[1]))
+            return MACOS_VERSION_UNKNOWN_NEWER;
+          else
+            return MACOS_VERSION_UNKNOWN;
       }
     }
     default: return MACOS_VERSION_UNKNOWN;
@@ -136,6 +141,23 @@ void LeakyResetEnv(const char *name, const char *name_value) {
   }
 }
 
+bool DyldNeedsEnvVariable() {
+// If running on OS X 10.11+ or iOS 9.0+, dyld will interpose even if
+// DYLD_INSERT_LIBRARIES is not set.
+
+#if SANITIZER_IOSSIM
+  // GetMacosVersion will not work for the simulator, whose kernel version
+  // is tied to the host. Use a weak linking hack for the simulator.
+  // This API was introduced in the same version of the OS as the dyld
+  // optimization.
+
+  // Check for presence of a symbol that is available on OS X 10.11+, iOS 9.0+.
+  return (dlsym(RTLD_NEXT, "mach_memory_info") == nullptr);
+#else
+  return (GetMacosVersion() <= MACOS_VERSION_YOSEMITE);
+#endif
+}
+
 void MaybeReexec() {
   if (!flags()->allow_reexec) return;
   // Make sure the dynamic ASan runtime library is preloaded so that the
@@ -148,8 +170,9 @@ void MaybeReexec() {
   uptr old_env_len = dyld_insert_libraries ?
       internal_strlen(dyld_insert_libraries) : 0;
   uptr fname_len = internal_strlen(info.dli_fname);
-  if (!dyld_insert_libraries ||
-      !REAL(strstr)(dyld_insert_libraries, info.dli_fname)) {
+  bool lib_is_in_env =
+      dyld_insert_libraries && REAL(strstr)(dyld_insert_libraries, info.dli_fname);
+  if (DyldNeedsEnvVariable() && !lib_is_in_env) {
     // DYLD_INSERT_LIBRARIES is not set or does not contain the runtime
     // library.
     char program_name[1024];
@@ -180,6 +203,10 @@ void MaybeReexec() {
     }
     execv(program_name, *_NSGetArgv());
   } else {
+
+    if (!lib_is_in_env)
+      return;
+
     // DYLD_INSERT_LIBRARIES is set and contains the runtime library.
     if (old_env_len == fname_len) {
       // It's just the runtime library name - fine to unset the variable.
index 2d1d4b0bfb33d6e11309659a281763171a89fb1b..efa6eb51fe5b96d20ae5cd6f98a11389f233d499 100644 (file)
@@ -41,7 +41,9 @@ enum MacosVersion {
   MACOS_VERSION_SNOW_LEOPARD,
   MACOS_VERSION_LION,
   MACOS_VERSION_MOUNTAIN_LION,
-  MACOS_VERSION_MAVERICKS
+  MACOS_VERSION_MAVERICKS,
+  MACOS_VERSION_YOSEMITE,
+  MACOS_VERSION_UNKNOWN_NEWER
 };
 
 // Used by asan_malloc_mac.cc and asan_mac.cc