diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -842,6 +842,10 @@ 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 --- 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 --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -34,7 +34,6 @@ if (NOT WIN32 AND NOT APPLE) list(APPEND ASAN_SOURCES - asan_rtl_x86_64.S asan_interceptors_vfork.S ) endif() @@ -49,6 +48,7 @@ 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 --- a/compiler-rt/lib/asan/asan_interface.inc +++ b/compiler-rt/lib/asan/asan_interface.inc @@ -180,37 +180,3 @@ 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 --- 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",@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 @@ pop %rcx ;\ jl RLABEL(reg, op, 1, i);\ mov %##reg,%rdi ;\ - jmp __asan_report_##op##1@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 @@ pop %rcx ;\ jl RLABEL(reg, op, 2, i);\ mov %##reg,%rdi ;\ - jmp __asan_report_##op##2@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 @@ pop %rcx ;\ jl RLABEL(reg, op, 4, i);\ mov %##reg,%rdi ;\ - jmp __asan_report_##op##4@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 @@ #define ASAN_MEMORY_ACCESS_FAIL(reg, op, s, i) \ FLABEL(reg, op, s, i): ;\ mov %##reg,%rdi ;\ - jmp __asan_report_##op##s@PLT;\ + jmp __asan_report_##op##s##_asm;\ #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \ BEGINF(reg, op, 8, add) ;\