Skip to content

Commit 8eee754

Browse files
committed
[asan] Fix dyld version detection on OS X
We currently have a dyld check in DyldNeedsEnvVariable that detects whether we are on a new OS X (10.11+) where we don't need to re-exec. For iOS simulator, we have a dlsym() hack that checks for a specific symbol, but this turns out to be fragile and problematic, because dlsym can sometimes call malloc(), which is not a good idea this early in the process runtime. Let's instead of this do a direct comparison of dyld's version, which is exported in a public symbol `dyldVersionNumber`. Differential Revision: http://reviews.llvm.org/D11719 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@243879 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 8902445 commit 8eee754

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

lib/asan/asan_mac.cc

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,16 @@ void DisableReexec() {
9999
reexec_disabled = true;
100100
}
101101

102-
bool DyldNeedsEnvVariable() {
103-
// If running on OS X 10.11+ or iOS 9.0+, dyld will interpose even if
104-
// DYLD_INSERT_LIBRARIES is not set.
105-
106-
#if SANITIZER_IOSSIM
107-
// GetMacosVersion will not work for the simulator, whose kernel version
108-
// is tied to the host. Use a weak linking hack for the simulator.
109-
// This API was introduced in the same version of the OS as the dyld
110-
// optimization.
102+
extern "C" double dyldVersionNumber;
103+
static const double kMinDyldVersionWithAutoInterposition = 360.0;
111104

112-
// Check for presence of a symbol that is available on OS X 10.11+, iOS 9.0+.
113-
return (dlsym(RTLD_NEXT, "mach_memory_info") == nullptr);
114-
#else
115-
return (GetMacosVersion() <= MACOS_VERSION_YOSEMITE);
116-
#endif
105+
bool DyldNeedsEnvVariable() {
106+
// If running on OS X 10.11+ or iOS 9.0+, dyld will interpose even if
107+
// DYLD_INSERT_LIBRARIES is not set. However, checking OS version via
108+
// GetMacosVersion() doesn't work for the simulator. Let's instead check
109+
// `dyldVersionNumber`, which is exported by dyld, against a known version
110+
// number from the first OS release where this appeared.
111+
return dyldVersionNumber < kMinDyldVersionWithAutoInterposition;
117112
}
118113

119114
void MaybeReexec() {

0 commit comments

Comments
 (0)