[compiler-rt] [compiler-rt][rtsan] Introduce first end to end RTsan lit tests, enable instrumented unit tests (PR #105732)
Chris Apple via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 27 11:19:23 PDT 2024
cjappl wrote:
Hi @Prabhuk,
Thanks for the early legwork on this, and sorry for the breakage. I am more than happy to help you get things back to green.
> Some observations from our team in our early investigation:
> libclang_rt.atomic.so is not linked in for the test binaries.
> We don't see -latomic in the link even though cmake file for the test seems to try to set it:
> [llvm-project/compiler-rt/lib/rtsan/tests/CMakeLists.txt](https://github.com/llvm/llvm-project/blob/0359b9a2306566a872cede1fcdaa4edc34e9398e/compiler-rt/lib/rtsan/tests/CMakeLists.txt#L39)
> Line 39 in [0359b9a](https://github.com/llvm/llvm-project/commit/0359b9a2306566a872cede1fcdaa4edc34e9398e)
> append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic RTSAN_UNITTEST_LINK_FLAGS)
> We suspect the problem here could be with detection of COMPILER_RT_HAS_LIBATOMIC.
This theory has a lot of weight for me, when I compile on ubuntu, for instance, and apply this patch:
```
diff --git a/compiler-rt/lib/rtsan/tests/CMakeLists.txt b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
index 0320bbad5921..c31370fa01be 100644
--- a/compiler-rt/lib/rtsan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
@@ -37,6 +37,7 @@ set(RTSAN_UNITTEST_LINK_FLAGS
-no-pie)
append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic RTSAN_UNITTEST_LINK_FLAGS)
+message(FATAL_ERROR "COMPILER_RT_HAS_LIBATOMIC: ${COMPILER_RT_HAS_LIBATOMIC}")
append_list_if(COMPILER_RT_HAS_LIBDL -ldl RTSAN_UNITTEST_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LIBRT -lrt RTSAN_UNITTEST_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LIBM -lm RTSAN_UNITTEST_LINK_FLAGS)
```
I get, as expected:
```
-- For aarch64 builtins preferring aarch64/fp_mode.c to fp_mode.c
CMake Error at /test_radsan/llvm-project/compiler-rt/lib/rtsan/tests/CMakeLists.txt:40 (message):
COMPILER_RT_HAS_LIBATOMIC: 1
```
Can you describe what OS and arch you are compiling for? (I see the build logs, but I don't want to assume anything). I typically run my tests locally against MacOS and ubuntu, which is why I may not have seen this error in my development.
If you explicitly hack to add the linker flag, such as:
```
diff --git a/compiler-rt/lib/rtsan/tests/CMakeLists.txt b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
index 0320bbad5921..b9755786965a 100644
--- a/compiler-rt/lib/rtsan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/tests/CMakeLists.txt
@@ -36,7 +36,7 @@ set(RTSAN_UNITTEST_LINK_FLAGS
${SANITIZER_TEST_CXX_LIBRARIES}
-no-pie)
-append_list_if(COMPILER_RT_HAS_LIBATOMIC -latomic RTSAN_UNITTEST_LINK_FLAGS)
+append_list_if(ON -latomic RTSAN_UNITTEST_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LIBDL -ldl RTSAN_UNITTEST_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LIBRT -lrt RTSAN_UNITTEST_LINK_FLAGS)
append_list_if(COMPILER_RT_HAS_LIBM -lm RTSAN_UNITTEST_LINK_FLAGS)
```
Does the flag show up, and it compiles? I think this would be another indication the detection of `COMPILER_RT_HAS_LIBATOMIC` is funky for this specific config.
https://github.com/llvm/llvm-project/pull/105732
More information about the llvm-commits
mailing list