@@ -4610,12 +4610,6 @@ void CodeGenModule::emitMultiVersionFunctions() {
4610
4610
}
4611
4611
llvm::Function *ResolverFunc = cast<llvm::Function>(ResolverConstant);
4612
4612
4613
- ResolverFunc->setLinkage (getMultiversionLinkage (*this , GD));
4614
-
4615
- if (!ResolverFunc->hasLocalLinkage () && supportsCOMDAT ())
4616
- ResolverFunc->setComdat (
4617
- getModule ().getOrInsertComdat (ResolverFunc->getName ()));
4618
-
4619
4613
const TargetInfo &TI = getTarget ();
4620
4614
llvm::stable_sort (
4621
4615
Options, [&TI](const CodeGenFunction::FMVResolverOption &LHS,
@@ -4624,6 +4618,11 @@ void CodeGenModule::emitMultiVersionFunctions() {
4624
4618
});
4625
4619
CodeGenFunction CGF (*this );
4626
4620
CGF.EmitMultiVersionResolver (ResolverFunc, Options);
4621
+
4622
+ setMultiVersionResolverAttributes (ResolverFunc, GD);
4623
+ if (!ResolverFunc->hasLocalLinkage () && supportsCOMDAT ())
4624
+ ResolverFunc->setComdat (
4625
+ getModule ().getOrInsertComdat (ResolverFunc->getName ()));
4627
4626
}
4628
4627
4629
4628
// Ensure that any additions to the deferred decls list caused by emitting a
@@ -4674,7 +4673,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
4674
4673
4675
4674
auto *ResolverFunc = cast<llvm::Function>(GetOrCreateLLVMFunction (
4676
4675
ResolverName, ResolverType, ResolverGD, /* ForVTable=*/ false ));
4677
- ResolverFunc-> setLinkage ( getMultiversionLinkage (* this , GD));
4676
+
4678
4677
if (supportsCOMDAT ())
4679
4678
ResolverFunc->setComdat (
4680
4679
getModule ().getOrInsertComdat (ResolverFunc->getName ()));
@@ -4740,6 +4739,7 @@ void CodeGenModule::emitCPUDispatchDefinition(GlobalDecl GD) {
4740
4739
4741
4740
CodeGenFunction CGF (*this );
4742
4741
CGF.EmitMultiVersionResolver (ResolverFunc, Options);
4742
+ setMultiVersionResolverAttributes (ResolverFunc, GD);
4743
4743
4744
4744
if (getTarget ().supportsIFunc ()) {
4745
4745
llvm::GlobalValue::LinkageTypes Linkage = getMultiversionLinkage (*this , GD);
@@ -4858,6 +4858,26 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
4858
4858
return Resolver;
4859
4859
}
4860
4860
4861
+ void CodeGenModule::setMultiVersionResolverAttributes (llvm::Function *Resolver,
4862
+ GlobalDecl GD) {
4863
+ const NamedDecl *D = dyn_cast_or_null<NamedDecl>(GD.getDecl ());
4864
+ Resolver->setLinkage (getMultiversionLinkage (*this , GD));
4865
+
4866
+ // Function body has to be emitted before calling setGlobalVisibility
4867
+ // for Resolver to be considered as definition.
4868
+ setGlobalVisibility (Resolver, D);
4869
+
4870
+ setDSOLocal (Resolver);
4871
+
4872
+ // Set the default target-specific attributes, such as PAC and BTI ones on
4873
+ // AArch64. Not passing Decl to prevent setting unrelated attributes,
4874
+ // as Resolver can be shared by multiple declarations.
4875
+ // FIXME Some targets may require a non-null D to set some attributes
4876
+ // (such as "stackrealign" on X86, even when it is requested via
4877
+ // "-mstackrealign" command line option).
4878
+ getTargetCodeGenInfo ().setTargetAttributes (/* D=*/ nullptr , Resolver, *this );
4879
+ }
4880
+
4861
4881
bool CodeGenModule::shouldDropDLLAttribute (const Decl *D,
4862
4882
const llvm::GlobalValue *GV) const {
4863
4883
auto SC = GV->getDLLStorageClass ();
0 commit comments