|
66 | 66 | #include "llvm/Support/CommandLine.h" |
67 | 67 | #include "llvm/Support/ConvertUTF.h" |
68 | 68 | #include "llvm/Support/ErrorHandling.h" |
| 69 | +#include "llvm/Support/Hash.h" |
69 | 70 | #include "llvm/Support/TimeProfiler.h" |
70 | | -#include "llvm/Support/xxhash.h" |
71 | 71 | #include "llvm/TargetParser/RISCVISAInfo.h" |
72 | 72 | #include "llvm/TargetParser/Triple.h" |
73 | 73 | #include "llvm/TargetParser/X86TargetParser.h" |
| 74 | +#include "llvm/Transforms/Instrumentation/KCFI.h" |
74 | 75 | #include "llvm/Transforms/Utils/BuildLibCalls.h" |
75 | 76 | #include <optional> |
76 | 77 | #include <set> |
@@ -1272,6 +1273,12 @@ void CodeGenModule::Release() { |
1272 | 1273 | CodeGenOpts.PatchableFunctionEntryOffset); |
1273 | 1274 | if (CodeGenOpts.SanitizeKcfiArity) |
1274 | 1275 | getModule().addModuleFlag(llvm::Module::Override, "kcfi-arity", 1); |
| 1276 | + // Store the hash algorithm choice for use in LLVM passes |
| 1277 | + getModule().addModuleFlag( |
| 1278 | + llvm::Module::Override, "kcfi-hash", |
| 1279 | + llvm::MDString::get( |
| 1280 | + getLLVMContext(), |
| 1281 | + llvm::stringifyKCFIHashAlgorithm(CodeGenOpts.SanitizeKcfiHash))); |
1275 | 1282 | } |
1276 | 1283 |
|
1277 | 1284 | if (CodeGenOpts.CFProtectionReturn && |
@@ -2450,8 +2457,8 @@ llvm::ConstantInt *CodeGenModule::CreateKCFITypeId(QualType T, StringRef Salt) { |
2450 | 2457 | if (getCodeGenOpts().SanitizeCfiICallGeneralizePointers) |
2451 | 2458 | Out << ".generalized"; |
2452 | 2459 |
|
2453 | | - return llvm::ConstantInt::get(Int32Ty, |
2454 | | - static_cast<uint32_t>(llvm::xxHash64(OutName))); |
| 2460 | + return llvm::ConstantInt::get( |
| 2461 | + Int32Ty, llvm::getKCFITypeID(OutName, getCodeGenOpts().SanitizeKcfiHash)); |
2455 | 2462 | } |
2456 | 2463 |
|
2457 | 2464 | void CodeGenModule::SetLLVMFunctionAttributes(GlobalDecl GD, |
@@ -3205,7 +3212,8 @@ void CodeGenModule::finalizeKCFITypes() { |
3205 | 3212 | continue; |
3206 | 3213 |
|
3207 | 3214 | std::string Asm = (".weak __kcfi_typeid_" + Name + "\n.set __kcfi_typeid_" + |
3208 | | - Name + ", " + Twine(Type->getZExtValue()) + "\n") |
| 3215 | + Name + ", " + Twine(Type->getZExtValue()) + " # " + |
| 3216 | + Twine(Type->getSExtValue()) + "\n") |
3209 | 3217 | .str(); |
3210 | 3218 | M.appendModuleInlineAsm(Asm); |
3211 | 3219 | } |
|
0 commit comments