[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)
Scott Constable via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 22 22:49:18 PST 2024
================
@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef MangledType) {
std::string Type = MangledType.str();
if (M.getModuleFlag("cfi-normalize-integers"))
Type += ".normalized";
+
+ uint32_t OutHash = static_cast<uint32_t>(llvm::xxHash64(Type));
+ auto T = Triple(Twine(M.getTargetTriple()));
+ if (T.isX86() && T.isArch64Bit() && T.isOSLinux()) {
+ // Estimate the function's arity (i.e., the number of arguments) at the ABI
+ // level by counting the number of parameters that are likely to be passed
+ // as registers, such as pointers and 64-bit (or smaller) integers. The
+ // Linux x86-64 ABI allows up to 6 parameters to be passed in GPRs.
+ // Additional parameters or parameters larger than 64 bits may be passed on
+ // the stack, in which case the arity is denoted as 7.
+ size_t NumParams = F.arg_size();
+ bool MayHaveStackArgs = NumParams > 6;
+
+ for (unsigned int i = 0; !MayHaveStackArgs && i < NumParams; ++i) {
+ const llvm::Type *PT = F.getArg(i)->getType();
+ if (!(PT->isPointerTy() || PT->getIntegerBitWidth() <= 64))
----------------
scottconstable wrote:
Is this condition equivalent to what I wrote in `CodeGenModule::CreateKCFITypeId` with `typeof(*PT) = clang::Type`? Specifically:
```
if (!(PT->isPointerType() || (PT->isIntegralOrEnumerationType() &&
getContext().getTypeSize(PT) <= 64)))
```
https://github.com/llvm/llvm-project/pull/117121
More information about the llvm-commits
mailing list