-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[rtsan] Handle attributed IR function declarations #169577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,23 +61,21 @@ static void insertCallAtAllFunctionExitPoints(Function &Fn, | |
| insertCallBeforeInstruction(Fn, I, InsertFnName, FunctionArgs); | ||
| } | ||
|
|
||
| static PreservedAnalyses rtsanPreservedCFGAnalyses() { | ||
| PreservedAnalyses PA; | ||
| PA.preserveSet<CFGAnalyses>(); | ||
| return PA; | ||
| } | ||
| static void runSanitizeRealtime(Function &Fn) { | ||
| if (Fn.empty()) | ||
| return; | ||
|
|
||
| static PreservedAnalyses runSanitizeRealtime(Function &Fn) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is not returning these preserved analyses going to bite us elsewhere? I remember most of the sanitizer transform passes (or transform passes generally) returning these.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps! But the issue is we're already not returning these preserved analyses - they're sadly discarded at the moment. I would advocate for this NFC because it makes the current behaviour explicit - even if it's not correct. I bundled this change in with this PR because it made the implementation of the checking a bit easier, but I'd be happy to submit this in a separate preparatory PR first - if that's easier to follow - just let me know. |
||
| insertCallAtFunctionEntryPoint(Fn, "__rtsan_realtime_enter", {}); | ||
| insertCallAtAllFunctionExitPoints(Fn, "__rtsan_realtime_exit", {}); | ||
| return rtsanPreservedCFGAnalyses(); | ||
| } | ||
|
|
||
| static PreservedAnalyses runSanitizeRealtimeBlocking(Function &Fn) { | ||
| static void runSanitizeRealtimeBlocking(Function &Fn) { | ||
| if (Fn.empty()) | ||
| return; | ||
|
|
||
| IRBuilder<> Builder(&Fn.front().front()); | ||
| Value *Name = Builder.CreateGlobalString(demangle(Fn.getName())); | ||
| insertCallAtFunctionEntryPoint(Fn, "__rtsan_notify_blocking_call", {Name}); | ||
| return rtsanPreservedCFGAnalyses(); | ||
| } | ||
|
|
||
| PreservedAnalyses RealtimeSanitizerPass::run(Module &M, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ; RUN: opt < %s -passes='rtsan' -S | FileCheck %s | ||
|
|
||
| declare void @declared_realtime_function() sanitize_realtime #0 | ||
|
|
||
| declare void @declared_blocking_function() sanitize_realtime_blocking #0 | ||
|
|
||
| ; RealtimeSanitizer pass should ignore attributed functions that are just declarations | ||
| ; CHECK: declared_realtime_function | ||
| ; CHECK-EMPTY: | ||
| ; CHECK: declared_blocking_function | ||
| ; CHECK-EMPTY: | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there precedence in other sanitizer passes for doing this? (Curious how they solved this problem)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the good idea. I hadn't looked before drafting this PR, but it appears like ASan solves it a similar way at one level higher - at the top level of the pass's
runmethod:llvm-project/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
Line 1318 in f5742c4
ThreadSanitizer has a
boolcheck for whether it shouldsanitizeFunction, which returns false if there are no calls in it. MemorySanitizer does the same thing as AddressSanitizer with acontinueat the top level if the function is.empty().If you prefer the ASan/MSan semantics I'm very happy to switch to it 👍