This is an archive of the discontinued LLVM Phabricator instance.

[MSan] factor userspace-specific declarations into createUserspaceApi(). NFC
ClosedPublic

Authored by glider on Jul 13 2018, 6:54 AM.

Details

Summary

This patch introduces createUserspaceApi() that creates function/global declarations for symbols used by MSan in the userspace.
This is a step towards the upcoming KMSAN implementation patch.

Diff Detail

Event Timeline

glider created this revision.Jul 13 2018, 6:54 AM
eugenis added inline comments.Jul 13 2018, 9:50 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
596

This should probably be a property of a module, not a compiler invocation.

glider added inline comments.Jul 13 2018, 10:02 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
596

We used to check for WarningFn value here, and are just using a special bool instead now.
It might be cleaner to make CallbacksInitialized a property of class MemorySanitizer, but how can it be a property of a module?

eugenis added inline comments.Jul 13 2018, 10:17 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
596

Just consider that this bool can become true only once in the compiler process. No matter how many modules are created.

Moving it to class MemorySanitizer sounds good.

In fact, a FunctionPass is not supposed to create new functions (which AFAIK includes function declarations) outside of doInitialization(). MSan breaks this assumption in a bunch of places...

glider updated this revision to Diff 155422.Jul 13 2018, 10:20 AM

Moved CallbackInitialized into class MemorySanitizer

eugenis accepted this revision.Jul 13 2018, 10:21 AM
This revision is now accepted and ready to land.Jul 13 2018, 10:21 AM
glider added inline comments.Jul 13 2018, 10:24 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
596

Just consider that this bool can become true only once in the compiler process. No matter how many modules are created.

IIRC we don't do that in other tools either, do we?

Moving it to class MemorySanitizer sounds good.

Done

In fact, a FunctionPass is not supposed to create new functions (which AFAIK includes function declarations) outside of doInitialization(). MSan breaks this assumption in a bunch of places...

We only create getAndInsertFunction() from initializeCallbacks().
Wonder if it's possible to just call it from doInitialization()

596

We only create getAndInsertFunction() from initializeCallbacks().

s/create/call

eugenis added inline comments.Jul 13 2018, 10:29 AM
lib/Transforms/Instrumentation/MemorySanitizer.cpp
596

IIRC we don't do that in other tools either, do we?

Do what?

We only create getAndInsertFunction() from initializeCallbacks().
Wonder if it's possible to just call it from doInitialization()

Yes, but only if at least on function in the module has sanitize_memory attribute.
We also mess with other functions attributes in visitCallSite(), and that can not be done ahead of time because some other function pass may revert the change.

Landed r337155.

glider closed this revision.Jul 16 2018, 3:15 AM