diff options
author | Alexander Potapenko <glider@google.com> | 2013-02-13 17:52:55 +0000 |
---|---|---|
committer | Alexander Potapenko <glider@google.com> | 2013-02-13 17:52:55 +0000 |
commit | eb5f427c10c5d23e520def5f921cbbed831526be (patch) | |
tree | 97a71e8119728ddae7f504ab1b43474fccb3851a /lib/asan/asan_mac.cc | |
parent | eaa0190fc9a510a621d871becce0536950c5468d (diff) | |
download | compiler-rt-eb5f427c10c5d23e520def5f921cbbed831526be.tar.gz compiler-rt-eb5f427c10c5d23e520def5f921cbbed831526be.tar.bz2 compiler-rt-eb5f427c10c5d23e520def5f921cbbed831526be.tar.xz |
[ASan] When re-executing the process on OS X, make sure we update the existing DYLD_INSERT_LIBRARIES correctly.
Previously ASan used to hang in an exec loop, because it failed to overwrite the env var value
(see https://code.google.com/p/address-sanitizer/issues/detail?id=159).
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@175059 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_mac.cc')
-rw-r--r-- | lib/asan/asan_mac.cc | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/asan/asan_mac.cc b/lib/asan/asan_mac.cc index f6f6b146..8a0cb9eb 100644 --- a/lib/asan/asan_mac.cc +++ b/lib/asan/asan_mac.cc @@ -106,7 +106,23 @@ void MaybeReexec() { _NSGetExecutablePath(program_name, &buf_size); // Ok to use setenv() since the wrappers don't depend on the value of // asan_inited. - setenv(kDyldInsertLibraries, info.dli_fname, /*overwrite*/0); + if (dyld_insert_libraries) { + // Append the runtime dylib name to the existing value of + // DYLD_INSERT_LIBRARIES. + uptr old_env_len = internal_strlen(dyld_insert_libraries); + uptr fname_len = internal_strlen(info.dli_fname); + LowLevelAllocator allocator_for_env; + char *new_env = + (char*)allocator_for_env.Allocate(old_env_len + fname_len + 2); + internal_strncpy(new_env, dyld_insert_libraries, old_env_len); + new_env[old_env_len] = ':'; + // Copy fname_len and add a trailing zero. + internal_strncpy(new_env + old_env_len + 1, info.dli_fname, fname_len + 1); + setenv(kDyldInsertLibraries, new_env, /*overwrite*/1); + } else { + // Set DYLD_INSERT_LIBRARIES equal to the runtime dylib name. + setenv(kDyldInsertLibraries, info.dli_fname, /*overwrite*/0); + } if (flags()->verbosity >= 1) { Report("exec()-ing the program with\n"); Report("%s=%s\n", kDyldInsertLibraries, info.dli_fname); |