- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
Rtsan/blocking 2 llvm pass #35
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
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 | 
|---|---|---|
|  | @@ -45,6 +45,26 @@ static void insertCallAtAllFunctionExitPoints(Function &Fn, | |
| insertCallBeforeInstruction(Fn, I, InsertFnName); | ||
| } | ||
|  | ||
| static PreservedAnalyses rtsanPreservedAnalyses() { | ||
| PreservedAnalyses PA; | ||
| PA.preserveSet<CFGAnalyses>(); | ||
| return PA; | ||
| } | ||
|  | ||
| static void transformRealtimeUnsafeFunction(Function &F) { | ||
| 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. Nit (take it or leave it): Transform is a little vague, could be more descriptive as to the actual transformation taking place 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. Thanks, agreed | ||
| IRBuilder<> Builder(&F.front().front()); | ||
| Value *NameArg = Builder.CreateGlobalString(F.getName()); | ||
|  | ||
| FunctionType *FuncType = | ||
| FunctionType::get(Type::getVoidTy(F.getContext()), | ||
| {PointerType::getUnqual(F.getContext())}, false); | ||
| 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. we should call reviewer eyes to this code when we post this so we make sure it is correct (not saying it isn't just that I have no clue about this code) | ||
|  | ||
| FunctionCallee Func = F.getParent()->getOrInsertFunction( | ||
| "__rtsan_expect_not_realtime", FuncType); | ||
|  | ||
| Builder.CreateCall(Func, {NameArg}); | ||
| } | ||
|  | ||
| RealtimeSanitizerPass::RealtimeSanitizerPass( | ||
| const RealtimeSanitizerOptions &Options) {} | ||
|  | ||
|  | @@ -53,10 +73,12 @@ PreservedAnalyses RealtimeSanitizerPass::run(Function &F, | |
| if (F.hasFnAttribute(Attribute::SanitizeRealtime)) { | ||
| insertCallAtFunctionEntryPoint(F, "__rtsan_realtime_enter"); | ||
| insertCallAtAllFunctionExitPoints(F, "__rtsan_realtime_exit"); | ||
| return rtsanPreservedAnalyses(); | ||
| } | ||
|  | ||
| PreservedAnalyses PA; | ||
| PA.preserveSet<CFGAnalyses>(); | ||
| return PA; | ||
| if (F.hasFnAttribute(Attribute::SanitizeRealtimeUnsafe)) { | ||
| transformRealtimeUnsafeFunction(F); | ||
| return rtsanPreservedAnalyses(); | ||
| } | ||
|  | ||
| return PreservedAnalyses::all(); | ||
|  | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| ; RUN: opt < %s -passes=rtsan -S | FileCheck %s | ||
|  | ||
| define void @blocking_function() #0 { | ||
| ret void | ||
| } | ||
|  | ||
| define noundef i32 @main() #2 { | ||
| call void @blocking_function() #4 | ||
| ret i32 0 | ||
| } | ||
|  | ||
| attributes #0 = { mustprogress noinline sanitize_realtime_unsafe optnone ssp uwtable(sync) } | ||
|  | ||
| ; RealtimeSanitizer pass should insert __rtsan_expect_not_realtime at function entrypoint | ||
| ; CHECK-LABEL: @blocking_function() | ||
| ; CHECK-NEXT: call{{.*}}@__rtsan_expect_not_realtime({{ptr .*}}) | ||
| 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. nice one! | ||
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.
I would get rid of this function and leave these explicit. I think the loop changing we will do will not preserve CFG, so I think it is OK to just do this explicitly in our main block
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.
Hmm yeah - part of my refactoring in the main pass function was intended to have a sequence of:
... to express the intent that these transformations are mutually exclusive and return early. But now I'm thinking about it, it doesn't really need to be that way - and it's a bit early days to start those sorts of refactors. So yeah, I think I'll revert this as you suggest
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.
On second thoughts, we still need it in two places. I've updated the function name to be more explicit, though - you'll see this in my latest PR. When we no longer need it as part of the
sanitize_realtimepass, we can inline it then. I think it's better to keep it in this case, don't you?