[compiler-rt] [ASan] Make most tests run under internal shell on Darwin (PR #168545)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 18 07:43:42 PST 2025
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/168545
>From 498eb04080625d011824b68f13e6124ff49acd59 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Tue, 18 Nov 2025 14:30:20 +0000
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
[skip ci]
---
compiler-rt/test/lit.common.cfg.py | 5 ++++-
compiler-rt/test/tsan/Darwin/dlopen.cpp | 7 ++++---
.../test/tsan/Darwin/external-ignore-noninstrumented.cpp | 6 ++++--
compiler-rt/test/tsan/Darwin/external.cpp | 9 ++++++---
compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp | 2 +-
compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp | 3 +++
6 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 3f7dd8e402b78..ea22fb0babc46 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -875,7 +875,7 @@ def is_windows_lto_supported():
config.substitutions.append(
(
"%ld_flags_rpath_so" + postfix,
- "-install_name @rpath/`basename %dynamiclib{}`".format(postfix),
+ "-install_name @rpath/%base_dynamiclib{}".format(postfix),
)
)
elif config.target_os in ("FreeBSD", "NetBSD", "OpenBSD"):
@@ -908,6 +908,9 @@ def is_windows_lto_supported():
config.substitutions.append(
("%dynamiclib" + postfix, "%t.dir/%xdynamiclib_filename" + postfix)
)
+ config.substitutions.append(
+ ("%base_dynamiclib" + postfix, "%xdynamiclib_filename" + postfix)
+ )
config.substitutions.append(
(
"%xdynamiclib_filename" + postfix,
diff --git a/compiler-rt/test/tsan/Darwin/dlopen.cpp b/compiler-rt/test/tsan/Darwin/dlopen.cpp
index 3d12b815f9c25..2ab052f1c0c26 100644
--- a/compiler-rt/test/tsan/Darwin/dlopen.cpp
+++ b/compiler-rt/test/tsan/Darwin/dlopen.cpp
@@ -9,14 +9,15 @@
// RUN: %clangxx_tsan %s -o %t.so -shared -DSHARED_LIB
// RUN: %clangxx_tsan -fno-sanitize=thread %s -o %t
-// RUN: TSAN_DYLIB_PATH=`%clangxx_tsan %s -### 2>&1 \
+// RUN: %clangxx_tsan %s -### 2>&1 \
// RUN: | grep "libclang_rt.tsan_osx_dynamic.dylib" \
-// RUN: | sed -e 's/.*"\(.*libclang_rt.tsan_osx_dynamic.dylib\)".*/\1/'`
+// RUN: | sed -e 's/.*"\(.*libclang_rt.tsan_osx_dynamic.dylib\)".*/\1/' \
+// RUN: | tr -d '\n' > %t.tsan_dylib_path
// Launching a non-instrumented binary that dlopen's an instrumented library should fail.
// RUN: not %run %t %t.so 2>&1 | FileCheck %s --check-prefix=CHECK-FAIL
// Launching a non-instrumented binary with an explicit DYLD_INSERT_LIBRARIES should work.
-// RUN: DYLD_INSERT_LIBRARIES=$TSAN_DYLIB_PATH %run %t %t.so 2>&1 | FileCheck %s
+// RUN: env DYLD_INSERT_LIBRARIES="%{readfile:%t.tsan_dylib_path}" %run %t %t.so 2>&1 | FileCheck %s
#include <dlfcn.h>
#include <pthread.h>
diff --git a/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp b/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp
index 916b0b893fc0d..cfa46e0f0a213 100644
--- a/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp
+++ b/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp
@@ -1,8 +1,10 @@
+// RUN: basename %t-lib.dylib | tr -d '\n' > %t.basename
// RUN: %clangxx_tsan -shared %p/external-lib.cpp -fno-sanitize=thread -DUSE_TSAN_CALLBACKS \
-// RUN: -o %t-lib.dylib -install_name @rpath/`basename %t-lib.dylib`
+// RUN: -o %t-lib.dylib -install_name @rpath/%{readfile:%t.basename}
+// RUN: basename %t-module.dylib | tr -d '\n' > %t.basename
// RUN: %clangxx_tsan -shared %p/external-noninstrumented-module.cpp %t-lib.dylib -fno-sanitize=thread \
-// RUN: -o %t-module.dylib -install_name @rpath/`basename %t-module.dylib`
+// RUN: -o %t-module.dylib -install_name @rpath/%{readfile:%t.basename}
// RUN: %clangxx_tsan %s %t-module.dylib -o %t
// RUN: %run %t 2>&1 | FileCheck %s
diff --git a/compiler-rt/test/tsan/Darwin/external.cpp b/compiler-rt/test/tsan/Darwin/external.cpp
index bf189eb1d6b5b..52fae36f0e1f4 100644
--- a/compiler-rt/test/tsan/Darwin/external.cpp
+++ b/compiler-rt/test/tsan/Darwin/external.cpp
@@ -1,14 +1,17 @@
+// RUN: basename %t-lib-instrumented.dylib | tr -d '\n' > %t.basename
// RUN: %clangxx_tsan %p/external-lib.cpp -shared \
// RUN: -o %t-lib-instrumented.dylib \
-// RUN: -install_name @rpath/`basename %t-lib-instrumented.dylib`
+// RUN: -install_name @rpath/%{readfile:%t.basename}
+// RUN: basename %t-lib-noninstrumented.dylib | tr -d '\n' > %t.basename
// RUN: %clangxx_tsan %p/external-lib.cpp -shared -fno-sanitize=thread \
// RUN: -o %t-lib-noninstrumented.dylib \
-// RUN: -install_name @rpath/`basename %t-lib-noninstrumented.dylib`
+// RUN: -install_name @rpath/%{readfile:%t.basename}
+// RUN: basename %t-lib-noninstrumented-callbacks.dylib | tr -d '\n' > %t.basename
// RUN: %clangxx_tsan %p/external-lib.cpp -shared -fno-sanitize=thread -DUSE_TSAN_CALLBACKS \
// RUN: -o %t-lib-noninstrumented-callbacks.dylib \
-// RUN: -install_name @rpath/`basename %t-lib-noninstrumented-callbacks.dylib`
+// RUN: -install_name @rpath/%{readfile:%t.basename}
// RUN: %clangxx_tsan %s %t-lib-instrumented.dylib -o %t-lib-instrumented
// RUN: %clangxx_tsan %s %t-lib-noninstrumented.dylib -o %t-lib-noninstrumented
diff --git a/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp b/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp
index 8d9c2122d0e6c..0a96e346f8012 100644
--- a/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp
+++ b/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp
@@ -4,7 +4,7 @@
// use syscalls directly) to make sure other interceptors aren't called.
// RUN: %clangxx_tsan -O1 %s -o %t
-// RUN: MallocStackLogging=1 %run %t 2>&1 | FileCheck %s
+// RUN: env MallocStackLogging=1 %run %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
diff --git a/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp b/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
index 7c6c7715d07dd..b36aa1db7aa76 100644
--- a/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
+++ b/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
@@ -1,4 +1,7 @@
// RUN: mkdir -p %t.dir && cd %t.dir
+// RUN: basename %dynamiclib > /tmp/test
+// RUN: echo %dynamiclib >> /tmp/test
+// RUN: echo %t >> /tmp/test
// RUN: %clang_tsan -O1 %s -DBUILD_LIB=1 -fno-sanitize=thread -shared -fPIC -o %dynamiclib %ld_flags_rpath_so
// RUN: %clang_tsan -O1 %s -o %t.dir/exe %ld_flags_rpath_exe
// RUN: %run %t.dir/exe | FileCheck %s
>From c23d02ddcd8f62f2225dd6afb066542444ab7626 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Tue, 18 Nov 2025 14:45:47 +0000
Subject: [PATCH 2/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
=?UTF-8?q?anges=20introduced=20through=20rebase?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
[skip ci]
---
compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp | 3 ---
1 file changed, 3 deletions(-)
diff --git a/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp b/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
index b36aa1db7aa76..7c6c7715d07dd 100644
--- a/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
+++ b/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
@@ -1,7 +1,4 @@
// RUN: mkdir -p %t.dir && cd %t.dir
-// RUN: basename %dynamiclib > /tmp/test
-// RUN: echo %dynamiclib >> /tmp/test
-// RUN: echo %t >> /tmp/test
// RUN: %clang_tsan -O1 %s -DBUILD_LIB=1 -fno-sanitize=thread -shared -fPIC -o %dynamiclib %ld_flags_rpath_so
// RUN: %clang_tsan -O1 %s -o %t.dir/exe %ld_flags_rpath_exe
// RUN: %run %t.dir/exe | FileCheck %s
>From 5cbf3bf3b023fa71d5f82934e185be1afe5f76f2 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Tue, 18 Nov 2025 15:43:30 +0000
Subject: [PATCH 3/3] feedback
Created using spr 1.3.7
---
.../TestCases/Darwin/dyld_insert_libraries_remove.cpp | 9 +--------
.../test/asan/TestCases/Darwin/init_for_dlopen.cpp | 2 +-
.../asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp | 2 +-
3 files changed, 3 insertions(+), 10 deletions(-)
diff --git a/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp b/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp
index 7e3fe584f706b..872848d075eaf 100644
--- a/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp
+++ b/compiler-rt/test/asan/TestCases/Darwin/dyld_insert_libraries_remove.cpp
@@ -13,26 +13,19 @@
// RUN: %clangxx -DSHARED_LIB %s \
// RUN: -dynamiclib -o %t/dummy-so.dylib
-// RUN: pushd %t
+// RUN: cd %t
// RUN: env DYLD_INSERT_LIBRARIES=@executable_path/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 | FileCheck %s
-// RUN: popd
-// RUN: pushd %t
// RUN: env DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 | FileCheck %s
-// RUN: popd
-// RUN: pushd %t
// RUN: %env_asan_opts=strip_env=0 \
// RUN: DYLD_INSERT_LIBRARIES=libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 | FileCheck %s --check-prefix=CHECK-KEEP
-// RUN: popd
-// RUN: pushd %t
// RUN: env DYLD_INSERT_LIBRARIES=%t/libclang_rt.asan_osx_dynamic.dylib:dummy-so.dylib \
// RUN: %run ./a.out 2>&1 | FileCheck %s
-// RUN: popd
#if !defined(SHARED_LIB)
#include <stdio.h>
diff --git a/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp b/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp
index 84d3387e0cd52..9bb652cc79438 100644
--- a/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp
+++ b/compiler-rt/test/asan/TestCases/Darwin/init_for_dlopen.cpp
@@ -5,7 +5,7 @@
// - 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: env APPLE_ASAN_INIT_FOR_DLOPEN=0 %env_asan_opts=abort_on_error=0 not \
+// RUN: %env_asan_opts=abort_on_error=0 APPLE_ASAN_INIT_FOR_DLOPEN=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 \
diff --git a/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp b/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
index 66f7e06a3d1f8..295e35f4f273b 100644
--- a/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
+++ b/compiler-rt/test/asan_abi/TestCases/Darwin/llvm_interface_symbols.cpp
@@ -25,7 +25,7 @@
// Ensure that there is no dynamic dylib linked.
// RUN: otool -L %t > %t.libs
-// not grep -q "dynamic.dylib" < %t.libs
+// RUN: not grep -q "dynamic.dylib" < %t.libs
// UNSUPPORTED: ios
More information about the llvm-commits
mailing list