From 8b899e067e8a798296e9ada0a0a264b629bfa41b Mon Sep 17 00:00:00 2001 From: Kirill Stoimenov Date: Wed, 2 Feb 2022 17:57:58 +0000 Subject: [PATCH] [ASan] Added intermediate functions between assembly and __asan_report.* to avoid link errors. Instead of calling asan_report.* directly from assembly code they have been replaced with corresponding asan_report.*_asm function, which call asan_report.*. All asan_report.* are now undefined weak symbols, which allows DSOs to link when z defs is used. Reviewed By: MaskRay, morehouse Differential Revision: https://reviews.llvm.org/D118813 --- compiler-rt/lib/asan/asan_rtl_static.cpp | 21 +++++++++++++++++++++ compiler-rt/lib/asan/asan_rtl_x86_64.S | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/asan/asan_rtl_static.cpp b/compiler-rt/lib/asan/asan_rtl_static.cpp index 74e6eb0ddf1c..a6f812bb8915 100644 --- a/compiler-rt/lib/asan/asan_rtl_static.cpp +++ b/compiler-rt/lib/asan/asan_rtl_static.cpp @@ -13,3 +13,24 @@ // This file is empty for now. Main reason to have it is workaround for Windows // build, which complains because no files are part of the asan_static lib. + +#include "sanitizer_common/sanitizer_common.h" + +#define REPORT_FUNCTION(Name) \ + extern "C" SANITIZER_WEAK_ATTRIBUTE void Name(__asan::uptr addr); \ + extern "C" void Name##_asm(uptr addr) { Name(addr); } + +namespace __asan { + +REPORT_FUNCTION(__asan_report_load1) +REPORT_FUNCTION(__asan_report_load2) +REPORT_FUNCTION(__asan_report_load4) +REPORT_FUNCTION(__asan_report_load8) +REPORT_FUNCTION(__asan_report_load16) +REPORT_FUNCTION(__asan_report_store1) +REPORT_FUNCTION(__asan_report_store2) +REPORT_FUNCTION(__asan_report_store4) +REPORT_FUNCTION(__asan_report_store8) +REPORT_FUNCTION(__asan_report_store16) + +} // namespace __asan diff --git a/compiler-rt/lib/asan/asan_rtl_x86_64.S b/compiler-rt/lib/asan/asan_rtl_x86_64.S index d27db745ed67..50e039e53d62 100644 --- a/compiler-rt/lib/asan/asan_rtl_x86_64.S +++ b/compiler-rt/lib/asan/asan_rtl_x86_64.S @@ -42,7 +42,7 @@ CLABEL(reg, op, 1, i): ;\ 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): ;\ @@ -54,7 +54,7 @@ CLABEL(reg, op, 2, i): ;\ 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): ;\ @@ -66,7 +66,7 @@ CLABEL(reg, op, 4, i): ;\ 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) ;\ @@ -97,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@PLT;\ + jmp __asan_report_##op##s##_asm;\ #define ASAN_MEMORY_ACCESS_CALLBACK_ADD_8(reg, op) \ BEGINF(reg, op, 8, add) ;\