[PATCH] D77477: tsan: don't instrument __attribute__((naked)) functions
Anton Bikineev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 4 14:22:24 PDT 2020
AntonBikineev created this revision.
AntonBikineev added reviewers: kcc, dvyukov.
AntonBikineev added a project: LLVM.
Herald added a subscriber: hiraditya.
Naked functions must not have compiler generated prologues/epilogues, hence no instrumentation is needed for them.
I was not sure whether to disable instrumentation for an entire function or only for prologues/epilogues (__tsan_func_entry/__tsan_func_exit), but I assumed that the latter would probably be incorrect. Please let me if you think this is wrong.
FWIW, from the C/C++ frontend point of view, naked functions can only contain inline assembly.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77477
Files:
llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
Index: llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
===================================================================
--- llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
+++ llvm/test/Instrumentation/ThreadSanitizer/tsan_basic.ll
@@ -78,5 +78,18 @@
call void @SwiftError(i8** %0)
ret void
}
+
+; CHECK-LABEL: @NakedTest(i32* %a)
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: %tmp1 = load i32, i32* %a, align 4
+; CHECK-NEXT: ret i32 %tmp1
+define i32 @NakedTest(i32* %a) naked sanitize_thread {
+ call void @foo()
+ %tmp1 = load i32, i32* %a, align 4
+ ret i32 %tmp1
+}
+
+declare void @foo() nounwind
+
; CHECK: define internal void @tsan.module_ctor()
; CHECK: call void @__tsan_init()
Index: llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
+++ llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp
@@ -441,6 +441,11 @@
// the module constructor.
if (F.getName() == kTsanModuleCtorName)
return false;
+ // Naked functions can not have prologue/epilogue
+ // (__tsan_func_entry/__tsan_func_exit) generated, so don't instrument them at
+ // all.
+ if (F.hasFnAttribute(Attribute::Naked))
+ return false;
initialize(*F.getParent());
SmallVector<Instruction*, 8> AllLoadsAndStores;
SmallVector<Instruction*, 8> LocalLoadsAndStores;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77477.255077.patch
Type: text/x-patch
Size: 1435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200404/741092bd/attachment.bin>
More information about the llvm-commits
mailing list