diff options
author | Dan Liew <dan@su-root.co.uk> | 2018-12-01 15:45:42 +0000 |
---|---|---|
committer | Dan Liew <dan@su-root.co.uk> | 2018-12-01 15:45:42 +0000 |
commit | 8bffb634970ce0ffc1f979d8399f1d415f60a688 (patch) | |
tree | 21f679659008fce03b030efc7222a23f8d137a90 /compiler-rt/lib/asan/asan_malloc_mac.cc | |
parent | 102854f4d403f22af10bd521a381adbd49f350a5 (diff) | |
download | bcm5719-llvm-8bffb634970ce0ffc1f979d8399f1d415f60a688.tar.gz bcm5719-llvm-8bffb634970ce0ffc1f979d8399f1d415f60a688.zip |
Introduce a way to allow the ASan dylib on Darwin platforms to be loaded via `dlopen()`.
Summary:
The purpose of this option is provide a way for the ASan dylib
to be loaded via `dlopen()` without triggering most initialization
steps (e.g. shadow memory set up) that normally occur when the
ASan dylib is loaded.
This new functionality is exposed by
- A `SANITIZER_SUPPORTS_INIT_FOR_DLOPEN` macro which indicates if the
feature is supported. This only true for Darwin currently.
- A `HandleDlopenInit()` function which should return true if the library
is being loaded via `dlopen()` and
`SANITIZER_SUPPORTS_INIT_FOR_DLOPEN` is supported. Platforms that
support this may perform any initialization they wish inside this
function.
Although disabling initialization is something that could potentially
apply to other sanitizers it appears to be unnecessary for other
sanitizers so this patch only makes the change for ASan.
rdar://problem/45284065
Reviewers: kubamracek, george.karpenkov, kcc, eugenis, krytarowski
Subscribers: #sanitizers, llvm-commits
Differential Revision: https://reviews.llvm.org/D54469
llvm-svn: 348078
Diffstat (limited to 'compiler-rt/lib/asan/asan_malloc_mac.cc')
-rw-r--r-- | compiler-rt/lib/asan/asan_malloc_mac.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/compiler-rt/lib/asan/asan_malloc_mac.cc b/compiler-rt/lib/asan/asan_malloc_mac.cc index 733ba2d86e1..27281f1bc83 100644 --- a/compiler-rt/lib/asan/asan_malloc_mac.cc +++ b/compiler-rt/lib/asan/asan_malloc_mac.cc @@ -61,4 +61,25 @@ using namespace __asan; #include "sanitizer_common/sanitizer_malloc_mac.inc" +namespace COMMON_MALLOC_NAMESPACE { +bool HandleDlopenInit() { + static_assert(SANITIZER_SUPPORTS_INIT_FOR_DLOPEN, + "Expected SANITIZER_SUPPORTS_INIT_FOR_DLOPEN to be true"); + // We have no reliable way of knowing how we are being loaded + // so make it a requirement on Apple platforms to set this environment + // variable to indicate that we want to perform initialization via + // dlopen(). + auto init_str = GetEnv("APPLE_ASAN_INIT_FOR_DLOPEN"); + if (!init_str) + return false; + if (internal_strncmp(init_str, "1", 1) != 0) + return false; + // When we are loaded via `dlopen()` path we still initialize the malloc zone + // so Symbolication clients (e.g. `leaks`) that load the ASan allocator can + // find an initialized malloc zone. + InitMallocZoneFields(); + return true; +} +} // namespace COMMON_MALLOC_NAMESPACE + #endif |