[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
This commit is contained in:
Kirill Stoimenov 2022-02-02 17:57:58 +00:00
parent e72d715079
commit 8b899e067e
2 changed files with 25 additions and 4 deletions

View File

@ -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

View File

@ -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) ;\