summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2018-12-20 10:05:00 +0000
committerAlexander Potapenko <glider@google.com>2018-12-20 10:05:00 +0000
commit0e3b85a730bc3ef2bcbc22bff33678005df9bafa (patch)
treeef3ef9f3fce9306403be164adabfd10ce8e96cb9 /llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
parente22cf4d7cb2e33d05d564932342023ec376a88fc (diff)
downloadbcm5719-llvm-0e3b85a730bc3ef2bcbc22bff33678005df9bafa.tar.gz
bcm5719-llvm-0e3b85a730bc3ef2bcbc22bff33678005df9bafa.zip
[MSan] Don't emit __msan_instrument_asm_load() calls
LLVM treats void* pointers passed to assembly routines as pointers to sized types. We used to emit calls to __msan_instrument_asm_load() for every such void*, which sometimes led to false positives. A less error-prone (and truly "conservative") approach is to unpoison only assembly output arguments. llvm-svn: 349734
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp14
1 files changed, 4 insertions, 10 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index 0bbf3a90b95..1fad7fc6381 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -99,9 +99,8 @@
/// also possible that the arguments only indicate the offset for a base taken
/// from a segment register, so it's dangerous to treat any asm() arguments as
/// pointers. We take a conservative approach generating calls to
-/// __msan_instrument_asm_load(ptr, size) and
/// __msan_instrument_asm_store(ptr, size)
-/// , which defer the memory checking/unpoisoning to the runtime library.
+/// , which defer the memory unpoisoning to the runtime library.
/// The latter can perform more complex address checks to figure out whether
/// it's safe to touch the shadow memory.
/// Like with atomic operations, we call __msan_instrument_asm_store() before
@@ -570,7 +569,7 @@ private:
Value *MsanMetadataPtrForLoadN, *MsanMetadataPtrForStoreN;
Value *MsanMetadataPtrForLoad_1_8[4];
Value *MsanMetadataPtrForStore_1_8[4];
- Value *MsanInstrumentAsmStoreFn, *MsanInstrumentAsmLoadFn;
+ Value *MsanInstrumentAsmStoreFn;
/// Helper to choose between different MsanMetadataPtrXxx().
Value *getKmsanShadowOriginAccessFn(bool isStore, int size);
@@ -779,9 +778,6 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
StringRef(""), StringRef(""),
/*hasSideEffects=*/true);
- MsanInstrumentAsmLoadFn =
- M.getOrInsertFunction("__msan_instrument_asm_load", IRB.getVoidTy(),
- PointerType::get(IRB.getInt8Ty(), 0), IntptrTy);
MsanInstrumentAsmStoreFn =
M.getOrInsertFunction("__msan_instrument_asm_store", IRB.getVoidTy(),
PointerType::get(IRB.getInt8Ty(), 0), IntptrTy);
@@ -3482,19 +3478,17 @@ struct MemorySanitizerVisitor : public InstVisitor<MemorySanitizerVisitor> {
Type *OpType = Operand->getType();
// Check the operand value itself.
insertShadowCheck(Operand, &I);
- if (!OpType->isPointerTy()) {
+ if (!OpType->isPointerTy() || !isOutput) {
assert(!isOutput);
return;
}
- Value *Hook =
- isOutput ? MS.MsanInstrumentAsmStoreFn : MS.MsanInstrumentAsmLoadFn;
Type *ElType = OpType->getPointerElementType();
if (!ElType->isSized())
return;
int Size = DL.getTypeStoreSize(ElType);
Value *Ptr = IRB.CreatePointerCast(Operand, IRB.getInt8PtrTy());
Value *SizeVal = ConstantInt::get(MS.IntptrTy, Size);
- IRB.CreateCall(Hook, {Ptr, SizeVal});
+ IRB.CreateCall(MS.MsanInstrumentAsmStoreFn, {Ptr, SizeVal});
}
/// Get the number of output arguments returned by pointers.
OpenPOWER on IntegriCloud