diff options
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 2d37e0f..4146876 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2366,7 +2366,7 @@ static QualType GeneralizeFunctionType(ASTContext &Ctx, QualType Ty) { llvm_unreachable("Encountered unknown FunctionType"); } -llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) { +llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T, StringRef Salt) { if (getCodeGenOpts().SanitizeCfiICallGeneralizePointers) T = GeneralizeFunctionType(getContext(), T); if (auto *FnType = T->getAs<FunctionProtoType>()) @@ -2379,6 +2379,9 @@ llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T) { getCXXABI().getMangleContext().mangleCanonicalTypeName( T, Out, getCodeGenOpts().SanitizeCfiICallNormalizeIntegers); + if (!Salt.empty()) + Out << "." << Salt; + if (getCodeGenOpts().SanitizeCfiICallNormalizeIntegers) Out << ".normalized"; if (getCodeGenOpts().SanitizeCfiICallGeneralizePointers) @@ -3047,9 +3050,15 @@ void CodeGenModule::createFunctionTypeMetadataForIcall(const FunctionDecl *FD, void CodeGenModule::setKCFIType(const FunctionDecl *FD, llvm::Function *F) { llvm::LLVMContext &Ctx = F->getContext(); llvm::MDBuilder MDB(Ctx); + llvm::StringRef Salt; + + if (const auto *FP = FD->getType()->getAs<FunctionProtoType>()) + if (const auto &Info = FP->getExtraAttributeInfo()) + Salt = Info.CFISalt; + F->setMetadata(llvm::LLVMContext::MD_kcfi_type, - llvm::MDNode::get( - Ctx, MDB.createConstant(CreateKCFITypeId(FD->getType())))); + llvm::MDNode::get(Ctx, MDB.createConstant(CreateKCFITypeId( + FD->getType(), Salt)))); } static bool allowKCFIIdentifier(StringRef Name) { |