[PATCH] D20541: [esan|cfrag] Create the cfrag variable for the runtime
Filipe Cabecinhas via llvm-commits
llvm-commits at lists.llvm.org
Wed May 25 06:57:45 PDT 2016
filcab added a subscriber: filcab.
filcab added a comment.
Please add a test for the cache fragmentation tool's global variable.
================
Comment at: lib/Transforms/Instrumentation/EfficiencySanitizer.cpp:207
@@ +206,3 @@
+ // struct CacheFragTy {
+ // int ToolType;
+ // const char *UnitName;
----------------
I don't really see a reason to include the tool type here. We're already emitting it in the call to `__esan_init`.
================
Comment at: lib/Transforms/Instrumentation/EfficiencySanitizer.cpp:226
@@ +225,3 @@
+ nullptr));
+ return CacheFragGV;
+}
----------------
I'd rather have a more abstract version of this that just creates an anonymous structure, and then each tool knows what to do with it.
A bit like what UBSan does in clang.
Check out clang's `lib/CodeGen/CGExpr.cpp`
Create the array and then call EmitCheck (line 585):
```
llvm::Constant *StaticData[] = {
EmitCheckSourceLocation(E->getLocStart()),
EmitCheckTypeDescriptor(CalleeType)
};
EmitCheck(Checks, "type_mismatch", StaticData, Ptr);
```
In EmitCheck, we have a common way to emit the static args:
```
// Emit handler arguments and create handler function type.
if (!StaticArgs.empty()) {
llvm::Constant *Info = llvm::ConstantStruct::getAnon(StaticArgs);
auto *InfoPtr =
new llvm::GlobalVariable(CGM.getModule(), Info->getType(), false,
llvm::GlobalVariable::PrivateLinkage, Info);
InfoPtr->setUnnamedAddr(true);
CGM.getSanitizerMetadata()->disableSanitizerForGlobal(InfoPtr);
Args.push_back(Builder.CreateBitCast(InfoPtr, Int8PtrTy));
ArgTypes.push_back(Int8PtrTy);
}
```
That way, each tool can just create the ArrayRef and pass it to a general `createToolGV` or something.
`__esan_init` would get the two args: `ToolType` and a `void*` which is tool specific.
http://reviews.llvm.org/D20541
More information about the llvm-commits
mailing list