Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a way to allow the ASan dylib on Darwin platforms to be loa…
…ded 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
- Loading branch information
Showing
10 changed files
with
117 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// RUN: %clangxx -g -O0 %s -o %t | ||
|
||
// Check that trying to dlopen() the ASan dylib fails. | ||
// We explictly set `abort_on_error=0` because | ||
// - By default the lit config sets this but we don't want this | ||
// test to implicitly depend on this. | ||
// - It avoids requiring `--crash` to be passed to `not`. | ||
// RUN: APPLE_ASAN_INIT_FOR_DLOPEN=0 %env_asan_opts=abort_on_error=0 not \ | ||
// RUN: %run %t %shared_libasan 2>&1 | \ | ||
// RUN: FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s | ||
// RUN: env -u APPLE_ASAN_INIT_FOR_DLOPEN %env_asan_opts=abort_on_error=0 not \ | ||
// RUN: %run %t %shared_libasan 2>&1 | \ | ||
// RUN: FileCheck -check-prefix=CHECK-DL-OPEN-FAIL %s | ||
|
||
// Check that we can successfully dlopen the ASan dylib when we set the right | ||
// environment variable. | ||
// RUN: env APPLE_ASAN_INIT_FOR_DLOPEN=1 %run %t %shared_libasan 2>&1 | \ | ||
// RUN: FileCheck -check-prefix=CHECK-DL-OPEN-SUCCESS %s | ||
|
||
#include <dlfcn.h> | ||
#include <stdio.h> | ||
|
||
// CHECK-DL-OPEN-FAIL: ERROR: Interceptors are not working | ||
|
||
int main(int argc, char **argv) { | ||
if (argc != 2) { | ||
fprintf(stderr, "Usage: %s <dylib_path>\n", argv[0]); | ||
return 1; | ||
} | ||
const char *dylib_path = argv[1]; | ||
void *handle = dlopen(dylib_path, RTLD_LAZY); | ||
if (!handle) { | ||
fprintf(stderr, "Failed to dlopen: %s\n", dlerror()); | ||
return 1; | ||
} | ||
// Make sure we can find a function we expect to be in the dylib. | ||
void *fn = dlsym(handle, "__sanitizer_mz_size"); | ||
if (!fn) { | ||
fprintf(stderr, "Failed to get symbol: %s\n", dlerror()); | ||
return 1; | ||
} | ||
// TODO(dliew): Actually call a function from the dylib that is safe to call. | ||
// CHECK-DL-OPEN-SUCCESS: DONE | ||
printf("DONE\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters