Skip to content

Commit 38bad73

Browse files
DanielKristofKissjroelofs
authored andcommitted
[AArch64][Clang] Fix linker error for function multiversioning (llvm#74358)
AArch64 part of llvm#71706. Default version is now mangled with .default. Resolver for the TargetVersion need to be emitted from the CodeGenModule::EmitMultiVersionFunctionDefinition.
1 parent 5ef32c8 commit 38bad73

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
@@ -1606,8 +1606,10 @@ static void AppendCPUSpecificCPUDispatchMangling(const CodeGenModule &CGM,
16061606
static void AppendTargetVersionMangling(const CodeGenModule &CGM,
16071607
const TargetVersionAttr *Attr,
16081608
raw_ostream &Out) {
1609-
if (Attr->isDefaultVersion())
1609+
if (Attr->isDefaultVersion()) {
1610+
Out << ".default";
16101611
return;
1612+
}
16111613
Out << "._";
16121614
const TargetInfo &TI = CGM.getTarget();
16131615
llvm::SmallVector<StringRef, 8> Feats;
@@ -1670,8 +1672,10 @@ static void AppendTargetClonesMangling(const CodeGenModule &CGM,
16701672
const TargetInfo &TI = CGM.getTarget();
16711673
if (TI.getTriple().isAArch64()) {
16721674
StringRef FeatureStr = Attr->getFeatureStr(VersionIndex);
1673-
if (FeatureStr == "default")
1675+
if (FeatureStr == "default") {
1676+
Out << ".default";
16741677
return;
1678+
}
16751679
Out << "._";
16761680
SmallVector<StringRef, 8> Features;
16771681
FeatureStr.split(Features, "+");
@@ -3868,6 +3872,8 @@ void CodeGenModule::EmitMultiVersionFunctionDefinition(GlobalDecl GD,
38683872
EmitGlobalFunctionDefinition(GD.getWithMultiVersionIndex(I), nullptr);
38693873
// Ensure that the resolver function is also emitted.
38703874
GetOrCreateMultiVersionResolver(GD);
3875+
} else if (FD->hasAttr<TargetVersionAttr>()) {
3876+
GetOrCreateMultiVersionResolver(GD);
38713877
} else
38723878
EmitGlobalFunctionDefinition(GD, GV);
38733879
}
@@ -4049,14 +4055,7 @@ void CodeGenModule::emitMultiVersionFunctions() {
40494055
llvm::Constant *ResolverConstant = GetOrCreateMultiVersionResolver(GD);
40504056
if (auto *IFunc = dyn_cast<llvm::GlobalIFunc>(ResolverConstant)) {
40514057
ResolverConstant = IFunc->getResolver();
4052-
// In Aarch64, default versions of multiversioned functions are mangled to
4053-
// their 'normal' assembly name. This deviates from other targets which
4054-
// append a '.default' string. As a result we need to continue appending
4055-
// .ifunc in Aarch64.
4056-
// FIXME: Should Aarch64 mangling for 'default' multiversion function and
4057-
// in turn ifunc function match that of other targets?
4058-
if (FD->isTargetClonesMultiVersion() &&
4059-
!getTarget().getTriple().isAArch64()) {
4058+
if (FD->isTargetClonesMultiVersion()) {
40604059
const CGFunctionInfo &FI = getTypes().arrangeGlobalDeclaration(GD);
40614060
llvm::FunctionType *DeclTy = getTypes().GetFunctionType(FI);
40624061
std::string MangledName = getMangledNameImpl(
@@ -4236,14 +4235,7 @@ llvm::Constant *CodeGenModule::GetOrCreateMultiVersionResolver(GlobalDecl GD) {
42364235
// a separate resolver).
42374236
std::string ResolverName = MangledName;
42384237
if (getTarget().supportsIFunc()) {
4239-
// In Aarch64, default versions of multiversioned functions are mangled to
4240-
// their 'normal' assembly name. This deviates from other targets which
4241-
// append a '.default' string. As a result we need to continue appending
4242-
// .ifunc in Aarch64.
4243-
// FIXME: Should Aarch64 mangling for 'default' multiversion function and
4244-
// in turn ifunc function match that of other targets?
4245-
if (!FD->isTargetClonesMultiVersion() ||
4246-
getTarget().getTriple().isAArch64())
4238+
if (!FD->isTargetClonesMultiVersion())
42474239
ResolverName += ".ifunc";
42484240
} else if (FD->isTargetMultiVersion()) {
42494241
ResolverName += ".resolver";

0 commit comments

Comments
 (0)