mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 18:54:02 +01:00
Revert "[KernelAddressSanitizer] Make globals constructors compatible with kernel"
This reverts commit 866ee2353f7d0224644799d0d1faed53c7f3a06d. Building the kernel results in modpost failures due to modpost relying on debug info and inspecting kernel modules' globals: https://github.com/ClangBuiltLinux/linux/issues/1045#issuecomment-640381783
This commit is contained in:
parent
db86191fa7
commit
d9efe1beb1
@ -42,10 +42,6 @@ void appendToGlobalDtors(Module &M, Function *F, int Priority,
|
||||
FunctionCallee declareSanitizerInitFunction(Module &M, StringRef InitName,
|
||||
ArrayRef<Type *> InitArgTypes);
|
||||
|
||||
/// Creates sanitizer constructor function.
|
||||
/// \return Returns pointer to constructor.
|
||||
Function *createSanitizerCtor(Module &M, StringRef CtorName);
|
||||
|
||||
/// Creates sanitizer constructor function, and calls sanitizer's init
|
||||
/// function from it.
|
||||
/// \return Returns pair of pointers to constructor, and init functions
|
||||
|
@ -589,10 +589,11 @@ struct AddressSanitizer {
|
||||
AddressSanitizer(Module &M, const GlobalsMetadata *GlobalsMD,
|
||||
bool CompileKernel = false, bool Recover = false,
|
||||
bool UseAfterScope = false)
|
||||
: CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
|
||||
: CompileKernel),
|
||||
Recover(ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover),
|
||||
UseAfterScope(UseAfterScope || ClUseAfterScope), GlobalsMD(*GlobalsMD) {
|
||||
: UseAfterScope(UseAfterScope || ClUseAfterScope), GlobalsMD(*GlobalsMD) {
|
||||
this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
|
||||
this->CompileKernel =
|
||||
ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan : CompileKernel;
|
||||
|
||||
C = &(M.getContext());
|
||||
LongSize = M.getDataLayout().getPointerSizeInBits();
|
||||
IntptrTy = Type::getIntNTy(*C, LongSize);
|
||||
@ -741,11 +742,7 @@ public:
|
||||
ModuleAddressSanitizer(Module &M, const GlobalsMetadata *GlobalsMD,
|
||||
bool CompileKernel = false, bool Recover = false,
|
||||
bool UseGlobalsGC = true, bool UseOdrIndicator = false)
|
||||
: GlobalsMD(*GlobalsMD),
|
||||
CompileKernel(ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan
|
||||
: CompileKernel),
|
||||
Recover(ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover),
|
||||
UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC && !this->CompileKernel),
|
||||
: GlobalsMD(*GlobalsMD), UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
|
||||
// Enable aliases as they should have no downside with ODR indicators.
|
||||
UsePrivateAlias(UseOdrIndicator || ClUsePrivateAlias),
|
||||
UseOdrIndicator(UseOdrIndicator || ClUseOdrIndicator),
|
||||
@ -756,7 +753,11 @@ public:
|
||||
// argument is designed as workaround. Therefore, disable both
|
||||
// ClWithComdat and ClUseGlobalsGC unless the frontend says it's ok to
|
||||
// do globals-gc.
|
||||
UseCtorComdat(UseGlobalsGC && ClWithComdat && !this->CompileKernel) {
|
||||
UseCtorComdat(UseGlobalsGC && ClWithComdat) {
|
||||
this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
|
||||
this->CompileKernel =
|
||||
ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan : CompileKernel;
|
||||
|
||||
C = &(M.getContext());
|
||||
int LongSize = M.getDataLayout().getPointerSizeInBits();
|
||||
IntptrTy = Type::getIntNTy(*C, LongSize);
|
||||
@ -1837,12 +1838,6 @@ bool ModuleAddressSanitizer::ShouldInstrumentGlobal(GlobalVariable *G) {
|
||||
}
|
||||
|
||||
if (G->hasSection()) {
|
||||
// The kernel uses explicit sections for mostly special global variables
|
||||
// that we should not instrument. E.g. the kernel may rely on their layout
|
||||
// without redzones, or remove them at link time ("discard.*"), etc.
|
||||
if (CompileKernel)
|
||||
return false;
|
||||
|
||||
StringRef Section = G->getSection();
|
||||
|
||||
// Globals from llvm.metadata aren't emitted, do not instrument them.
|
||||
@ -2450,23 +2445,20 @@ int ModuleAddressSanitizer::GetAsanVersion(const Module &M) const {
|
||||
bool ModuleAddressSanitizer::instrumentModule(Module &M) {
|
||||
initializeCallbacks(M);
|
||||
|
||||
if (CompileKernel)
|
||||
return false;
|
||||
|
||||
// Create a module constructor. A destructor is created lazily because not all
|
||||
// platforms, and not all modules need it.
|
||||
if (CompileKernel) {
|
||||
// The kernel always builds with its own runtime, and therefore does not
|
||||
// need the init and version check calls.
|
||||
AsanCtorFunction = createSanitizerCtor(M, kAsanModuleCtorName);
|
||||
} else {
|
||||
std::string AsanVersion = std::to_string(GetAsanVersion(M));
|
||||
std::string VersionCheckName =
|
||||
ClInsertVersionCheck ? (kAsanVersionCheckNamePrefix + AsanVersion) : "";
|
||||
std::tie(AsanCtorFunction, std::ignore) =
|
||||
createSanitizerCtorAndInitFunctions(M, kAsanModuleCtorName,
|
||||
kAsanInitName, /*InitArgTypes=*/{},
|
||||
/*InitArgs=*/{}, VersionCheckName);
|
||||
}
|
||||
std::string AsanVersion = std::to_string(GetAsanVersion(M));
|
||||
std::string VersionCheckName =
|
||||
ClInsertVersionCheck ? (kAsanVersionCheckNamePrefix + AsanVersion) : "";
|
||||
std::tie(AsanCtorFunction, std::ignore) = createSanitizerCtorAndInitFunctions(
|
||||
M, kAsanModuleCtorName, kAsanInitName, /*InitArgTypes=*/{},
|
||||
/*InitArgs=*/{}, VersionCheckName);
|
||||
|
||||
bool CtorComdat = true;
|
||||
// TODO(glider): temporarily disabled globals instrumentation for KASan.
|
||||
if (ClGlobals) {
|
||||
IRBuilder<> IRB(AsanCtorFunction->getEntryBlock().getTerminator());
|
||||
InstrumentGlobals(IRB, M, &CtorComdat);
|
||||
|
@ -119,15 +119,6 @@ llvm::declareSanitizerInitFunction(Module &M, StringRef InitName,
|
||||
AttributeList());
|
||||
}
|
||||
|
||||
Function *llvm::createSanitizerCtor(Module &M, StringRef CtorName) {
|
||||
Function *Ctor = Function::Create(
|
||||
FunctionType::get(Type::getVoidTy(M.getContext()), false),
|
||||
GlobalValue::InternalLinkage, CtorName, &M);
|
||||
BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor);
|
||||
ReturnInst::Create(M.getContext(), CtorBB);
|
||||
return Ctor;
|
||||
}
|
||||
|
||||
std::pair<Function *, FunctionCallee> llvm::createSanitizerCtorAndInitFunctions(
|
||||
Module &M, StringRef CtorName, StringRef InitName,
|
||||
ArrayRef<Type *> InitArgTypes, ArrayRef<Value *> InitArgs,
|
||||
@ -137,8 +128,11 @@ std::pair<Function *, FunctionCallee> llvm::createSanitizerCtorAndInitFunctions(
|
||||
"Sanitizer's init function expects different number of arguments");
|
||||
FunctionCallee InitFunction =
|
||||
declareSanitizerInitFunction(M, InitName, InitArgTypes);
|
||||
Function *Ctor = createSanitizerCtor(M, CtorName);
|
||||
IRBuilder<> IRB(Ctor->getEntryBlock().getTerminator());
|
||||
Function *Ctor = Function::Create(
|
||||
FunctionType::get(Type::getVoidTy(M.getContext()), false),
|
||||
GlobalValue::InternalLinkage, CtorName, &M);
|
||||
BasicBlock *CtorBB = BasicBlock::Create(M.getContext(), "", Ctor);
|
||||
IRBuilder<> IRB(ReturnInst::Create(M.getContext(), CtorBB));
|
||||
IRB.CreateCall(InitFunction, InitArgs);
|
||||
if (!VersionCheckName.empty()) {
|
||||
FunctionCallee VersionCheckFunction = M.getOrInsertFunction(
|
||||
|
Loading…
Reference in New Issue
Block a user