aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorAnatoly Trosinenko <atrosinenko@accesssoftek.com>2025-09-17 20:23:09 +0300
committerGitHub <noreply@github.com>2025-09-17 20:23:09 +0300
commit6bbf734ecac35a5a1c3bcb680d20519dfd46da11 (patch)
treef16a3867ef1f496187ca79967976c181a59d1a12 /clang/lib/CodeGen/CodeGenModule.cpp
parent453e4102bd32b892e7fda2aea3f3ef9e9b038580 (diff)
downloadllvm-6bbf734ecac35a5a1c3bcb680d20519dfd46da11.zip
llvm-6bbf734ecac35a5a1c3bcb680d20519dfd46da11.tar.gz
llvm-6bbf734ecac35a5a1c3bcb680d20519dfd46da11.tar.bz2
[FMV] Set default attributes on the resolver functions (#141573)
There is a number of attributes that is expected to be set on functions by default. This patch implements setting more such attributes on the FMV resolver functions generated by Clang. On AArch64, this makes the resolver functions use the default PAC and BTI hardening settings.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0ebab14..0b660e3 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -4610,12 +4610,6 @@ void CodeGenModule::emitMultiVersionFunctions() {
}
llvm::Function *ResolverFunc = cast<llvm::Function>(ResolverConstant);
- ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
-
- if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
- ResolverFunc->setComdat(
- getModule().getOrInsertComdat(ResolverFunc->getName()));
-
const TargetInfo &TI = getTarget();
llvm::stable_sort(
Options, [&TI](const CodeGenFunction::FMVResolverOption &LHS,
@@ -4624,6 +4618,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
});
CodeGenFunction CGF(*this);
CGF.EmitMultiVersionResolver(ResolverFunc, Options);
+
+ setMultiVersionResolverAttributes(ResolverFunc, GD);
+ if (!ResolverFunc->hasLocalLinkage() && supportsCOMDAT())
+ ResolverFunc->setComdat(
+ getModule().getOrInsertComdat(ResolverFunc->getName()));
}
// Ensure that any additions to the deferred decls list caused by emitting a
@@ -4674,7 +4673,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
auto *ResolverFunc = cast<llvm::Function>(GetOrCreateLLVMFunction(
ResolverName, ResolverType, ResolverGD, /*ForVTable=*/false));
- ResolverFunc->setLinkage(getMultiversionLinkage(*this, GD));
+
if (supportsCOMDAT())
ResolverFunc->setComdat(
getModule().getOrInsertComdat(ResolverFunc->getName()));
@@ -4740,6 +4739,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
CodeGenFunction CGF(*this);
CGF.EmitMultiVersionResolver(ResolverFunc, Options);
+ setMultiVersionResolverAttributes(ResolverFunc, GD);
if (getTarget().supportsIFunc()) {
llvm::GlobalValue::LinkageTypes Linkage = getMultiversionLinkage(*this, GD);
@@ -4858,6 +4858,26 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
return Resolver;
}
+void CodeGenModule::setMultiVersionResolverAttributes(llvm::Function *Resolver,
+ GlobalDecl GD) {
+ const NamedDecl *D = dyn_cast_or_null<NamedDecl>(GD.getDecl());
+ Resolver->setLinkage(getMultiversionLinkage(*this, GD));
+
+ // Function body has to be emitted before calling setGlobalVisibility
+ // for Resolver to be considered as definition.
+ setGlobalVisibility(Resolver, D);
+
+ setDSOLocal(Resolver);
+
+ // Set the default target-specific attributes, such as PAC and BTI ones on
+ // AArch64. Not passing Decl to prevent setting unrelated attributes,
+ // as Resolver can be shared by multiple declarations.
+ // FIXME Some targets may require a non-null D to set some attributes
+ // (such as "stackrealign" on X86, even when it is requested via
+ // "-mstackrealign" command line option).
+ getTargetCodeGenInfo().setTargetAttributes(/*D=*/nullptr, Resolver, *this);
+}
+
bool CodeGenModule::shouldDropDLLAttribute(const Decl *D,
const llvm::GlobalValue *GV) const {
auto SC = GV->getDLLStorageClass();