Skip to content

[TYSan][CMake] CMake build fixes #121224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 30, 2024
Merged

Conversation

petrhosek
Copy link
Member

TYSan CMake build follows patterns used by other sanitizers, but there's also a number of issues, like referring to undefined variables, which breaks the build in some cases (such as cross-compiling). This change addresses the issues.

TYSan CMake build follows patterns used by other sanitizers, but there's
also a number of issues, like referring to undefined variables, which
breaks the build in some cases (such as cross-compiling). This change
addresses the issues.
@llvmbot
Copy link
Member

llvmbot commented Dec 27, 2024

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

Author: Petr Hosek (petrhosek)

Changes

TYSan CMake build follows patterns used by other sanitizers, but there's also a number of issues, like referring to undefined variables, which breaks the build in some cases (such as cross-compiling). This change addresses the issues.


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

1 Files Affected:

  • (modified) compiler-rt/lib/tysan/CMakeLists.txt (+21-7)
diff --git a/compiler-rt/lib/tysan/CMakeLists.txt b/compiler-rt/lib/tysan/CMakeLists.txt
index 859b67928f004a..a041ba5ee5937a 100644
--- a/compiler-rt/lib/tysan/CMakeLists.txt
+++ b/compiler-rt/lib/tysan/CMakeLists.txt
@@ -3,12 +3,25 @@ include_directories(..)
 # Runtime library sources and build flags.
 set(TYSAN_SOURCES
   tysan.cpp
-  tysan_interceptors.cpp)
+  tysan_interceptors.cpp
+  )
+
+SET(TYSAN_HEADERS
+  tysan_flags.inc
+  )
+
 set(TYSAN_COMMON_CFLAGS ${SANITIZER_COMMON_CFLAGS})
 append_rtti_flag(OFF TYSAN_COMMON_CFLAGS)
 # Prevent clang from generating libc calls.
 append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding TYSAN_COMMON_CFLAGS)
 
+set(TYSAN_COMMON_DEFINITIONS "")
+set(TYSAN_DYNAMIC_DEFINITIONS ${TYSAN_COMMON_DEFINITIONS})
+
+set(TYSAN_DYNAMIC_CFLAGS ${TYSAN_COMMON_CFLAGS})
+
+# Compile TYSan sources into an object library.
+
 add_compiler_rt_object_libraries(RTTysan_dynamic
   OS ${SANITIZER_COMMON_SUPPORTED_OS}
   ARCHS ${TYSAN_SUPPORTED_ARCH}
@@ -47,17 +60,18 @@ if(APPLE)
     DEFS ${TYSAN_COMMON_DEFINITIONS}
     PARENT_TARGET tysan)
 else()
+  set(TYSAN_CFLAGS ${TYSAN_COMMON_CFLAGS})
+  append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TYSAN_CFLAGS)
+
   foreach(arch ${TYSAN_SUPPORTED_ARCH})
-    set(TYSAN_CFLAGS ${TYSAN_COMMON_CFLAGS})
-    append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TYSAN_CFLAGS)
     add_compiler_rt_runtime(clang_rt.tysan
       STATIC
       ARCHS ${arch}
       SOURCES ${TYSAN_SOURCES}
-              $<TARGET_OBJECTS:RTInterception.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
-              $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
+      OBJECT_LIBS RTInterception
+                  RTSanitizerCommon
+                  RTSanitizerCommonLibc
+                  RTSanitizerCommonSymbolizer
       CFLAGS ${TYSAN_CFLAGS}
       PARENT_TARGET tysan)
   endforeach()

Copy link
Contributor

@fhahn fhahn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@gulfemsavrun gulfemsavrun merged commit 9a88ede into llvm:main Dec 30, 2024
7 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Dec 31, 2024

LLVM Buildbot has detected a new failure on builder clang-ppc64-aix running on aix-ppc64 while building compiler-rt at step 3 "clean-build-dir".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/64/builds/1826

Here is the relevant piece of the build log for the reference
Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out)
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Profile-powerpc :: ContinuousSyncMode/online-merging.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 6: rm -rf /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir && mkdir -p /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir && cd /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir
+ rm -rf /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir
+ mkdir -p /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir
+ cd /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir
RUN: at line 9: echo "void dso1(void) {}" > dso1.c
+ echo 'void dso1(void) {}'
RUN: at line 10: echo "void dso2(void) {}" > dso2.c
+ echo 'void dso2(void) {}'
RUN: at line 11: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/./bin/clang   -m32   -fprofile-generate -mllvm -runtime-counter-relocation -shared -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso1.dylib dso1.c -fprofile-update=atomic
+ /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/./bin/clang -m32 -fprofile-generate -mllvm -runtime-counter-relocation -shared -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso1.dylib dso1.c -fprofile-update=atomic
RUN: at line 12: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/./bin/clang   -m32   -fprofile-generate -mllvm -runtime-counter-relocation -shared -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso2.dylib dso2.c -fprofile-update=atomic
+ /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/./bin/clang -m32 -fprofile-generate -mllvm -runtime-counter-relocation -shared -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso2.dylib dso2.c -fprofile-update=atomic
RUN: at line 13: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/./bin/clang   -m32   -fprofile-generate -mllvm -runtime-counter-relocation -o main.exe /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso1.dylib /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso2.dylib -fprofile-update=atomic
+ /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/./bin/clang -m32 -fprofile-generate -mllvm -runtime-counter-relocation -o main.exe /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso1.dylib /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/dso2.dylib -fprofile-update=atomic
RUN: at line 18: env LLVM_PROFILE_FILE="/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir/%m%c.profraw"  /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/main.exe nospawn
+ env LLVM_PROFILE_FILE=/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir/%m%c.profraw /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/main.exe nospawn
RUN: at line 19: llvm-profdata merge -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir
+ llvm-profdata merge -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir
RUN: at line 20: llvm-profdata show --counts --all-functions /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata | FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c -check-prefix=ROUND1
+ llvm-profdata show --counts --all-functions /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata
+ FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c -check-prefix=ROUND1
RUN: at line 42: env LLVM_PROFILE_FILE="/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir/%m%c.profraw"  /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/main.exe spawn 'LLVM_PROFILE_FILE=/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir/%m%c.profraw'
+ env LLVM_PROFILE_FILE=/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir/%m%c.profraw /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/main.exe spawn LLVM_PROFILE_FILE=/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir/%m%c.profraw
RUN: at line 43: llvm-profdata merge -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir
+ llvm-profdata merge -o /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.dir/profdir
RUN: at line 44: llvm-profdata show --counts --all-functions /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata | FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c -check-prefix=ROUND2
+ llvm-profdata show --counts --all-functions /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/runtimes/runtimes-bins/compiler-rt/test/profile/Profile-powerpc/ContinuousSyncMode/Output/online-merging.c.tmp.profdata
+ FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c -check-prefix=ROUND2
/home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c:54:16: error: ROUND2-DAG: expected string not found in input
// ROUND2-DAG: Block counts: [97]
               ^
<stdin>:13:20: note: scanning from here
 Block counts: [97]
                   ^
<stdin>:14:12: note: possible intended match here
Instrumentation level: IR entry_first = 0 instrument_loop_entries = 0
           ^

Input file: <stdin>
Check file: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/compiler-rt/test/profile/ContinuousSyncMode/online-merging.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
...

@petrhosek petrhosek deleted the tysan-cmake-fixes branch February 24, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants