[PATCH] D28500: [asan] Make ASan compatible with linker dead stripping on Linux, compiler-rt part
Evgeniy Stepanov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 9 16:26:06 PST 2017
eugenis created this revision.
eugenis added reviewers: pcc, rnk.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.
Herald added subscribers: dberris, kubabrecka.
This is the compiler-rt part of https://reviews.llvm.org/D28498
Repository:
rL LLVM
https://reviews.llvm.org/D28500
Files:
lib/asan/asan_globals.cc
lib/asan/asan_interface_internal.h
test/asan/TestCases/Linux/globals-gc-sections-lld.cc
test/asan/TestCases/Linux/globals-gc-sections.cc
Index: test/asan/TestCases/Linux/globals-gc-sections.cc
===================================================================
--- test/asan/TestCases/Linux/globals-gc-sections.cc
+++ test/asan/TestCases/Linux/globals-gc-sections.cc
@@ -1,11 +1,15 @@
-// RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -ffunction-sections -mllvm -asan-globals=0
-// RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -ffunction-sections -mllvm -asan-globals=1
+// RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -fuse-ld=bfd -ffunction-sections -fdata-sections -mllvm -asan-globals=0
+// RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -fuse-ld=bfd -ffunction-sections -fdata-sections -mllvm -asan-globals=1
// https://code.google.com/p/address-sanitizer/issues/detail?id=260
-// XFAIL: *
int undefined();
+// bug in ld.bfd: with multiple "asan_globals" sections, __start_asan_globals is
+// treated as a strong GC reference to the first such section. As a result, the
+// first (for some definition of the word) global is never gc-ed.
+int first_unused = 42;
+
int (*unused)() = undefined;
int main() {
Index: test/asan/TestCases/Linux/globals-gc-sections-lld.cc
===================================================================
--- /dev/null
+++ test/asan/TestCases/Linux/globals-gc-sections-lld.cc
@@ -0,0 +1,14 @@
+// RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -fuse-ld=lld -ffunction-sections -fdata-sections -mllvm -asan-globals=0
+// RUN: %clangxx_asan %s -o %t -Wl,--gc-sections -fuse-ld=lld -ffunction-sections -fdata-sections -mllvm -asan-globals=1
+
+// https://code.google.com/p/address-sanitizer/issues/detail?id=260
+
+// REQUIRES: lld
+
+int undefined();
+
+int (*unused)() = undefined;
+
+int main() {
+ return 0;
+}
Index: lib/asan/asan_interface_internal.h
===================================================================
--- lib/asan/asan_interface_internal.h
+++ lib/asan/asan_interface_internal.h
@@ -67,6 +67,11 @@
SANITIZER_INTERFACE_ATTRIBUTE
void __asan_unregister_image_globals(uptr *flag);
+ SANITIZER_INTERFACE_ATTRIBUTE
+ void __asan_register_elf_globals(uptr *flag, void *start, void *stop);
+ SANITIZER_INTERFACE_ATTRIBUTE
+ void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop);
+
// These two functions should be called by the instrumented code.
// 'globals' is an array of structures describing 'n' globals.
SANITIZER_INTERFACE_ATTRIBUTE
Index: lib/asan/asan_globals.cc
===================================================================
--- lib/asan/asan_globals.cc
+++ lib/asan/asan_globals.cc
@@ -332,6 +332,26 @@
*flag = 0;
}
+void __asan_register_elf_globals(uptr *flag, void *start, void *stop) {
+ if (*flag) return;
+ if (!start) return;
+ CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
+ __asan_global *globals_start = (__asan_global*)start;
+ __asan_global *globals_stop = (__asan_global*)stop;
+ __asan_register_globals(globals_start, globals_stop - globals_start);
+ *flag = 1;
+}
+
+void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop) {
+ if (!*flag) return;
+ if (!start) return;
+ CHECK_EQ(0, ((uptr)stop - (uptr)start) % sizeof(__asan_global));
+ __asan_global *globals_start = (__asan_global*)start;
+ __asan_global *globals_stop = (__asan_global*)stop;
+ __asan_unregister_globals(globals_start, globals_stop - globals_start);
+ *flag = 0;
+}
+
// Register an array of globals.
void __asan_register_globals(__asan_global *globals, uptr n) {
if (!flags()->report_globals) return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28500.83734.patch
Type: text/x-patch
Size: 3530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170110/b2b97afc/attachment.bin>
More information about the llvm-commits
mailing list