Skip to content

Commit a174a31

Browse files
committed
Target: Add target option for disabling AArch64_ELFTargetObjectFile::SupportIndirectSymViaGOTPCRel
The gold linker that comes with https://github.com/swiftlang/swift-docker/blob/main/swift-ci/main/ubuntu/24.04/Dockerfile (`GNU gold (GNU Binutils for Ubuntu 2.42) 1.16`) does not support this option and fails to link the standard library, so the Swift compiler needs a way to disable the option for AArch64 ELF. See: - #9339 - llvm#78003
1 parent f3db0cb commit a174a31

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

llvm/include/llvm/Target/TargetOptions.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class TargetOptions {
140140
DebugStrictDwarf(false), Hotpatch(false),
141141
PPCGenScalarMASSEntries(false), JMCInstrument(false),
142142
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
143+
SupportIndirectSymViaGOTPCRel_AArch64_ELF(true),
143144
VerifyArgABICompliance(true),
144145
FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
145146

@@ -373,6 +374,10 @@ class TargetOptions {
373374
/// into the RO data section.
374375
unsigned XCOFFReadOnlyPointers : 1;
375376

377+
/// When set to true, enables indirect symbol replacement with GOTPCREL for
378+
/// AArch64/ELF. The default is `true`.
379+
unsigned SupportIndirectSymViaGOTPCRel_AArch64_ELF : 1;
380+
376381
/// When set to true, call/return argument extensions of narrow integers
377382
/// are verified in the target backend if it cares about them. This is
378383
/// not done with internal tools like llc that run many tests that ignore

llvm/lib/Target/AArch64/AArch64TargetMachine.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,15 @@ void AArch64TargetMachine::reset() { SubtargetMap.clear(); }
280280
//===----------------------------------------------------------------------===//
281281
// AArch64 Lowering public interface.
282282
//===----------------------------------------------------------------------===//
283-
static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
283+
static std::unique_ptr<TargetLoweringObjectFile>
284+
createTLOF(const Triple &TT, const TargetOptions &Options) {
284285
if (TT.isOSBinFormatMachO())
285286
return std::make_unique<AArch64_MachoTargetObjectFile>();
286287
if (TT.isOSBinFormatCOFF())
287288
return std::make_unique<AArch64_COFFTargetObjectFile>();
288289

289-
return std::make_unique<AArch64_ELFTargetObjectFile>();
290+
return std::make_unique<AArch64_ELFTargetObjectFile>(
291+
Options.SupportIndirectSymViaGOTPCRel_AArch64_ELF);
290292
}
291293

292294
// Helper function to build a DataLayout string
@@ -367,7 +369,7 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
367369
computeDefaultCPU(TT, CPU), FS, Options,
368370
getEffectiveRelocModel(TT, RM),
369371
getEffectiveAArch64CodeModel(TT, CM, JIT), OL),
370-
TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
372+
TLOF(createTLOF(getTargetTriple(), Options)), isLittle(LittleEndian) {
371373
initAsmInfo();
372374

373375
if (TT.isOSBinFormatMachO()) {

llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
2626
const TargetMachine &TM) {
2727
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
2828
PLTRelativeSpecifier = AArch64::S_PLT;
29-
SupportIndirectSymViaGOTPCRel = true;
3029

3130
// AARCH64 ELF ABI does not define static relocation type for TLS offset
3231
// within a module. Do not generate AT_location for TLS variables.

llvm/lib/Target/AArch64/AArch64TargetObjectFile.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class AArch64_ELFTargetObjectFile : public TargetLoweringObjectFileELF {
2020
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
2121

2222
public:
23+
AArch64_ELFTargetObjectFile(bool SupportIndirectSymViaGOTPCRel) {
24+
this->SupportIndirectSymViaGOTPCRel = SupportIndirectSymViaGOTPCRel;
25+
}
26+
2327
const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV,
2428
const MCSymbol *Sym,
2529
const MCValue &MV, int64_t Offset,

0 commit comments

Comments
 (0)