Skip to content

[TySan] A Type Sanitizer (Runtime Library) #76261

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 25 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4c3ac21
[𝘀𝗽𝗿] initial version
fhahn Dec 22, 2023
e5158df
!fixup address comments, thanks
fhahn Apr 18, 2024
9e30a88
!fiupx address comments, thanks!
fhahn Jun 27, 2024
557abfc
!fixup remove Instrumentation.h include
fhahn Dec 6, 2024
f035588
!fixup address latest comments, thanks!
fhahn Dec 6, 2024
9e05f83
!fixup modernize check lines.
fhahn Dec 6, 2024
1dd1d14
!fixup pass ShadowBase/AppMemMask by value.
fhahn Dec 6, 2024
4c19928
!fixup address first set of comments, thanks!
fhahn Dec 10, 2024
694cb2c
!Fixup address remaining comments, thanks!
fhahn Dec 10, 2024
be6f759
[TySan] A Type Sanitizer (Clang)
fhahn Apr 18, 2024
9adf5be
!fixup: add test
fhahn Apr 18, 2024
349c32d
!fixup formatting and add release note.
fhahn Nov 22, 2024
2c3ac3d
!fixup merge reportGlobal again, adjust release notes.
fhahn Nov 27, 2024
bac1590
!fixup add missing ``
fhahn Nov 27, 2024
8dfaca8
!fixup undo unrelated changes, fix runtimes to push
fhahn Dec 6, 2024
13c4092
!fixup account for globals without types.
fhahn Dec 10, 2024
524eb55
[TySan] A Type Sanitizer (Runtime Library)
fhahn Nov 22, 2024
6f48a28
!fixup update tests
fhahn Dec 6, 2024
f92088f
!fixup remove commented out code, thanks!
fhahn Dec 12, 2024
758c99a
!fixup update checks for linux.
fhahn Dec 12, 2024
43b62b9
!fixup fix formatting in test
fhahn Dec 12, 2024
c3aa78a
!fixup fix python formatting
fhahn Dec 12, 2024
17c4577
!fixup address latest comments, thanks!
fhahn Dec 16, 2024
975d1ed
!fixup address latest comments, thanks!
fhahn Dec 17, 2024
7cc9117
Merge remote-tracking branch 'origin/main' into users/fhahn/tysan-a-t…
fhahn Dec 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ if(LLVM_BUILD_EXTERNAL_COMPILER_RT AND EXISTS ${COMPILER_RT_SRC_ROOT}/)
COMPONENT compiler-rt)

# Add top-level targets that build specific compiler-rt runtimes.
set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan ubsan ubsan-minimal)
set(COMPILER_RT_RUNTIMES fuzzer asan builtins dfsan lsan msan profile tsan tysan ubsan ubsan-minimal)
foreach(runtime ${COMPILER_RT_RUNTIMES})
get_ext_project_build_command(build_runtime_cmd ${runtime})
add_custom_target(${runtime}
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ else()
set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
${LOONGARCH64} ${RISCV64})
endif()
set(ALL_TYSAN_SUPPORTED_ARCH ${X86_64} ${ARM64})
set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
${LOONGARCH64})
Expand Down
15 changes: 14 additions & 1 deletion compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ if(APPLE)
set(SANITIZER_COMMON_SUPPORTED_OS osx)
set(PROFILE_SUPPORTED_OS osx)
set(TSAN_SUPPORTED_OS osx)
set(TYSAN_SUPPORTED_OS osx)
set(XRAY_SUPPORTED_OS osx)
set(FUZZER_SUPPORTED_OS osx)
set(ORC_SUPPORTED_OS)
Expand Down Expand Up @@ -593,6 +594,7 @@ if(APPLE)
list(APPEND FUZZER_SUPPORTED_OS ${platform})
list(APPEND ORC_SUPPORTED_OS ${platform})
list(APPEND UBSAN_SUPPORTED_OS ${platform})
list(APPEND TYSAN_SUPPORTED_OS ${platform})
list(APPEND LSAN_SUPPORTED_OS ${platform})
list(APPEND STATS_SUPPORTED_OS ${platform})
endif()
Expand Down Expand Up @@ -651,6 +653,9 @@ if(APPLE)
list_intersect(CTX_PROFILE_SUPPORTED_ARCH
ALL_CTX_PROFILE_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
list_intersect(TYSAN_SUPPORTED_ARCH
ALL_TYSAN_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
list_intersect(TSAN_SUPPORTED_ARCH
ALL_TSAN_SUPPORTED_ARCH
SANITIZER_COMMON_SUPPORTED_ARCH)
Expand Down Expand Up @@ -703,6 +708,7 @@ else()
filter_available_targets(PROFILE_SUPPORTED_ARCH ${ALL_PROFILE_SUPPORTED_ARCH})
filter_available_targets(CTX_PROFILE_SUPPORTED_ARCH ${ALL_CTX_PROFILE_SUPPORTED_ARCH})
filter_available_targets(TSAN_SUPPORTED_ARCH ${ALL_TSAN_SUPPORTED_ARCH})
filter_available_targets(TYSAN_SUPPORTED_ARCH ${ALL_TYSAN_SUPPORTED_ARCH})
filter_available_targets(UBSAN_SUPPORTED_ARCH ${ALL_UBSAN_SUPPORTED_ARCH})
filter_available_targets(SAFESTACK_SUPPORTED_ARCH
${ALL_SAFESTACK_SUPPORTED_ARCH})
Expand Down Expand Up @@ -748,7 +754,7 @@ if(COMPILER_RT_SUPPORTED_ARCH)
endif()
message(STATUS "Compiler-RT supported architectures: ${COMPILER_RT_SUPPORTED_ARCH}")

set(ALL_SANITIZERS asan;rtsan;dfsan;msan;hwasan;tsan;safestack;cfi;scudo_standalone;ubsan_minimal;gwp_asan;nsan;asan_abi)
set(ALL_SANITIZERS asan;rtsan;dfsan;msan;hwasan;tsan;tysan;safestack;cfi;scudo_standalone;ubsan_minimal;gwp_asan;nsan;asan_abi)
set(COMPILER_RT_SANITIZERS_TO_BUILD all CACHE STRING
"sanitizers to build if supported on the target (all;${ALL_SANITIZERS})")
list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
Expand Down Expand Up @@ -843,6 +849,13 @@ else()
set(COMPILER_RT_HAS_CTX_PROFILE FALSE)
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND TYSAN_SUPPORTED_ARCH AND
OS_NAME MATCHES "Linux|Darwin")
set(COMPILER_RT_HAS_TYSAN TRUE)
else()
set(COMPILER_RT_HAS_TYSAN FALSE)
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND TSAN_SUPPORTED_ARCH)
if (OS_NAME MATCHES "Linux|Darwin|FreeBSD|NetBSD")
set(COMPILER_RT_HAS_TSAN TRUE)
Expand Down
64 changes: 64 additions & 0 deletions compiler-rt/lib/tysan/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
include_directories(..)

