Skip to content

Commit 4a8fcef

Browse files
[AArch64][Clang] Fix linker error for function multiversioning.
AArch64 part of #71706. Default version is now mangled with .default. Resolver for the TargetVersion need to be emitted from the CodeGenModule::EmitMultiVersionFunctionDefinition.
1 parent 114325b commit 4a8fcef

File tree

5 files changed

+656
-302
lines changed

5 files changed

+656
-302
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,8 +1688,10 @@ static void AppendCPUSpecificCPUDispatchMangling(const CodeGenModule &CGM,
16881688
static void AppendTargetVersionMangling(const CodeGenModule &CGM,
16891689
const TargetVersionAttr *Attr,
16901690
raw_ostream &Out) {
1691-
if (Attr->isDefaultVersion())
1691+
if (Attr->isDefaultVersion()) {
1692+
Out << ".default";
16921693
return;
1694+
}
16931695
Out << "._";
16941696
const TargetInfo &TI = CGM.getTarget();
16951697
llvm::SmallVector<StringRef, 8> Feats;
@@ -1752,8 +1754,10 @@ static void AppendTargetClonesMangling(const CodeGenModule &CGM,
17521754
const TargetInfo &TI = CGM.getTarget();
17531755
if (TI.getTriple().isAArch64()) {
17541756
StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
1755-
if (FeatureStr == "default")
1757+
if (FeatureStr == "default") {
1758+
Out << ".default";
17561759
return;
1760+
}
17571761
Out << "._";
17581762
SmallVector<StringRef, 8> Features;
17591763
FeatureStr.split(Features, "+");
@@ -3999,6 +4003,8 @@ void CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
39994003
EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
40004004
// Ensure that the resolver function is also emitted.
40014005
GetOrCreateMultiVersionResolver(GD);
4006+
} else if (FD->hasAttr<TargetVersionAttr>()) {
4007+
GetOrCreateMultiVersionResolver(GD);
40024008
} else
40034009
EmitGlobalFunctionDefinition(GD, GV);
40044010
}
@@ -4180,14 +4186,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
41804186
llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
41814187
if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant)) {
41824188
ResolverConstant = IFunc->getResolver();
4183-
// In Aarch64, default versions of multiversioned functions are mangled to
4184-
// their 'normal' assembly name. This deviates from other targets which
4185-
// append a '.default' string. As a result we need to continue appending
4186-
// .ifunc in Aarch64.
4187-
// FIXME: Should Aarch64 mangling for 'default' multiversion function and
4188-
// in turn ifunc function match that of other targets?
4189-
if (FD->isTargetClonesMultiVersion() &&
4190-
!getTarget().getTriple().isAArch64()) {
4189+
if (FD->isTargetClonesMultiVersion()) {
41914190
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
41924191
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
41934192
std::string MangledName = getMangledNameImpl(
@@ -4368,14 +4367,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
43684367
// a separate resolver).
43694368
std::string ResolverName = MangledName;
43704369
if (getTarget().supportsIFunc()) {
4371-
// In Aarch64, default versions of multiversioned functions are mangled to
4372-
// their 'normal' assembly name. This deviates from other targets which
4373-
// append a '.default' string. As a result we need to continue appending
4374-
// .ifunc in Aarch64.
4375-
// FIXME: Should Aarch64 mangling for 'default' multiversion function and
4376-
// in turn ifunc function match that of other targets?
4377-
if (!FD->isTargetClonesMultiVersion() ||
4378-
getTarget().getTriple().isAArch64())
4370+
if (!FD->isTargetClonesMultiVersion())
43794371
ResolverName += ".ifunc";
43804372
} else if (FD->isTargetMultiVersion()) {
43814373
ResolverName += ".resolver";

0 commit comments

Comments
 (0)