Skip to content

Commit dd67e69

Browse files
committed
[ASan] Reland of D116182 to always link asan_static library.
After landing D121813 the binary size increase introduced by this change can be minimized by using --gc-sections link options. D121813 allows each individual callbacks to be optimized out if not used. Reviewed By: vitalybuka, MaskRay Differential Revision: https://reviews.llvm.org/D122407
1 parent 8705708 commit dd67e69

File tree

5 files changed

+12
-39
lines changed

5 files changed

+12
-39
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
849849
if (SanArgs.needsStatsRt() && SanArgs.linkRuntimes())
850850
StaticRuntimes.push_back("stats_client");
851851

852+
// Always link the static runtime regardless of DSO or executable.
853+
if (SanArgs.needsAsanRt())
854+
HelperStaticRuntimes.push_back("asan_static");
855+
852856
// Collect static runtimes.
853857
if (Args.hasArg(options::OPT_shared)) {
854858
// Don't link static runtimes into DSOs.

clang/test/Driver/sanitizer-ld.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
3131
// RUN: | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s
3232
//
33+
// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static-x86_64
3334
// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan-x86_64
3435

3536
// RUN: %clang -fsanitize=address -shared %s -### -o %t.o 2>&1 \
@@ -38,6 +39,7 @@
3839
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
3940
// RUN: | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s
4041
//
42+
// CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static-x86_64
4143
// CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan-x86_64
4244

4345
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \

compiler-rt/lib/asan/CMakeLists.txt

Lines changed: 1 addition & 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()
@@ -49,6 +48,7 @@ set(ASAN_STATIC_SOURCES
4948

5049
if (NOT WIN32 AND NOT APPLE)
5150
list(APPEND ASAN_STATIC_SOURCES
51+
asan_rtl_x86_64.S
5252
)
5353
endif()
5454

compiler-rt/lib/asan/asan_interface.inc

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -180,37 +180,3 @@ INTERFACE_FUNCTION(__asan_update_allocation_context)
180180
INTERFACE_WEAK_FUNCTION(__asan_default_options)
181181
INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
182182
INTERFACE_WEAK_FUNCTION(__asan_on_error)
183-
184-
#if defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
185-
186-
# define ASAN_MEMORY_ACCESS_CALLBACK_ADD(s, reg, op) \
187-
INTERFACE_FUNCTION(__asan_check_##op##_add_##s##_##reg)
188-
189-
# define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg) \
190-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, load) \
191-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, store) \
192-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, load) \
193-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, store) \
194-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, load) \
195-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, store) \
196-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, load) \
197-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, store) \
198-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, load) \
199-
ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, store)
200-
201-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
202-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
203-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
204-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
205-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
206-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
207-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
208-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
209-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
210-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
211-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
212-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
213-
ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
214-
215-
#endif // defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
216-

compiler-rt/lib/asan/asan_rtl_x86_64.S

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define BEGINF(reg, op, s, i) \
1717
.section .text.FNAME(reg, op, s, i),"ax",@progbits ;\
1818
.globl FNAME(reg, op, s, i) ;\
19+
.hidden FNAME(reg, op, s, i) ;\
1920
ASM_TYPE_FUNCTION(FNAME(reg, op, s, i)) ;\
2021
.cfi_startproc ;\
2122
FNAME(reg, op, s, i): ;\
@@ -41,7 +42,7 @@ CLABEL(reg, op, 1, i): ;\
4142
pop %rcx ;\
4243
jl RLABEL(reg, op, 1, i);\
4344
mov %##reg,%rdi ;\
44-
jmp __asan_report_##op##1@PLT ;\
45+
jmp __asan_report_##op##1_asm ;\
4546

4647
#define ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, i) \
4748
CLABEL(reg, op, 2, i): ;\
@@ -53,7 +54,7 @@ CLABEL(reg, op, 2, i): ;\
5354
pop %rcx ;\
5455
jl RLABEL(reg, op, 2, i);\
5556
mov %##reg,%rdi ;\
56-
jmp __asan_report_##op##2@PLT ;\
57+
jmp __asan_report_##op##2_asm ;\
5758

5859
#define ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, i) \
5960
CLABEL(reg, op, 4, i): ;\
@@ -65,7 +66,7 @@ CLABEL(reg, op, 4, i): ;\
6566
pop %rcx ;\
6667
jl RLABEL(reg, op, 4, i);\
6768
mov %##reg,%rdi ;\
68-
jmp __asan_report_##op##4@PLT ;\
69+
jmp __asan_report_##op##4_asm ;\
6970

7071
#define ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, op) \
7172
BEGINF(reg, op, 1, add) ;\
@@ -96,7 +97,7 @@ ENDF
9697
#define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \
9798
FLABEL(reg, op, s, i): ;\
9899
mov %##reg,%rdi ;\
99-
jmp __asan_report_##op##s@PLT;\
100+
jmp __asan_report_##op##s##_asm;\
100101

101102
#define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \
102103
BEGINF(reg, op, 8, add) ;\

0 commit comments

Comments
 (0)