[clang] dd67e69 - [ASan] Reland of D116182 to always link asan_static library.
Kirill Stoimenov via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 24 12:32:40 PDT 2022
Author: Kirill Stoimenov
Date: 2022-03-24T19:32:23Z
New Revision: dd67e6972f85b4f0d00f7c68aea857b09e7a0b8a
URL: https://github.com/llvm/llvm-project/commit/dd67e6972f85b4f0d00f7c68aea857b09e7a0b8a
DIFF: https://github.com/llvm/llvm-project/commit/dd67e6972f85b4f0d00f7c68aea857b09e7a0b8a.diff
LOG: [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
Added:
Modified:
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/sanitizer-ld.c
compiler-rt/lib/asan/CMakeLists.txt
compiler-rt/lib/asan/asan_interface.inc
compiler-rt/lib/asan/asan_rtl_x86_64.S
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 156821a6e7854..b9efb6b77f074 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -849,6 +849,10 @@ 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 9a7a7db284c5d..966edbd7d038b 100644
--- a/clang/test/Driver/sanitizer-ld.c
+++ b/clang/test/Driver/sanitizer-ld.c
@@ -30,6 +30,7 @@
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
// RUN: | FileCheck --check-prefix=CHECK-ASAN-EXECUTABLE-LINUX %s
//
+// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan_static-x86_64
// CHECK-ASAN-EXECUTABLE-LINUX: libclang_rt.asan-x86_64
// RUN: %clang -fsanitize=address -shared %s -### -o %t.o 2>&1 \
@@ -38,6 +39,7 @@
// RUN: --sysroot=%S/Inputs/basic_linux_tree \
// RUN: | FileCheck --check-prefix=CHECK-ASAN-SHARED-LINUX %s
//
+// CHECK-ASAN-SHARED-LINUX: libclang_rt.asan_static-x86_64
// CHECK-ASAN-SHARED-LINUX-NOT: libclang_rt.asan-x86_64
// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index 0862a3d648fa2..0e7250a8fa10b 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()
@@ -49,6 +48,7 @@ set(ASAN_STATIC_SOURCES
if (NOT WIN32 AND NOT APPLE)
list(APPEND ASAN_STATIC_SOURCES
+ asan_rtl_x86_64.S
)
endif()
diff --git a/compiler-rt/lib/asan/asan_interface.inc b/compiler-rt/lib/asan/asan_interface.inc
index e9e7accf1675e..89ef552b71173 100644
--- a/compiler-rt/lib/asan/asan_interface.inc
+++ b/compiler-rt/lib/asan/asan_interface.inc
@@ -180,37 +180,3 @@ INTERFACE_FUNCTION(__asan_update_allocation_context)
INTERFACE_WEAK_FUNCTION(__asan_default_options)
INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
INTERFACE_WEAK_FUNCTION(__asan_on_error)
-
-#if defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
-# define ASAN_MEMORY_ACCESS_CALLBACK_ADD(s, reg, op) \
- INTERFACE_FUNCTION(__asan_check_##op##_add_##s##_##reg)
-
-# define ASAN_MEMORY_ACCESS_CALLBACKS_ADD(reg) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, load) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(1, reg, store) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, load) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(2, reg, store) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, load) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(4, reg, store) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, load) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(8, reg, store) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, load) \
- ASAN_MEMORY_ACCESS_CALLBACK_ADD(16, reg, store)
-
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RAX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RCX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDX)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RSI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RDI)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(RBP)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R8)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R9)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R12)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R13)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R14)
-ASAN_MEMORY_ACCESS_CALLBACKS_ADD(R15)
-
-#endif // defined(__x86_64__) && !defined(__APPLE__) && !defined(_WIN32)
-
diff --git a/compiler-rt/lib/asan/asan_rtl_x86_64.S b/compiler-rt/lib/asan/asan_rtl_x86_64.S
index e5e5fc440da5b..d93b5ed2a7fe3 100644
--- a/compiler-rt/lib/asan/asan_rtl_x86_64.S
+++ b/compiler-rt/lib/asan/asan_rtl_x86_64.S
@@ -16,6 +16,7 @@
#define BEGINF(reg, op, s, i) \
.section .text.FNAME(reg, op, s, i),"ax", at progbits ;\
.globl FNAME(reg, op, s, i) ;\
+.hidden FNAME(reg, op, s, i) ;\
ASM_TYPE_FUNCTION(FNAME(reg, op, s, i)) ;\
.cfi_startproc ;\
FNAME(reg, op, s, i): ;\
@@ -41,7 +42,7 @@ CLABEL(reg, op, 1, i): ;\
pop %rcx ;\
jl RLABEL(reg, op, 1, i);\
mov %##reg,%rdi ;\
- jmp __asan_report_##op##1 at PLT ;\
+ jmp __asan_report_##op##1_asm ;\
#define ASAN_MEMORY_ACCESS_EXTRA_CHECK_2(reg, op, i) \
CLABEL(reg, op, 2, i): ;\
@@ -53,7 +54,7 @@ CLABEL(reg, op, 2, i): ;\
pop %rcx ;\
jl RLABEL(reg, op, 2, i);\
mov %##reg,%rdi ;\
- jmp __asan_report_##op##2 at PLT ;\
+ jmp __asan_report_##op##2_asm ;\
#define ASAN_MEMORY_ACCESS_EXTRA_CHECK_4(reg, op, i) \
CLABEL(reg, op, 4, i): ;\
@@ -65,7 +66,7 @@ CLABEL(reg, op, 4, i): ;\
pop %rcx ;\
jl RLABEL(reg, op, 4, i);\
mov %##reg,%rdi ;\
- jmp __asan_report_##op##4 at PLT ;\
+ jmp __asan_report_##op##4_asm ;\
#define ASAN_MEMORY_ACCESS_CALLBACK_ADD_1(reg, op) \
BEGINF(reg, op, 1, add) ;\
@@ -96,7 +97,7 @@ ENDF
#define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \
FLABEL(reg, op, s, i): ;\
mov %##reg,%rdi ;\
- jmp __asan_report_##op##s at PLT;\
+ jmp __asan_report_##op##s##_asm;\
#define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \
BEGINF(reg, op, 8, add) ;\
More information about the cfe-commits
mailing list