diff options
author | Sami Tolvanen <samitolvanen@users.noreply.github.com> | 2024-08-20 16:51:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-20 16:51:16 -0700 |
commit | e1c36bde0551977d4b2efae032af6dfc4b2b3936 (patch) | |
tree | d029ba7b43a1e89956f515e3f43b9212fca69bdd /llvm/lib/Transforms/Utils/ModuleUtils.cpp | |
parent | 3145cff24bda61ae0d3ba3981c19599f12af95ab (diff) | |
download | llvm-e1c36bde0551977d4b2efae032af6dfc4b2b3936.zip llvm-e1c36bde0551977d4b2efae032af6dfc4b2b3936.tar.gz llvm-e1c36bde0551977d4b2efae032af6dfc4b2b3936.tar.bz2 |
Fix KCFI types for generated functions with integer normalization (#104826)
With -fsanitize-cfi-icall-experimental-normalize-integers, Clang
appends ".normalized" to KCFI types in CodeGenModule::CreateKCFITypeId,
which changes type hashes also for functions that don't have integer
types in their signatures. However, llvm::setKCFIType does not take
integer normalization into account, which means LLVM generated
functions with KCFI types, e.g. sanitizer constructors, will fail KCFI
checks when integer normalization is enabled in Clang.
Add a cfi-normalize-integers module flag to indicate integer
normalization is used, and append ".normalized" to KCFI types also in
llvm::setKCFIType to fix the type mismatch.
Diffstat (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ModuleUtils.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 309cf8e..7249571 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -205,11 +205,13 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef MangledType) { // Matches CodeGenModule::CreateKCFITypeId in Clang. LLVMContext &Ctx = M.getContext(); MDBuilder MDB(Ctx); - F.setMetadata( - LLVMContext::MD_kcfi_type, - MDNode::get(Ctx, MDB.createConstant(ConstantInt::get( - Type::getInt32Ty(Ctx), - static_cast<uint32_t>(xxHash64(MangledType)))))); + std::string Type = MangledType.str(); + if (M.getModuleFlag("cfi-normalize-integers")) + Type += ".normalized"; + F.setMetadata(LLVMContext::MD_kcfi_type, + MDNode::get(Ctx, MDB.createConstant(ConstantInt::get( + Type::getInt32Ty(Ctx), + static_cast<uint32_t>(xxHash64(Type)))))); // If the module was compiled with -fpatchable-function-entry, ensure // we use the same patchable-function-prefix. if (auto *MD = mdconst::extract_or_null<ConstantInt>( |