[compiler-rt] [llvm] [sanitizer_common] Add experimental flag to tweak dlopen(<main program>) (PR #71715)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 9 10:54:25 PST 2023
================
@@ -6307,7 +6308,36 @@ INTERCEPTOR(int, fclose, __sanitizer_FILE *fp) {
INTERCEPTOR(void*, dlopen, const char *filename, int flag) {
void *ctx;
COMMON_INTERCEPTOR_ENTER_NOIGNORE(ctx, dlopen, filename, flag);
- if (filename) COMMON_INTERCEPTOR_READ_STRING(ctx, filename, 0);
+
+ if (filename) {
+ COMMON_INTERCEPTOR_READ_STRING(ctx, filename, 0);
+
+# if !SANITIZER_DYNAMIC
+ // We care about a very specific use-case: dladdr on
+ // statically-linked ASan may return <main program>
+ // instead of the library.
+ // We therefore only take effect if the sanitizer is statically
+ // linked, and we don't bother canonicalizing paths because
+ // dladdr should return the same address both times (we assume
+ // the user did not canonicalize the result from dladdr).
+ if (common_flags()->test_only_replace_dlopen_main_program) {
+ VPrintf(1, "dlopen interceptor: filename: %s\n", filename);
+
+ const char *selfFName = dladdrSelfFName();
----------------
vitalybuka wrote:
dladdrSelfFName -> DladdrSelfFName
https://github.com/llvm/llvm-project/pull/71715
More information about the llvm-commits
mailing list