diff --git a/clang/runtime/CMakeLists.txt b/clang/runtime/CMakeLists.txt --- a/clang/runtime/CMakeLists.txt +++ b/clang/runtime/CMakeLists.txt @@ -119,7 +119,7 @@ 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} diff --git a/compiler-rt/lib/tysan/CMakeLists.txt b/compiler-rt/lib/tysan/CMakeLists.txt --- a/compiler-rt/lib/tysan/CMakeLists.txt +++ b/compiler-rt/lib/tysan/CMakeLists.txt @@ -46,4 +46,19 @@ 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} + $ + $ + $ + $ + CFLAGS ${TYSAN_CFLAGS} + PARENT_TARGET tysan) + endforeach() endif() diff --git a/compiler-rt/lib/tysan/tysan_interceptors.cpp b/compiler-rt/lib/tysan/tysan_interceptors.cpp --- a/compiler-rt/lib/tysan/tysan_interceptors.cpp +++ b/compiler-rt/lib/tysan/tysan_interceptors.cpp @@ -84,7 +84,7 @@ return res; } -#ifndef SANITIZER_APPLE +#if !SANITIZER_APPLE INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags, int fd, OFF64_T offset) { void *res = REAL(mmap64)(addr, length, prot, flags, fd, offset); @@ -154,35 +154,54 @@ return res; } -#ifndef SANITIZER_APPLE +#if SANITIZER_INTERCEPT_MEMALIGN INTERCEPTOR(void *, memalign, uptr alignment, uptr size) { void *res = REAL(memalign)(alignment, size); if (res) tysan_set_type_unknown(res, size); return res; } +#define TYSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign) +#else +#define TYSAN_MAYBE_INTERCEPT_MEMALIGN +#endif // SANITIZER_INTERCEPT_MEMALIGN +#if SANITIZER_INTERCEPT___LIBC_MEMALIGN INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) { void *res = REAL(__libc_memalign)(alignment, size); if (res) tysan_set_type_unknown(res, size); return res; } +#define TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN \ + INTERCEPT_FUNCTION(__libc_memalign) +#else +#define TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN +#endif // SANITIZER_INTERCEPT___LIBC_MEMALIGN +#if SANITIZER_INTERCEPT_PVALLOC INTERCEPTOR(void *, pvalloc, uptr size) { void *res = REAL(pvalloc)(size); if (res) tysan_set_type_unknown(res, size); return res; } -#endif +#define TYSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc) +#else +#define TYSAN_MAYBE_INTERCEPT_PVALLOC +#endif // SANITIZER_INTERCEPT_PVALLOC +#if SANITIZER_INTERCEPT_ALIGNED_ALLOC INTERCEPTOR(void *, aligned_alloc, uptr alignment, uptr size) { void *res = REAL(aligned_alloc)(alignment, size); if (res) tysan_set_type_unknown(res, size); return res; } +#define TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(aligned_alloc) +#else +#define TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC +#endif INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) { int res = REAL(posix_memalign)(memptr, alignment, size); @@ -216,10 +235,10 @@ INTERCEPT_FUNCTION(free); INTERCEPT_FUNCTION(realloc); INTERCEPT_FUNCTION(valloc); - INTERCEPT_FUNCTION(memalign); - INTERCEPT_FUNCTION(__libc_memalign); - INTERCEPT_FUNCTION(pvalloc); - INTERCEPT_FUNCTION(aligned_alloc); + TYSAN_MAYBE_INTERCEPT_MEMALIGN; + TYSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN; + TYSAN_MAYBE_INTERCEPT_PVALLOC; + TYSAN_MAYBE_INTERCEPT_ALIGNED_ALLOC INTERCEPT_FUNCTION(posix_memalign); INTERCEPT_FUNCTION(memset);