Skip to content

Commit

Permalink
[TYSan][CMake] CMake build fixes (#121224)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
petrhosek authored Dec 30, 2024
1 parent fb365ac commit 9a88ede
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions compiler-rt/lib/tysan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +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.h
tysan_flags.inc
tysan_platform.h
)

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_DYNAMIC_CFLAGS ${TYSAN_COMMON_CFLAGS})

set(TYSAN_COMMON_DEFINITIONS "")
set(TYSAN_DYNAMIC_DEFINITIONS ${TYSAN_COMMON_DEFINITIONS} TYSAN_DYNAMIC=1)

# Compile TYSan sources into an object library.

add_compiler_rt_object_libraries(RTTysan_dynamic
OS ${SANITIZER_COMMON_SUPPORTED_OS}
Expand Down Expand Up @@ -47,17 +61,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()
Expand Down

0 comments on commit 9a88ede

Please sign in to comment.