Skip to content

Commit 9e25a42

Browse files
authored
[TySan] Make TySan compatible with UBSan (#169036)
1 parent e0c6007 commit 9e25a42

File tree

7 files changed

+21
-2
lines changed

7 files changed

+21
-2
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ bool SanitizerArgs::needsFuzzerInterceptors() const {
358358
bool SanitizerArgs::needsUbsanRt() const {
359359
// All of these include ubsan.
360360
if (needsAsanRt() || needsMsanRt() || needsNsanRt() || needsHwasanRt() ||
361-
needsTsanRt() || needsDfsanRt() || needsLsanRt() ||
361+
needsTsanRt() || needsDfsanRt() || needsLsanRt() || needsTysanRt() ||
362362
needsCfiCrossDsoDiagRt() || (needsScudoRt() && !requiresMinimalRuntime()))
363363
return false;
364364

compiler-rt/lib/tysan/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ if(APPLE)
4646
OBJECT_LIBS RTTysan_dynamic
4747
RTInterception
4848
RTSanitizerCommon
49+
RTSanitizerCommonCoverage
4950
RTSanitizerCommonLibc
5051
RTSanitizerCommonSymbolizer
52+
RTUbsan
5153
CFLAGS ${TYSAN_DYNAMIC_CFLAGS}
5254
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
5355
DEFS ${TYSAN_DYNAMIC_DEFINITIONS}
@@ -71,8 +73,10 @@ else()
7173
SOURCES ${TYSAN_SOURCES}
7274
OBJECT_LIBS RTInterception
7375
RTSanitizerCommon
76+
RTSanitizerCommonCoverage
7477
RTSanitizerCommonLibc
7578
RTSanitizerCommonSymbolizer
79+
RTUbsan
7680
CFLAGS ${TYSAN_CFLAGS}
7781
PARENT_TARGET tysan)
7882
endforeach()

compiler-rt/test/ubsan/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ foreach(arch ${UBSAN_TEST_ARCH})
6262
if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};" AND NOT ANDROID)
6363
add_ubsan_testsuites("ThreadSanitizer" tsan ${arch})
6464
endif()
65+
if(COMPILER_RT_HAS_TYSAN AND ";${TYSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
66+
add_ubsan_testsuites("TypeSanitizer" tysan ${arch})
67+
endif()
6568
endforeach()
6669

6770
macro(add_ubsan_device_testsuite test_mode sanitizer platform arch)
@@ -124,6 +127,10 @@ if(APPLE)
124127
if(COMPILER_RT_HAS_TSAN AND ";${TSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
125128
add_ubsan_device_testsuite("ThreadSanitizer" tsan ${platform} ${arch})
126129
endif()
130+
131+
if(COMPILER_RT_HAS_TYSAN AND ";${TYSAN_SUPPORTED_ARCH};" MATCHES ";${arch};")
132+
add_ubsan_device_testsuite("TypeSanitizer" tysan ${platform} ${arch})
133+
endif()
127134
endforeach()
128135
endforeach()
129136
endif()

compiler-rt/test/ubsan/TestCases/Misc/Posix/sigaction.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
// Reason unknown, needs debugging.
88
// UNSUPPORTED: target=aarch64{{.*}} && ubsan-tsan
99

10+
// TySan doesn't build a shared library
11+
// UNSUPPORTED: ubsan-tysan
12+
1013
#include <assert.h>
1114
#include <signal.h>
1215
#include <stdio.h>

compiler-rt/test/ubsan/TestCases/Misc/coverage-levels.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=edge,trace-pc-guard %s -o %t
2020
// RUN: %env_ubsan_opts=coverage=1:verbosity=1:coverage_dir='"%t-dir"' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN
2121

22-
// Coverage is not yet implemented in TSan.
22+
// Coverage is not yet implemented in TSan or TySan.
2323
// XFAIL: ubsan-tsan
24+
// XFAIL: ubsan-tysan
2425
// UNSUPPORTED: ubsan-standalone-static
2526
// No coverage support
2627
// UNSUPPORTED: target={{.*openbsd.*}}

compiler-rt/test/ubsan/lit.common.cfg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def get_required_attr(config, attr_name):
3939
elif ubsan_lit_test_mode == "ThreadSanitizer":
4040
config.available_features.add("ubsan-tsan")
4141
clang_ubsan_cflags = ["-fsanitize=thread"]
42+
elif ubsan_lit_test_mode == "TypeSanitizer":
43+
config.available_features.add("ubsan-tysan")
44+
clang_ubsan_cflags = ["-fsanitize=type"]
4245
else:
4346
lit_config.fatal("Unknown UBSan test mode: %r" % ubsan_lit_test_mode)
4447

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ Changes to BOLT
222222
Changes to Sanitizers
223223
---------------------
224224

225+
* Support running TypeSanitizer with UndefinedBehaviourSanitizer.
225226
* TypeSanitizer no longer inlines all instrumentation by default. Added the
226227
`-f[no-]sanitize-type-outline-instrumentation` flags to give users control
227228
over this behaviour.

0 commit comments

Comments
 (0)