This is an archive of the discontinued LLVM Phabricator instance.

[MSan] Introduce ActualFnStart. NFC
ClosedPublic

Authored by glider on Mar 15 2018, 3:57 AM.

Details

Summary

This is a step towards the upcoming KMSAN implementation patch.
KMSAN is going to prepend a special basic block containing tool-specific calls to each function. Because we still want to instrument the original entry block, we'll need to store it in ActualFnStart.
For MSan this will still be F.getEntryBlock(), whereas for KMSAN it'll contain the second BB.

Diff Detail

Repository
rL LLVM

Event Timeline

glider created this revision.Mar 15 2018, 3:57 AM

What kind of code will this basic block contain? Can it be created later, at the end of instrumentation pass?

This basic block will contain a runtime call, which provides addresses of TLS structs used later in the instrumentation.
If we insert the call late, we'll have to fix all the users of its return values, which is trickier than inserting the call in advance.

vitalybuka added inline comments.Mar 21 2018, 1:26 PM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
741

can you initialize ActualFnStart here?

eugenis accepted this revision.Mar 23 2018, 3:27 PM

Please address Vitaly's comment.

This revision is now accepted and ready to land.Mar 23 2018, 3:27 PM
glider added inline comments.Mar 26 2018, 1:48 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
741

Note that this code will finally look like:

if (MS.CompileKernel)
  ActualFnStart = insertKmsanPrologue(F);
else
  ActualFnStart = &F.getEntryBlock();

, so we'll be basically performing some instrumentation in the constructor instead of runOnFunction().
If you're fine with that, I'll proceed, but the ActualFnStart initialization needs to be performed after setting InsertChecks, PropagateShadow, PoisonStack etc., i.e. at the very end of the constructor.
Also, we'll have to move MS.initializeCallbacks(*F.getParent()); into the constructor as well.

glider closed this revision.Mar 28 2018, 4:40 AM

I've moved the initialization of ActualFnStart and callbacks to the end of the constructor and landed r328697.