[compiler-rt] [compiler-rt] [sanitizer_common] Add a testcase reproducing SIGSEGV in ForEachMappedRegion (PR #208358)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 8 17:50:31 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Mike Kruskal (mkruskal-google)

<details>
<summary>Changes</summary>

Likely related to https://github.com/llvm/llvm-project/issues/84482 and https://github.com/llvm/llvm-project/issues/21068

Assisted-by: Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/208358.diff


1 Files Affected:

- (added) compiler-rt/test/sanitizer_common/TestCases/Linux/dlopen_image_base.c (+55) 


``````````diff
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Linux/dlopen_image_base.c b/compiler-rt/test/sanitizer_common/TestCases/Linux/dlopen_image_base.c
new file mode 100644
index 0000000000000..c7f7639f4c446
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/Linux/dlopen_image_base.c
@@ -0,0 +1,55 @@
+/* RUN: %clang_msan -g %s -o %t
+   RUN: %clang_msan -g %s -DBUILD_SO -fPIC -o %t-so.so -shared -Wl,--image-base=0x4000000
+   RUN: %run %t 2>&1
+   REQUIRES: lld-available
+   REQUIRES: glibc
+   XFAIL: msan, dfsan
+*/
+
+#ifndef BUILD_SO
+#define _GNU_SOURCE
+#include <assert.h>
+#include <dlfcn.h>
+#include <link.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[]) {
+  char path[4096];
+  snprintf(path, sizeof(path), "%s-so.so", argv[0]);
+
+  void *handle = dlopen(path, RTLD_LAZY);
+  if (!handle) {
+    fprintf(stderr, "dlopen failed: %s\n", dlerror());
+    return 1;
+  }
+
+  struct link_map *map = NULL;
+  dlinfo(handle, RTLD_DI_LINKMAP, &map);
+  if (map) {
+    printf("DSO link_map name: %s\n", map->l_name);
+    printf("DSO link_map l_addr: %p\n", (void*)map->l_addr);
+    int pipefd[2];
+    bool readable = false;
+    if (pipe(pipefd) == 0) {
+      if (write(pipefd[1], (void*)map->l_addr, 1) == 1) {
+        readable = true;
+      }
+      close(pipefd[0]);
+      close(pipefd[1]);
+    }
+    printf("DSO l_addr readable: %d\n", readable);
+  }
+
+  void (*fn)() = (void (*)())dlsym(handle, "fn");
+  assert(fn != NULL);
+  fn();
+
+  dlclose(handle);
+  return 0;
+}
+#else // BUILD_SO
+#include <stdio.h>
+void fn() { printf("DSO function called successfully\n"); }
+#endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/208358


More information about the llvm-commits mailing list