Skip to content

Commit 1be0d9d

Browse files
[AArch64][Clang] Fix linker error for function multiversioning (#74358)
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 16d2583 commit 1be0d9d

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
@@ -1716,8 +1716,10 @@ static void AppendCPUSpecificCPUDispatchMangling(const CodeGenModule &CGM,
17161716
static void AppendTargetVersionMangling(const CodeGenModule &CGM,
17171717
const TargetVersionAttr *Attr,
17181718
raw_ostream &Out) {
1719-
if (Attr->isDefaultVersion())
1719+
if (Attr->isDefaultVersion()) {
1720+
Out << ".default";
17201721
return;
1722+
}
17211723
Out << "._";
17221724
const TargetInfo &TI = CGM.getTarget();
17231725
llvm::SmallVector<StringRef, 8> Feats;
@@ -1780,8 +1782,10 @@ static void AppendTargetClonesMangling(const CodeGenModule &CGM,
17801782
const TargetInfo &TI = CGM.getTarget();
17811783
if (TI.getTriple().isAArch64()) {
17821784
StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
1783-
if (FeatureStr == "default")
1785+
if (FeatureStr == "default") {
1786+
Out << ".default";
17841787
return;
1788+
}
17851789
Out << "._";
17861790
SmallVector<StringRef, 8> Features;
17871791
FeatureStr.split(Features, "+");
@@ -4029,6 +4033,8 @@ void CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
40294033
EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
40304034
// Ensure that the resolver function is also emitted.
40314035
GetOrCreateMultiVersionResolver(GD);
4036+
} else if (FD->hasAttr<TargetVersionAttr>()) {
4037+
GetOrCreateMultiVersionResolver(GD);
40324038
} else
40334039
EmitGlobalFunctionDefinition(GD, GV);
40344040
}
@@ -4210,14 +4216,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
42104216
llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
42114217
if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant)) {
42124218
ResolverConstant = IFunc->getResolver();
4213-
// In Aarch64, default versions of multiversioned functions are mangled to
4214-
// their 'normal' assembly name. This deviates from other targets which
4215-
// append a '.default' string. As a result we need to continue appending
4216-
// .ifunc in Aarch64.
4217-
// FIXME: Should Aarch64 mangling for 'default' multiversion function and
4218-
// in turn ifunc function match that of other targets?
4219-
if (FD->isTargetClonesMultiVersion() &&
4220-
!getTarget().getTriple().isAArch64()) {
4219+
if (FD->isTargetClonesMultiVersion()) {
42214220
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
42224221
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
42234222
std::string MangledName = getMangledNameImpl(
@@ -4398,14 +4397,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
43984397
// a separate resolver).
43994398
std::string ResolverName = MangledName;
44004399
if (getTarget().supportsIFunc()) {
4401-
// In Aarch64, default versions of multiversioned functions are mangled to
4402-
// their 'normal' assembly name. This deviates from other targets which
4403-
// append a '.default' string. As a result we need to continue appending
4404-
// .ifunc in Aarch64.
4405-
// FIXME: Should Aarch64 mangling for 'default' multiversion function and
4406-
// in turn ifunc function match that of other targets?
4407-
if (!FD->isTargetClonesMultiVersion() ||
4408-
getTarget().getTriple().isAArch64())
4400+
if (!FD->isTargetClonesMultiVersion())
44094401
ResolverName += ".ifunc";
44104402
} else if (FD->isTargetMultiVersion()) {
44114403
ResolverName += ".resolver";

0 commit comments

Comments
 (0)