Skip to content

Commit 71b3bfd

Browse files
committed
[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
1 parent 735fe1d commit 71b3bfd

File tree

5 files changed

+55
-2
lines changed

5 files changed

+55
-2
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,11 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
826826
if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
827827
StaticRuntimes.push_back("stats_client");
828828

829+
// Always link the static runtime regardless of DSO or executable.
830+
if (SanArgs.needsAsanRt()) {
831+
HelperStaticRuntimes.push_back("asan_static");
832+
}
833+
829834
// Collect static runtimes.
830835
if (Args.hasArg(options::OPT_shared)) {
831836
// Don't link static runtimes into DSOs.

clang/test/Driver/sanitizer-ld.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
2323
// RUN: | FileCheck --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-LINUX %s
2424
//
25-
// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan
25+
// CHECK-ASAN-NO-LINK-RUNTIME-LINUX-NOT: libclang_rt.asan-x86_64
2626

2727
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
2828
// RUN: -target i386-unknown-linux -fuse-ld=ld -fsanitize=address -shared-libsan \

compiler-rt/lib/asan/CMakeLists.txt

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ set(ASAN_SOURCES
3434

3535
if (NOT WIN32 AND NOT APPLE)
3636
list(APPEND ASAN_SOURCES
37-
asan_rtl_x86_64.S
3837
asan_interceptors_vfork.S
3938
)
4039
endif()
@@ -43,6 +42,16 @@ set(ASAN_CXX_SOURCES
4342
asan_new_delete.cpp
4443
)
4544

45+
set(ASAN_STATIC_SOURCES
46+
asan_rtl_static.cpp
47+
)
48+
49+
if (NOT WIN32 AND NOT APPLE)
50+
list(APPEND ASAN_STATIC_SOURCES
51+
asan_rtl_x86_64.S
52+
)
53+
endif()
54+
4655
set(ASAN_PREINIT_SOURCES
4756
asan_preinit.cpp
4857
)
@@ -135,6 +144,12 @@ if(NOT APPLE)
135144
ADDITIONAL_HEADERS ${ASAN_HEADERS}
136145
CFLAGS ${ASAN_CFLAGS}
137146
DEFS ${ASAN_COMMON_DEFINITIONS})
147+
add_compiler_rt_object_libraries(RTAsan_static
148+
ARCHS ${ASAN_SUPPORTED_ARCH}
149+
SOURCES ${ASAN_STATIC_SOURCES}
150+
ADDITIONAL_HEADERS ${ASAN_HEADERS}
151+
CFLAGS ${ASAN_CFLAGS}
152+
DEFS ${ASAN_COMMON_DEFINITIONS})
138153
add_compiler_rt_object_libraries(RTAsan_preinit
139154
ARCHS ${ASAN_SUPPORTED_ARCH}
140155
SOURCES ${ASAN_PREINIT_SOURCES}
@@ -176,6 +191,14 @@ if(APPLE)
176191
LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
177192
DEFS ${ASAN_DYNAMIC_DEFINITIONS}
178193
PARENT_TARGET asan)
194+
195+
add_compiler_rt_runtime(clang_rt.asan_static
196+
STATIC
197+
ARCHS ${ASAN_SUPPORTED_ARCH}
198+
OBJECT_LIBS RTAsan_static
199+
CFLAGS ${ASAN_CFLAGS}
200+
DEFS ${ASAN_COMMON_DEFINITIONS}
201+
PARENT_TARGET asan)
179202
else()
180203
# Build separate libraries for each target.
181204

@@ -207,6 +230,14 @@ else()
207230
DEFS ${ASAN_COMMON_DEFINITIONS}
208231
PARENT_TARGET asan)
209232

233+
add_compiler_rt_runtime(clang_rt.asan_static
234+
STATIC
235+
ARCHS ${ASAN_SUPPORTED_ARCH}
236+
OBJECT_LIBS RTAsan_static
237+
CFLAGS ${ASAN_CFLAGS}
238+
DEFS ${ASAN_COMMON_DEFINITIONS}
239+
PARENT_TARGET asan)
240+
210241
add_compiler_rt_runtime(clang_rt.asan-preinit
211242
STATIC
212243
ARCHS ${ASAN_SUPPORTED_ARCH}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//===-- asan_static_rtl.cpp -----------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file is a part of AddressSanitizer, an address sanity checker.
10+
//
11+
// Main file of the ASan run-time library.
12+
//===----------------------------------------------------------------------===//
13+
14+
// This file is empty for now. Main reason to have it is workaround for Windows
15+
// build, which complains because no files are part of the asan_static lib.

compiler-rt/lib/asan/tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
261261
set(ASAN_TEST_RUNTIME_OBJECTS
262262
$<TARGET_OBJECTS:RTAsan.${arch}>
263263
$<TARGET_OBJECTS:RTAsan_cxx.${arch}>
264+
$<TARGET_OBJECTS:RTAsan_static.${arch}>
264265
$<TARGET_OBJECTS:RTInterception.${arch}>
265266
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
266267
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
@@ -286,6 +287,7 @@ if(ANDROID)
286287
# Test w/o ASan instrumentation. Link it with ASan statically.
287288
add_executable(AsanNoinstTest # FIXME: .arch?
288289
$<TARGET_OBJECTS:RTAsan.${arch}>
290+
$<TARGET_OBJECTS:RTAsan_static.${arch}>
289291
$<TARGET_OBJECTS:RTInterception.${arch}>
290292
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
291293
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>

0 commit comments

Comments
 (0)