diff options
| author | Sami Tolvanen <samitolvanen@google.com> | 2022-08-24 19:26:05 +0000 |
|---|---|---|
| committer | Sami Tolvanen <samitolvanen@google.com> | 2022-08-24 19:30:13 +0000 |
| commit | a79060e275440ccd8d403d5af5fb5b9395ea3fac (patch) | |
| tree | 7d29f75ff6c6a0cd2ceba3945e7d7cc0951c1d79 /clang/lib/CodeGen/CodeGenModule.cpp | |
| parent | dda38786534af733786c681e0c47b863e0626a0e (diff) | |
Revert "KCFI sanitizer"
This reverts commit 67504c95494ff05be2a613129110c9bcf17f6c13 as using
PointerEmbeddedInt to store 32 bits breaks 32-bit arm builds.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
| -rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 6238a289978d..74c14fed6575 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -48,7 +48,6 @@ #include "clang/CodeGen/ConstantInitBuilder.h" #include "clang/Frontend/FrontendDiagnostic.h" #include "llvm/ADT/STLExtras.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/TargetLibraryInfo.h" @@ -68,7 +67,6 @@ #include "llvm/Support/MD5.h" #include "llvm/Support/TimeProfiler.h" #include "llvm/Support/X86TargetParser.h" -#include "llvm/Support/xxhash.h" using namespace clang; using namespace CodeGen; @@ -579,8 +577,6 @@ void CodeGenModule::Release() { CodeGenFunction(*this).EmitCfiCheckFail(); CodeGenFunction(*this).EmitCfiCheckStub(); } - if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) - finalizeKCFITypes(); emitAtAvailableLinkGuard(); if (Context.getTargetInfo().getTriple().isWasm()) EmitMainVoidAlias(); @@ -763,9 +759,6 @@ void CodeGenModule::Release() { CodeGenOpts.SanitizeCfiCanonicalJumpTables); } - if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) - getModule().addModuleFlag(llvm::Module::Override, "kcfi", 1); - if (CodeGenOpts.CFProtectionReturn && Target.checkCFProtectionReturnSupported(getDiags())) { // Indicate that we want to instrument return control flow protection. @@ -1676,20 +1669,6 @@ llvm::ConstantInt *CodeGenModule::CreateCrossDsoCfiTypeId(llvm::Metadata *MD) { return llvm::ConstantInt::get(Int64Ty, llvm::MD5Hash(MDS->getString())); } -llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) { - if (auto *FnType = T->getAs<FunctionProtoType>()) - T = getContext().getFunctionType( - FnType->getReturnType(), FnType->getParamTypes(), - FnType->getExtProtoInfo().withExceptionSpec(EST_None)); - - std::string OutName; - llvm::raw_string_ostream Out(OutName); - getCXXABI().getMangleContext().mangleTypeName(T, Out); - - return llvm::ConstantInt::get(Int32Ty, - static_cast<uint32_t>(llvm::xxHash64(OutName))); -} - void CodeGenModule::SetLLVMFunctionAttributes(GlobalDecl GD, const CGFunctionInfo &Info, llvm::Function *F, bool IsThunk) { @@ -2308,57 +2287,6 @@ void CodeGenModule::CreateFunctionTypeMetadataForIcall(const FunctionDecl *FD, F->addTypeMetadata(0, llvm::ConstantAsMetadata::get(CrossDsoTypeId)); } -void CodeGenModule::setKCFIType(const FunctionDecl *FD, llvm::Function *F) { - if (isa<CXXMethodDecl>(FD) && !cast<CXXMethodDecl>(FD)->isStatic()) - return; - - llvm::LLVMContext &Ctx = F->getContext(); - llvm::MDBuilder MDB(Ctx); - F->setMetadata(llvm::LLVMContext::MD_kcfi_type, - llvm::MDNode::get( - Ctx, MDB.createConstant(CreateKCFITypeId(FD->getType())))); -} - -static bool allowKCFIIdentifier(StringRef Name) { - // KCFI type identifier constants are only necessary for external assembly - // functions, which means it's safe to skip unusual names. Subset of - // MCAsmInfo::isAcceptableChar() and MCAsmInfoXCOFF::isAcceptableChar(). - return llvm::all_of(Name, [](const char &C) { - return llvm::isAlnum(C) || C == '_' || C == '.'; - }); -} - -void CodeGenModule::finalizeKCFITypes() { - llvm::Module &M = getModule(); - for (auto &F : M.functions()) { - // Remove KCFI type metadata from non-address-taken local functions. - bool AddressTaken = F.hasAddressTaken(); - if (!AddressTaken && F.hasLocalLinkage()) - F.eraseMetadata(llvm::LLVMContext::MD_kcfi_type); - - // Generate a constant with the expected KCFI type identifier for all - // address-taken function declarations to support annotating indirectly - // called assembly functions. - if (!AddressTaken || !F.isDeclaration()) - continue; - - const llvm::ConstantInt *Type; - if (const llvm::MDNode *MD = F.getMetadata(llvm::LLVMContext::MD_kcfi_type)) - Type = llvm::mdconst::extract<llvm::ConstantInt>(MD->getOperand(0)); - else - continue; - - StringRef Name = F.getName(); - if (!allowKCFIIdentifier(Name)) - continue; - - std::string Asm = (".weak __kcfi_typeid_" + Name + "\n.set __kcfi_typeid_" + - Name + ", " + Twine(Type->getZExtValue()) + "\n") - .str(); - M.appendModuleInlineAsm(Asm); - } -} - void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, bool IsIncompleteFunction, bool IsThunk) { @@ -2441,9 +2369,6 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Function *F, !CodeGenOpts.SanitizeCfiCanonicalJumpTables) CreateFunctionTypeMetadataForIcall(FD, F); - if (LangOpts.Sanitize.has(SanitizerKind::KCFI)) - setKCFIType(FD, F); - if (getLangOpts().OpenMP && FD->hasAttr<OMPDeclareSimdDeclAttr>()) getOpenMPRuntime().emitDeclareSimdFunction(FD, F); |
