[llvm-branch-commits] [compiler-rt] release/19.x: [test][compiler-rt] Mark dlsym_alloc.c as unsupported on macos (#108439) (PR #121100)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Dec 25 01:34:13 PST 2024


https://github.com/llvmbot created https://github.com/llvm/llvm-project/pull/121100

Backport 1797174ea6adab08474658f9c9748991d172321c ae0ed3d58600da9ec266bf86d0084775f561ba3a d9ed8b018df725faec4076a3efdfcbd7a24c99f0

Requested by: @nikic

>From 3486581b10a421da8037c366c89f08a30482f2ad Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 11 Sep 2024 14:44:06 -0700
Subject: [PATCH 1/3] [NFC][sanitizer] Commit test for #106912 (#108289)

Almost all sanitizers already support the test.
* Tsan does not use DlsymAlloc yet.
* Lsan will support with #106912.

memprof,rtsan,nsan are not tested as part of
sanitizer_common, but we should keep them here to
show up when it happen.

---------

Co-authored-by: Xiaofeng Tian <110771974+txff99 at users.noreply.github.com>
(cherry picked from commit 1797174ea6adab08474658f9c9748991d172321c)
---
 .../sanitizer_common/TestCases/dlsym_alloc.c  | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c

diff --git a/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
new file mode 100644
index 00000000000000..3905ac40ae2dc7
--- /dev/null
+++ b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
@@ -0,0 +1,61 @@
+// RUN: %clang -O0 %s -o %t && %run %t
+
+// FIXME: TSAN does not use DlsymAlloc.
+// UNSUPPORTED: tsan
+
+// FIXME: https://github.com/llvm/llvm-project/pull/106912
+// XFAIL: lsan
+
+#include <stdlib.h>
+
+const char *test() __attribute__((disable_sanitizer_instrumentation)) {
+  void *volatile p = malloc(3);
+  p = realloc(p, 7);
+  free(p);
+
+  p = calloc(3, 7);
+  free(p);
+
+  free(NULL);
+
+  return "";
+}
+
+const char *__asan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__hwasan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__lsan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__memprof_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__msan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__nsan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__rtsan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__tsan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+const char *__ubsan_default_options()
+    __attribute__((disable_sanitizer_instrumentation)) {
+  return test();
+}
+
+int main(int argc, char **argv) { return 0; }

>From 774cf1c976b9865e2380170dbebfd327b1ebf6d3 Mon Sep 17 00:00:00 2001
From: tmiasko <tomasz.miasko at gmail.com>
Date: Thu, 12 Sep 2024 00:37:02 +0200
Subject: [PATCH 2/3] [lsan] Fix free(NULL) interception during initialization
 (#106912)

Previously an attempt to free a null pointer during initialization would
fail on ENSURE_LSAN_INITED assertion (since a null pointer is not owned
by DlsymAlloc).

(cherry picked from commit ae0ed3d58600da9ec266bf86d0084775f561ba3a)
---
 compiler-rt/lib/lsan/lsan_interceptors.cpp                | 2 ++
 compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c | 3 ---
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/lsan/lsan_interceptors.cpp b/compiler-rt/lib/lsan/lsan_interceptors.cpp
index b569c337e97641..efbf2fdfb0ab3f 100644
--- a/compiler-rt/lib/lsan/lsan_interceptors.cpp
+++ b/compiler-rt/lib/lsan/lsan_interceptors.cpp
@@ -77,6 +77,8 @@ INTERCEPTOR(void*, malloc, uptr size) {
 }
 
 INTERCEPTOR(void, free, void *p) {
+  if (UNLIKELY(!p))
+    return;
   if (DlsymAlloc::PointerIsMine(p))
     return DlsymAlloc::Free(p);
   ENSURE_LSAN_INITED;
diff --git a/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
index 3905ac40ae2dc7..0228c3bc50dbd9 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
@@ -3,9 +3,6 @@
 // FIXME: TSAN does not use DlsymAlloc.
 // UNSUPPORTED: tsan
 
-// FIXME: https://github.com/llvm/llvm-project/pull/106912
-// XFAIL: lsan
-
 #include <stdlib.h>
 
 const char *test() __attribute__((disable_sanitizer_instrumentation)) {

>From e502f0f2bb15f408f745d2573f4f22fb2cda7bfe Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Thu, 12 Sep 2024 20:52:24 -0700
Subject: [PATCH 3/3] [test][compiler-rt] Mark dlsym_alloc.c as unsupported on
 macos (#108439)

With #106912, the test now fails on macos, e.g.

https://green.lab.llvm.org/job/llvm.org/job/clang-stage1-RA/2058/.
(cherry picked from commit d9ed8b018df725faec4076a3efdfcbd7a24c99f0)
---
 compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
index 0228c3bc50dbd9..7b5b9cf34a90f9 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/dlsym_alloc.c
@@ -2,6 +2,8 @@
 
 // FIXME: TSAN does not use DlsymAlloc.
 // UNSUPPORTED: tsan
+// FIXME: investigate why this fails on macos
+// UNSUPPORTED: darwin
 
 #include <stdlib.h>
 



More information about the llvm-branch-commits mailing list