[clang] [llvm] [clang][llvm][AArch64] Set hardening fn attrs on synthetic functions (PR #211013)
Anatoly Trosinenko via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 31 07:39:50 PDT 2026
================
@@ -1543,6 +1543,27 @@ void CodeGenModule::Release() {
"sign-return-address-with-bkey", 2);
}
if (T.isAArch64()) {
+ // Emit the following 4 module flags so LLVM can derive corresponding
+ // function attributes for synthetically generated functions (e.g.
+ // __llvm_gcov_writeout). It is safe to only emit the flags conditionally
+ // and set the Max behavior because of two reasons:
+ // 1) all 4 hardening features gated behind the attributes do not break ABI
+ // compatibility, so we do not need to error on flag mismatch (thus,
+ // conditional emission);
+ // 2) promoting an absent flag to a present flag enables the corresponding
+ // hardening feature for newly emitted functions which does not affect
+ // correctness and is guaranteed to have sufficient target features for
+ // it, since the module we are merging with already has the flag set.
+ if (LangOpts.PointerAuthReturns)
+ getModule().addModuleFlag(llvm::Module::Max, "ptrauth-returns", 1);
+ if (LangOpts.PointerAuthAuthTraps)
+ getModule().addModuleFlag(llvm::Module::Max, "ptrauth-auth-traps", 1);
+ if (LangOpts.PointerAuthIndirectGotos)
+ getModule().addModuleFlag(llvm::Module::Max, "ptrauth-indirect-gotos", 1);
+ if (LangOpts.AArch64JumpTableHardening)
+ getModule().addModuleFlag(llvm::Module::Max,
+ "aarch64-jump-table-hardening", 1);
+
----------------
atrosinenko wrote:
[nit] I would add a tiny comment here mentioning why the below flags are treated differently.
https://github.com/llvm/llvm-project/pull/211013
More information about the cfe-commits
mailing list