[clang] [clang][rtsan] Introduce realtime sanitizer clang codegen and -fsanitize flag (PR #100192)

via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 23 15:32:10 PDT 2024


================
@@ -1410,6 +1414,35 @@ QualType CodeGenFunction::BuildFunctionArgList(GlobalDecl GD,
   return ResTy;
 }
 
+void InsertCallBeforeInstruction(llvm::Function *Fn,
----------------
davidtrevelyan wrote:

I can add a bit of context here on some attempts we made implementing the insertion in codegen vs. in a pass. 

In the very first implementation of rtsan, we did actually implement the insertion of `__rtsan_realtime_enter()` and `__rtsan_realtime_exit()` in a pass. We thought at the time that this insertion was only possible in a pass if the `nonblocking` attribute was added to the function in its IR. This method seemed to work fine until we activated optimisation level `-O1`, at which point we found that our attribute in the IR was disappearing, presumably from some sort of DCE (but we weren't sure), before we had a chance to inject our function calls. This, of course, broke our code injection. Someone on the LLVM Discord server pointed out that it was possible to do what we wanted to do entirely at CodeGen time, so we pivoted our approach towards doing so. 

@vitalybuka and @MaskRay, what would you recommend here? Are the problems that we experienced originally with the pass implementation surmountable? We also questioned whether we should be injecting early (before optimisations) or late (after optimisations). Our first assumption was that early was better (less risk of inlining optimisations breaking our realtime depth tracking?), but we're very keen to learn from your expert opinions here.

https://github.com/llvm/llvm-project/pull/100192


More information about the cfe-commits mailing list