[compiler-rt] 445978e - [compiler-rt] Use just built libatomic if available

Alex Brachet via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 14:39:08 PDT 2023


Author: Alex Brachet
Date: 2023-08-29T21:38:56Z
New Revision: 445978ee8c398ddc5d8ae51bc0b0137ce3bb37cb

URL: https://github.com/llvm/llvm-project/commit/445978ee8c398ddc5d8ae51bc0b0137ce3bb37cb
DIFF: https://github.com/llvm/llvm-project/commit/445978ee8c398ddc5d8ae51bc0b0137ce3bb37cb.diff

LOG: [compiler-rt] Use just built libatomic if available

Use libclang_rt.atomic.so instead of the libatomic installed
on the system if it is available.

Differential Revision: https://reviews.llvm.org/D151680

Added: 
    

Modified: 
    compiler-rt/test/CMakeLists.txt
    compiler-rt/test/dfsan/libatomic.c
    compiler-rt/test/lit.common.cfg.py
    compiler-rt/test/lit.common.configured.in
    compiler-rt/test/msan/libatomic.c
    compiler-rt/test/msan/libatomic_load_exceptions.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/CMakeLists.txt b/compiler-rt/test/CMakeLists.txt
index ee0685ec8ee6b9..f9b01b15b0e62c 100644
--- a/compiler-rt/test/CMakeLists.txt
+++ b/compiler-rt/test/CMakeLists.txt
@@ -14,6 +14,7 @@ pythonize_bool(COMPILER_RT_TEST_STANDALONE_BUILD_LIBS)
 pythonize_bool(LLVM_ENABLE_EXPENSIVE_CHECKS)
 
 pythonize_bool(ZLIB_FOUND)
+pythonize_bool(COMPILER_RT_BUILD_STANDALONE_LIBATOMIC)
 
 pythonize_bool(COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
 

diff  --git a/compiler-rt/test/dfsan/libatomic.c b/compiler-rt/test/dfsan/libatomic.c
index 188804fbd04c24..82970cddfcdeeb 100644
--- a/compiler-rt/test/dfsan/libatomic.c
+++ b/compiler-rt/test/dfsan/libatomic.c
@@ -1,7 +1,7 @@
-// RUN: %clang_dfsan -g3 -DDATA_BYTES=3 %s -fno-exceptions -latomic -o %t && %run %t
-// RUN: %clang_dfsan -g3 -DDATA_BYTES=3 -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions -latomic -o %t && %run %t
-// RUN: %clang_dfsan -g3 -DDATA_BYTES=32 %s -fno-exceptions -latomic -o %t && %run %t
-// RUN: %clang_dfsan -g3 -DDATA_BYTES=32 -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions -latomic -o %t && %run %t
+// RUN: %clang_dfsan -g3 -DDATA_BYTES=3 %s -fno-exceptions %libatomic -o %t && %run %t
+// RUN: %clang_dfsan -g3 -DDATA_BYTES=3 -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions %libatomic -o %t && %run %t
+// RUN: %clang_dfsan -g3 -DDATA_BYTES=32 %s -fno-exceptions %libatomic -o %t && %run %t
+// RUN: %clang_dfsan -g3 -DDATA_BYTES=32 -DORIGIN_TRACKING -mllvm -dfsan-track-origins=1 %s -fno-exceptions %libatomic -o %t && %run %t
 
 #include <assert.h>
 #include <sanitizer/dfsan_interface.h>

diff  --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 956a7702544002..230efd580199cb 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -933,6 +933,16 @@ def is_windows_lto_supported():
 # preempt something we're looking to trap (e.g. _FORTIFY_SOURCE vs our ASAN).
 config.environment["CLANG_NO_DEFAULT_CONFIG"] = "1"
 
+if config.has_compiler_rt_libatomic:
+  base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.atomic%s.so"
+                          % config.target_suffix)
+  if sys.platform in ['win32'] and execute_external:
+    # Don't pass dosish path separator to msys bash.exe.
+    base_lib = base_lib.replace('\\', '/')
+  config.substitutions.append(("%libatomic", base_lib + f" -Wl,-rpath,{config.compiler_rt_libdir}"))
+else:
+  config.substitutions.append(("%libatomic", "-latomic"))
+
 # Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
 push_dynamic_library_lookup_path(config, config.compiler_rt_libdir)
 

diff  --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in
index cc24e25ae75633..7c2d53520099a1 100644
--- a/compiler-rt/test/lit.common.configured.in
+++ b/compiler-rt/test/lit.common.configured.in
@@ -49,6 +49,7 @@ set_default("have_rpc_xdr_h", @HAVE_RPC_XDR_H@)
 set_default("gwp_asan", @COMPILER_RT_HAS_GWP_ASAN_PYBOOL@)
 set_default("expensive_checks", @LLVM_ENABLE_EXPENSIVE_CHECKS_PYBOOL@)
 set_default("test_standalone_build_libs", @COMPILER_RT_TEST_STANDALONE_BUILD_LIBS_PYBOOL@)
+set_default("has_compiler_rt_libatomic", @COMPILER_RT_BUILD_STANDALONE_LIBATOMIC_PYBOOL@)
 # True iff the test suite supports ignoring the test compiler's runtime library path
 # and using `config.compiler_rt_libdir` instead. This only matters when the runtime
 # library paths 
diff er.

diff  --git a/compiler-rt/test/msan/libatomic.c b/compiler-rt/test/msan/libatomic.c
index a8c030b7dbb26c..be0b4523690a45 100644
--- a/compiler-rt/test/msan/libatomic.c
+++ b/compiler-rt/test/msan/libatomic.c
@@ -1,6 +1,6 @@
-// RUN: %clang_msan -fsanitize-memory-track-origins=2 -latomic -DTEST_STORE -O0 %s -o %t && %run %t 2>&1
-// RUN: %clang_msan -fsanitize-memory-track-origins=0 -latomic -DTEST_LOAD -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
-// RUN: %clang_msan -fsanitize-memory-track-origins=2 -latomic -DTEST_LOAD -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SHADOW
+// RUN: %clang_msan -fsanitize-memory-track-origins=2 %libatomic -DTEST_STORE -O0 %s -o %t && %run %t 2>&1
+// RUN: %clang_msan -fsanitize-memory-track-origins=0 %libatomic -DTEST_LOAD -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK
+// RUN: %clang_msan -fsanitize-memory-track-origins=2 %libatomic -DTEST_LOAD -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SHADOW
 
 // PPC has no libatomic
 // UNSUPPORTED: powerpc64-target-arch

diff  --git a/compiler-rt/test/msan/libatomic_load_exceptions.cpp b/compiler-rt/test/msan/libatomic_load_exceptions.cpp
index 99fd42f20af655..83449c01081027 100644
--- a/compiler-rt/test/msan/libatomic_load_exceptions.cpp
+++ b/compiler-rt/test/msan/libatomic_load_exceptions.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_msan -fexceptions -fsanitize-memory-track-origins=2 -latomic -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SHADOW
+// RUN: %clangxx_msan -fexceptions -fsanitize-memory-track-origins=2 %libatomic -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SHADOW
 
 // PPC has no libatomic
 // UNSUPPORTED: powerpc64-target-arch


        


More information about the llvm-commits mailing list