# Runtime library sources and build flags.
set(TYSAN_SOURCES
tysan.cpp
tysan_interceptors.cpp)
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)

add_compiler_rt_object_libraries(RTTysan_dynamic
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${TYSAN_SUPPORTED_ARCH}
SOURCES ${TYSAN_SOURCES}
ADDITIONAL_HEADERS ${TYSAN_HEADERS}
CFLAGS ${TYSAN_DYNAMIC_CFLAGS}
DEFS ${TYSAN_DYNAMIC_DEFINITIONS})


# Static runtime library.
add_compiler_rt_component(tysan)


if(APPLE)
add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)

add_compiler_rt_runtime(clang_rt.tysan
SHARED
OS ${SANITIZER_COMMON_SUPPORTED_OS}
ARCHS ${TYSAN_SUPPORTED_ARCH}
OBJECT_LIBS RTTysan_dynamic
RTInterception
RTSanitizerCommon
RTSanitizerCommonLibc
RTSanitizerCommonSymbolizer
CFLAGS ${TYSAN_DYNAMIC_CFLAGS}
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
DEFS ${TYSAN_DYNAMIC_DEFINITIONS}
PARENT_TARGET tysan)

add_compiler_rt_runtime(clang_rt.tysan_static
STATIC
ARCHS ${TYSAN_SUPPORTED_ARCH}
OBJECT_LIBS RTTysan_static
CFLAGS ${TYSAN_CFLAGS}
DEFS ${TYSAN_COMMON_DEFINITIONS}
PARENT_TARGET tysan)
else()
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}>
CFLAGS ${TYSAN_CFLAGS}
PARENT_TARGET tysan)
endforeach()
endif()
35 changes: 35 additions & 0 deletions compiler-rt/lib/tysan/lit.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# -*- Python -*-

import os

# Setup config name.
config.name = 'TypeSanitizer' + getattr(config, 'name_suffix', 'default')

# Setup source root.
config.test_source_root = os.path.dirname(__file__)

# Setup default compiler flags used with -fsanitize=type option.
clang_tysan_cflags = (["-fsanitize=type",
"-mno-omit-leaf-frame-pointer",
"-fno-omit-frame-pointer",
"-fno-optimize-sibling-calls"] +
config.target_cflags +
config.debug_info_flags)
clang_tysan_cxxflags = config.cxx_mode_flags + clang_tysan_cflags

def build_invocation(compile_flags):
return " " + " ".join([config.clang] + compile_flags) + " "

config.substitutions.append( ("%clang_tysan ", build_invocation(clang_tysan_cflags)) )
config.substitutions.append( ("%clangxx_tysan ", build_invocation(clang_tysan_cxxflags)) )

# Default test suffixes.
config.suffixes = ['.c', '.cc', '.cpp']

# TypeSanitizer tests are currently supported on Linux only.
if config.host_os not in ['Linux']:
config.unsupported = True

if config.target_arch != 'aarch64':
config.available_features.add('stable-runtime')

12 changes: 12 additions & 0 deletions compiler-rt/lib/tysan/lit.site.cfg.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@LIT_SITE_CFG_IN_HEADER@

# Tool-specific config options.
config.name_suffix = "@TYSAN_TEST_CONFIG_SUFFIX@"
config.target_cflags = "@TYSAN_TEST_TARGET_CFLAGS@"
config.target_arch = "@TYSAN_TEST_TARGET_ARCH@"

# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")

# Load tool-specific config that would do the real work.
lit_config.load_config(config, "@TYSAN_LIT_SOURCE_DIR@/lit.cfg")
Loading
Loading