[clang] ab3640a - [ASan] Moved optimized callbacks into a separate library.
Kirill Stoimenov via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 23 08:41:15 PST 2021
Author: Kirill Stoimenov
Date: 2021-12-23T16:40:36Z
New Revision: ab3640aa0e8361921a5d0cdc393a5b75e78ec22b
URL: https://github.com/llvm/llvm-project/commit/ab3640aa0e8361921a5d0cdc393a5b75e78ec22b
DIFF: https://github.com/llvm/llvm-project/commit/ab3640aa0e8361921a5d0cdc393a5b75e78ec22b.diff
LOG: [ASan] Moved optimized callbacks into a separate library.
This will allow linking in the callbacks directly instead of using PLT.
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D116182
Added:
Modified:
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/asan/CMakeLists.txt
compiler-rt/lib/asan/tests/CMakeLists.txt
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 407f81a2ae09a..267625c70b251 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -826,6 +826,11 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
StaticRuntimes.push_back("stats_client");
+ // Always link the static runtime regardless of DSO or executable.
+ if (SanArgs.needsAsanRt()) {
+ HelperStaticRuntimes.push_back("asan_static");
+ }
+
// Collect static runtimes.
if (Args.hasArg(options::OPT_shared)) {
// Don't link static runtimes into DSOs.
diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c
index d62e19fd4021b..ea8c49f2384ad 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -22,7 +22,7 @@
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
// RUN: | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
//
-// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan
+// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
// RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address -shared-libsan \
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index 2e63c8d051688..2ca59c94cc757 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -34,7 +34,6 @@ set(ASAN_SOURCES
if (NOT WIN32 AND NOT APPLE)
list(APPEND ASAN_SOURCES
- asan_rtl_x86_64.S
asan_interceptors_vfork.S
)
endif()
@@ -43,6 +42,12 @@ set(ASAN_CXX_SOURCES
asan_new_delete.cpp
)
+if (NOT WIN32 AND NOT APPLE)
+ set(ASAN_STATIC_SOURCES
+ asan_rtl_x86_64.S
+ )
+endif()
+
set(ASAN_PREINIT_SOURCES
asan_preinit.cpp
)
@@ -135,6 +140,12 @@ if(NOT APPLE)
ADDITIONAL_HEADERS ${ASAN_HEADERS}
CFLAGS ${ASAN_CFLAGS}
DEFS ${ASAN_COMMON_DEFINITIONS})
+ add_compiler_rt_object_libraries(RTAsan_static
+ ARCHS ${ASAN_SUPPORTED_ARCH}
+ SOURCES ${ASAN_STATIC_SOURCES}
+ ADDITIONAL_HEADERS ${ASAN_HEADERS}
+ CFLAGS ${ASAN_CFLAGS}
+ DEFS ${ASAN_COMMON_DEFINITIONS})
add_compiler_rt_object_libraries(RTAsan_preinit
ARCHS ${ASAN_SUPPORTED_ARCH}
SOURCES ${ASAN_PREINIT_SOURCES}
@@ -176,6 +187,14 @@ if(APPLE)
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
DEFS ${ASAN_DYNAMIC_DEFINITIONS}
PARENT_TARGET asan)
+
+ add_compiler_rt_runtime(clang_rt.asan_static
+ STATIC
+ ARCHS ${ASAN_SUPPORTED_ARCH}
+ OBJECT_LIBS RTAsan_static
+ CFLAGS ${ASAN_CFLAGS}
+ DEFS ${ASAN_COMMON_DEFINITIONS}
+ PARENT_TARGET asan)
else()
# Build separate libraries for each target.
@@ -207,6 +226,14 @@ else()
DEFS ${ASAN_COMMON_DEFINITIONS}
PARENT_TARGET asan)
+ add_compiler_rt_runtime(clang_rt.asan_static
+ STATIC
+ ARCHS ${ASAN_SUPPORTED_ARCH}
+ OBJECT_LIBS RTAsan_static
+ CFLAGS ${ASAN_CFLAGS}
+ DEFS ${ASAN_COMMON_DEFINITIONS}
+ PARENT_TARGET asan)
+
add_compiler_rt_runtime(clang_rt.asan-preinit
STATIC
ARCHS ${ASAN_SUPPORTED_ARCH}
diff --git a/compiler-rt/lib/asan/tests/CMakeLists.txt b/compiler-rt/lib/asan/tests/CMakeLists.txt
index cc375acf2dfbc..95a324766ae7c 100644
--- a/compiler-rt/lib/asan/tests/CMakeLists.txt
+++ b/compiler-rt/lib/asan/tests/CMakeLists.txt
@@ -261,6 +261,7 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
set(ASAN_TEST_RUNTIME_OBJECTS
$<TARGET_OBJECTS:RTAsan.${arch}>
$<TARGET_OBJECTS:RTAsan_cxx.${arch}>
+ $<TARGET_OBJECTS:RTAsan_static.${arch}>
$<TARGET_OBJECTS:RTInterception.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
@@ -286,6 +287,7 @@ if(ANDROID)
# Test w/o ASan instrumentation. Link it with ASan statically.
add_executable(AsanNoinstTest # FIXME: .arch?
$<TARGET_OBJECTS:RTAsan.${arch}>
+ $<TARGET_OBJECTS:RTAsan_static.${arch}>
$<TARGET_OBJECTS:RTInterception.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
More information about the cfe-commits
mailing list