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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Other than __asan_report.*_asm intermediate functions the @PLT is removed from the assembly code.
The @PLT modifier does not matter for x86-64. @PLT for jmp/call is ignored anyway since the integrated assembler switched from R_X86_64_PC32 to R_X86_64_PLT32.
Added intermediate functions between assembly and __asan_report.* to avoid link errors.
Do you mind more information to clarify how the link error (which diagnostic?) is avoided?
compiler-rt/lib/asan/asan_rtl_static.cpp | ||
---|---|---|
20 | WEAK_DEF may be misleading because the declared symbol (__asan_report_load1) is not a definition. Consider just write extern "C" SANITIZER_WEAK_ATTRIBUTE |
- https://reviews.llvm.org/D107850 outlined some instrumented code sequences to __asan_check_* functions
- -fsanitize-address-outline-instrumentation -mllvm -asan-optimize-callbacks=1 teaches the asan instrumentation to call __asan_check_*
- https://reviews.llvm.org/D114558 implemented these __asan_check_* functions in libclang_rt.asan-static.a. They were later changed to hidden visibility to avoid PLT
- A __asan_check_* function may call __asan_report_* in libclang_rt.asan.a
When linking a shared object, libclang_rt.asan-static.a may bring in some resolved undefined symbols, causing a --no-undefined (-z defs) link to fail.
This patch changes the symbol table entries
% egrep 'load8|load_add_8_RAX' asan_static.txt 15: 000000000000011a 0 NOTYPE LOCAL DEFAULT 2 .fail_load_add_8_RAX 227: 0000000000000108 0 FUNC GLOBAL HIDDEN 2 __asan_check_load_add_8_RAX 228: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __asan_report_load8
to
% egrep 'load8|load_add_8_RAX' asan_static.new.txt 5: 0000000000000000 0 SECTION LOCAL DEFAULT 9 .text.__asan_report_load8_asm 25: 0000000000000000 5 FUNC GLOBAL HIDDEN 9 __asan_report_load8_asm 26: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __asan_report_load8 15: 000000000000011a 0 NOTYPE LOCAL DEFAULT 2 .fail_load_add_8_RAX 227: 0000000000000108 0 FUNC GLOBAL HIDDEN 2 __asan_check_load_add_8_RAX 228: 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND __asan_report_load8_asm
Since the call to __asan_report_load8 is now weak, the linker will not error for --no-undefined (-z defs).
So, the patch LGTM, but it needs some clarification.
Added intermediate functions between assembly and __asan_report.* to avoid link errors.
The main difference is not intermediate functions, but weak references to functions defined in asan.a (e.g. __asan_report_load8) to fix --no-undefined linker errors.
WEAK_DEF may be misleading because the declared symbol (__asan_report_load1) is not a definition.
Consider just write extern "C" SANITIZER_WEAK_ATTRIBUTE