Skip to content

Commit 2ca8501

Browse files
authored
Revert "[ELF] Change Ctx::target to unique_ptr (#111260)" (#111449)
This patch seems to be breaking the windows build bots. https://lab.llvm.org/buildbot/#/builders/63/builds/1953 We also see this in Fuchsia's Linux CI: https://fxbug.dev/372010530 This reverts commit 4ec06b1.
1 parent 376b5c0 commit 2ca8501

19 files changed

+122
-81
lines changed

lld/ELF/Arch/AArch64.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,10 +1208,12 @@ void elf::createTaggedSymbols(Ctx &ctx) {
12081208
}
12091209
}
12101210

1211-
void elf::setAArch64TargetInfo(Ctx &ctx) {
1211+
TargetInfo *elf::getAArch64TargetInfo(Ctx &ctx) {
12121212
if ((ctx.arg.andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) ||
1213-
ctx.arg.zPacPlt)
1214-
ctx.target.reset(new AArch64BtiPac(ctx));
1215-
else
1216-
ctx.target.reset(new AArch64(ctx));
1213+
ctx.arg.zPacPlt) {
1214+
static AArch64BtiPac t(ctx);
1215+
return &t;
1216+
}
1217+
static AArch64 t(ctx);
1218+
return &t;
12171219
}

lld/ELF/Arch/AMDGPU.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,7 @@ int64_t AMDGPU::getImplicitAddend(const uint8_t *buf, RelType type) const {
219219
}
220220
}
221221

222-
void elf::setAMDGPUTargetInfo(Ctx &ctx) { ctx.target.reset(new AMDGPU(ctx)); }
222+
TargetInfo *elf::getAMDGPUTargetInfo(Ctx &ctx) {
223+
static AMDGPU target(ctx);
224+
return ⌖
225+
}

lld/ELF/Arch/ARM.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,10 @@ template <typename ELFT> void elf::writeARMCmseImportLib(Ctx &ctx) {
15331533
"': " + toString(std::move(e)));
15341534
}
15351535

1536-
void elf::setARMTargetInfo(Ctx &ctx) { ctx.target.reset(new ARM(ctx)); }
1536+
TargetInfo *elf::getARMTargetInfo(Ctx &ctx) {
1537+
static ARM target(ctx);
1538+
return &target;
1539+
}
15371540

15381541
template void elf::writeARMCmseImportLib<ELF32LE>(Ctx &);
15391542
template void elf::writeARMCmseImportLib<ELF32BE>(Ctx &);

lld/ELF/Arch/AVR.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,10 @@ void AVR::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
267267
}
268268
}
269269

270-
void elf::setAVRTargetInfo(Ctx &ctx) { ctx.target.reset(new AVR(ctx)); }
270+
TargetInfo *elf::getAVRTargetInfo(Ctx &ctx) {
271+
static AVR target(ctx);
272+
return &target;
273+
}
271274

272275
static uint32_t getEFlags(InputFile *file) {
273276
return cast<ObjFile<ELF32LE>>(file)->getObj().getHeader().e_flags;

lld/ELF/Arch/Hexagon.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,4 +404,7 @@ int64_t Hexagon::getImplicitAddend(const uint8_t *buf, RelType type) const {
404404
}
405405
}
406406

407-
void elf::setHexagonTargetInfo(Ctx &ctx) { ctx.target.reset(new Hexagon(ctx)); }
407+
TargetInfo *elf::getHexagonTargetInfo(Ctx &ctx) {
408+
static Hexagon target(ctx);
409+
return &target;
410+
}

lld/ELF/Arch/LoongArch.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ void LoongArch::finalizeRelax(int passes) const {
893893
}
894894
}
895895

896-
void elf::setLoongArchTargetInfo(Ctx &ctx) {
897-
ctx.target.reset(new LoongArch(ctx));
896+
TargetInfo *elf::getLoongArchTargetInfo(Ctx &ctx) {
897+
static LoongArch target(ctx);
898+
return &target;
898899
}

lld/ELF/Arch/MSP430.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,7 @@ void MSP430::relocate(uint8_t *loc, const Relocation &rel, uint64_t val) const {
8888
}
8989
}
9090

91-
void elf::setMSP430TargetInfo(Ctx &ctx) { ctx.target.reset(new MSP430(ctx)); }
91+
TargetInfo *elf::getMSP430TargetInfo(Ctx &ctx) {
92+
static MSP430 target(ctx);
93+
return &target;
94+
}

lld/ELF/Arch/Mips.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -779,23 +779,23 @@ template <class ELFT> bool elf::isMipsPIC(const Defined *sym) {
779779
return cast<ObjFile<ELFT>>(file)->getObj().getHeader().e_flags & EF_MIPS_PIC;
780780
}
781781

782-
void elf::setMipsTargetInfo(Ctx &ctx) {
782+
TargetInfo *elf::getMipsTargetInfo(Ctx &ctx) {
783783
switch (ctx.arg.ekind) {
784784
case ELF32LEKind: {
785-
ctx.target.reset(new MIPS<ELF32LE>(ctx));
786-
return;
785+
static MIPS<ELF32LE> t(ctx);
786+
return &t;
787787
}
788788
case ELF32BEKind: {
789-
ctx.target.reset(new MIPS<ELF32BE>(ctx));
790-
return;
789+
static MIPS<ELF32BE> t(ctx);
790+
return &t;
791791
}
792792
case ELF64LEKind: {
793-
ctx.target.reset(new MIPS<ELF64LE>(ctx));
794-
return;
793+
static MIPS<ELF64LE> t(ctx);
794+
return &t;
795795
}
796796
case ELF64BEKind: {
797-
ctx.target.reset(new MIPS<ELF64BE>(ctx));
798-
return;
797+
static MIPS<ELF64BE> t(ctx);
798+
return &t;
799799
}
800800
default:
801801
llvm_unreachable("unsupported target");

lld/ELF/Arch/PPC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,4 +523,7 @@ void PPC::relocateAlloc(InputSectionBase &sec, uint8_t *buf) const {
523523
}
524524
}
525525

526-
void elf::setPPCTargetInfo(Ctx &ctx) { ctx.target.reset(new PPC(ctx)); }
526+
TargetInfo *elf::getPPCTargetInfo(Ctx &ctx) {
527+
static PPC target(ctx);
528+
return &target;
529+
}

lld/ELF/Arch/PPC64.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1747,4 +1747,7 @@ bool PPC64::adjustPrologueForCrossSplitStack(uint8_t *loc, uint8_t *end,
17471747
return true;
17481748
}
17491749

1750-
void elf::setPPC64TargetInfo(Ctx &ctx) { ctx.target.reset(new PPC64(ctx)); }
1750+
TargetInfo *elf::getPPC64TargetInfo(Ctx &ctx) {
1751+
static PPC64 target(ctx);
1752+
return &target;
1753+
}

0 commit comments

Comments
 (0)