mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-18 11:26:29 +00:00
[MSan] factor userspace-specific declarations into createUserspaceApi(). NFC
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. Reviewed at https://reviews.llvm.org/D49292 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@337155 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
249b255c78
commit
0f2a60eba6
@ -422,6 +422,7 @@ private:
|
|||||||
friend struct VarArgPowerPC64Helper;
|
friend struct VarArgPowerPC64Helper;
|
||||||
|
|
||||||
void initializeCallbacks(Module &M);
|
void initializeCallbacks(Module &M);
|
||||||
|
void createUserspaceApi(Module &M);
|
||||||
|
|
||||||
/// Track origins (allocation points) of uninitialized values.
|
/// Track origins (allocation points) of uninitialized values.
|
||||||
int TrackOrigins;
|
int TrackOrigins;
|
||||||
@ -455,8 +456,11 @@ private:
|
|||||||
/// function.
|
/// function.
|
||||||
GlobalVariable *OriginTLS;
|
GlobalVariable *OriginTLS;
|
||||||
|
|
||||||
|
/// Are the instrumentation callbacks set up?
|
||||||
|
bool CallbacksInitialized = false;
|
||||||
|
|
||||||
/// The run-time callback to print a warning.
|
/// The run-time callback to print a warning.
|
||||||
Value *WarningFn = nullptr;
|
Value *WarningFn;
|
||||||
|
|
||||||
// These arrays are indexed by log2(AccessSize).
|
// These arrays are indexed by log2(AccessSize).
|
||||||
Value *MaybeWarningFn[kNumberOfAccessSizes];
|
Value *MaybeWarningFn[kNumberOfAccessSizes];
|
||||||
@ -522,12 +526,8 @@ static GlobalVariable *createPrivateNonConstGlobalForString(Module &M,
|
|||||||
GlobalValue::PrivateLinkage, StrConst, "");
|
GlobalValue::PrivateLinkage, StrConst, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert extern declaration of runtime-provided functions and globals.
|
/// Insert declarations for userspace-specific functions and globals.
|
||||||
void MemorySanitizer::initializeCallbacks(Module &M) {
|
void MemorySanitizer::createUserspaceApi(Module &M) {
|
||||||
// Only do this once.
|
|
||||||
if (WarningFn)
|
|
||||||
return;
|
|
||||||
|
|
||||||
IRBuilder<> IRB(*C);
|
IRBuilder<> IRB(*C);
|
||||||
// Create the callback.
|
// Create the callback.
|
||||||
// FIXME: this function should have "Cold" calling conv,
|
// FIXME: this function should have "Cold" calling conv,
|
||||||
@ -536,6 +536,38 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
|
|||||||
: "__msan_warning_noreturn";
|
: "__msan_warning_noreturn";
|
||||||
WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy());
|
WarningFn = M.getOrInsertFunction(WarningFnName, IRB.getVoidTy());
|
||||||
|
|
||||||
|
// Create the global TLS variables.
|
||||||
|
RetvalTLS = new GlobalVariable(
|
||||||
|
M, ArrayType::get(IRB.getInt64Ty(), kRetvalTLSSize / 8), false,
|
||||||
|
GlobalVariable::ExternalLinkage, nullptr, "__msan_retval_tls", nullptr,
|
||||||
|
GlobalVariable::InitialExecTLSModel);
|
||||||
|
|
||||||
|
RetvalOriginTLS = new GlobalVariable(
|
||||||
|
M, OriginTy, false, GlobalVariable::ExternalLinkage, nullptr,
|
||||||
|
"__msan_retval_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel);
|
||||||
|
|
||||||
|
ParamTLS = new GlobalVariable(
|
||||||
|
M, ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), false,
|
||||||
|
GlobalVariable::ExternalLinkage, nullptr, "__msan_param_tls", nullptr,
|
||||||
|
GlobalVariable::InitialExecTLSModel);
|
||||||
|
|
||||||
|
ParamOriginTLS = new GlobalVariable(
|
||||||
|
M, ArrayType::get(OriginTy, kParamTLSSize / 4), false,
|
||||||
|
GlobalVariable::ExternalLinkage, nullptr, "__msan_param_origin_tls",
|
||||||
|
nullptr, GlobalVariable::InitialExecTLSModel);
|
||||||
|
|
||||||
|
VAArgTLS = new GlobalVariable(
|
||||||
|
M, ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), false,
|
||||||
|
GlobalVariable::ExternalLinkage, nullptr, "__msan_va_arg_tls", nullptr,
|
||||||
|
GlobalVariable::InitialExecTLSModel);
|
||||||
|
VAArgOverflowSizeTLS = new GlobalVariable(
|
||||||
|
M, IRB.getInt64Ty(), false, GlobalVariable::ExternalLinkage, nullptr,
|
||||||
|
"__msan_va_arg_overflow_size_tls", nullptr,
|
||||||
|
GlobalVariable::InitialExecTLSModel);
|
||||||
|
OriginTLS = new GlobalVariable(
|
||||||
|
M, IRB.getInt32Ty(), false, GlobalVariable::ExternalLinkage, nullptr,
|
||||||
|
"__msan_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel);
|
||||||
|
|
||||||
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
|
for (size_t AccessSizeIndex = 0; AccessSizeIndex < kNumberOfAccessSizes;
|
||||||
AccessSizeIndex++) {
|
AccessSizeIndex++) {
|
||||||
unsigned AccessSize = 1 << AccessSizeIndex;
|
unsigned AccessSize = 1 << AccessSizeIndex;
|
||||||
@ -556,6 +588,17 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
|
|||||||
MsanPoisonStackFn =
|
MsanPoisonStackFn =
|
||||||
M.getOrInsertFunction("__msan_poison_stack", IRB.getVoidTy(),
|
M.getOrInsertFunction("__msan_poison_stack", IRB.getVoidTy(),
|
||||||
IRB.getInt8PtrTy(), IntptrTy);
|
IRB.getInt8PtrTy(), IntptrTy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Insert extern declaration of runtime-provided functions and globals.
|
||||||
|
void MemorySanitizer::initializeCallbacks(Module &M) {
|
||||||
|
// Only do this once.
|
||||||
|
if (CallbacksInitialized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IRBuilder<> IRB(*C);
|
||||||
|
// Initialize callbacks that are common for kernel and userspace
|
||||||
|
// instrumentation.
|
||||||
MsanChainOriginFn = M.getOrInsertFunction(
|
MsanChainOriginFn = M.getOrInsertFunction(
|
||||||
"__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty());
|
"__msan_chain_origin", IRB.getInt32Ty(), IRB.getInt32Ty());
|
||||||
MemmoveFn = M.getOrInsertFunction(
|
MemmoveFn = M.getOrInsertFunction(
|
||||||
@ -567,41 +610,13 @@ void MemorySanitizer::initializeCallbacks(Module &M) {
|
|||||||
MemsetFn = M.getOrInsertFunction(
|
MemsetFn = M.getOrInsertFunction(
|
||||||
"__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(),
|
"__msan_memset", IRB.getInt8PtrTy(), IRB.getInt8PtrTy(), IRB.getInt32Ty(),
|
||||||
IntptrTy);
|
IntptrTy);
|
||||||
|
|
||||||
// Create globals.
|
|
||||||
RetvalTLS = new GlobalVariable(
|
|
||||||
M, ArrayType::get(IRB.getInt64Ty(), kRetvalTLSSize / 8), false,
|
|
||||||
GlobalVariable::ExternalLinkage, nullptr, "__msan_retval_tls", nullptr,
|
|
||||||
GlobalVariable::InitialExecTLSModel);
|
|
||||||
RetvalOriginTLS = new GlobalVariable(
|
|
||||||
M, OriginTy, false, GlobalVariable::ExternalLinkage, nullptr,
|
|
||||||
"__msan_retval_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel);
|
|
||||||
|
|
||||||
ParamTLS = new GlobalVariable(
|
|
||||||
M, ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), false,
|
|
||||||
GlobalVariable::ExternalLinkage, nullptr, "__msan_param_tls", nullptr,
|
|
||||||
GlobalVariable::InitialExecTLSModel);
|
|
||||||
ParamOriginTLS = new GlobalVariable(
|
|
||||||
M, ArrayType::get(OriginTy, kParamTLSSize / 4), false,
|
|
||||||
GlobalVariable::ExternalLinkage, nullptr, "__msan_param_origin_tls",
|
|
||||||
nullptr, GlobalVariable::InitialExecTLSModel);
|
|
||||||
|
|
||||||
VAArgTLS = new GlobalVariable(
|
|
||||||
M, ArrayType::get(IRB.getInt64Ty(), kParamTLSSize / 8), false,
|
|
||||||
GlobalVariable::ExternalLinkage, nullptr, "__msan_va_arg_tls", nullptr,
|
|
||||||
GlobalVariable::InitialExecTLSModel);
|
|
||||||
VAArgOverflowSizeTLS = new GlobalVariable(
|
|
||||||
M, IRB.getInt64Ty(), false, GlobalVariable::ExternalLinkage, nullptr,
|
|
||||||
"__msan_va_arg_overflow_size_tls", nullptr,
|
|
||||||
GlobalVariable::InitialExecTLSModel);
|
|
||||||
OriginTLS = new GlobalVariable(
|
|
||||||
M, IRB.getInt32Ty(), false, GlobalVariable::ExternalLinkage, nullptr,
|
|
||||||
"__msan_origin_tls", nullptr, GlobalVariable::InitialExecTLSModel);
|
|
||||||
|
|
||||||
// We insert an empty inline asm after __msan_report* to avoid callback merge.
|
// We insert an empty inline asm after __msan_report* to avoid callback merge.
|
||||||
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
|
EmptyAsm = InlineAsm::get(FunctionType::get(IRB.getVoidTy(), false),
|
||||||
StringRef(""), StringRef(""),
|
StringRef(""), StringRef(""),
|
||||||
/*hasSideEffects=*/true);
|
/*hasSideEffects=*/true);
|
||||||
|
|
||||||
|
createUserspaceApi(M);
|
||||||
|
CallbacksInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Module-level initialization.
|
/// Module-level initialization.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user