[compiler-rt] 8b899e0 - [ASan] Added intermediate functions between assembly and __asan_report.* to avoid link errors.

Kirill Stoimenov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 2 16:31:51 PST 2022


Author: Kirill Stoimenov
Date: 2022-02-03T00:31:27Z
New Revision: 8b899e067e8a798296e9ada0a0a264b629bfa41b

URL: https://github.com/llvm/llvm-project/commit/8b899e067e8a798296e9ada0a0a264b629bfa41b
DIFF: https://github.com/llvm/llvm-project/commit/8b899e067e8a798296e9ada0a0a264b629bfa41b.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/asan/asan_rtl_static.cpp
    compiler-rt/lib/asan/asan_rtl_x86_64.S

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/asan/asan_rtl_static.cpp b/compiler-rt/lib/asan/asan_rtl_static.cpp
index 74e6eb0ddf1cf..a6f812bb89151 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 d27db745ed674..50e039e53d626 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 at 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 at 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 at 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 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 llvm-commits mailing list