[llvm] Target: Add target option for disabling `AArch64_ELFTargetObjectFile::SupportIndirectSymViaGOTPCRel` (PR #153910)
Anthony Latsis via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 15 19:09:38 PDT 2025
https://github.com/AnthonyLatsis updated https://github.com/llvm/llvm-project/pull/153910
>From a174a3170b2dcc42ca389dca1bd599054d0fc82c Mon Sep 17 00:00:00 2001
From: Anthony Latsis <alatsis at apple.com>
Date: Fri, 6 Jun 2025 14:08:59 +0100
Subject: [PATCH] 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:
- https://github.com/swiftlang/llvm-project/pull/9339
- https://github.com/llvm/llvm-project/pull/78003
---
llvm/include/llvm/Target/TargetOptions.h | 5 +++++
llvm/lib/Target/AArch64/AArch64TargetMachine.cpp | 8 +++++---
llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp | 1 -
llvm/lib/Target/AArch64/AArch64TargetObjectFile.h | 4 ++++
4 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index db90f2e4cc7cc..5bba0c0046fb2 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -140,6 +140,7 @@ class TargetOptions {
DebugStrictDwarf(false), Hotpatch(false),
PPCGenScalarMASSEntries(false), JMCInstrument(false),
EnableCFIFixup(false), MisExpect(false), XCOFFReadOnlyPointers(false),
+ SupportIndirectSymViaGOTPCRel_AArch64_ELF(true),
VerifyArgABICompliance(true),
FPDenormalMode(DenormalMode::IEEE, DenormalMode::IEEE) {}
@@ -373,6 +374,10 @@ class TargetOptions {
/// into the RO data section.
unsigned XCOFFReadOnlyPointers : 1;
+ /// When set to true, enables indirect symbol replacement with GOTPCREL for
+ /// AArch64/ELF. The default is `true`.
+ unsigned SupportIndirectSymViaGOTPCRel_AArch64_ELF : 1;
+
/// When set to true, call/return argument extensions of narrow integers
/// are verified in the target backend if it cares about them. This is
/// not done with internal tools like llc that run many tests that ignore
diff --git a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
index 95eab16511e5a..0a7b1f14fff75 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
@@ -280,13 +280,15 @@ void AArch64TargetMachine::reset() { SubtargetMap.clear(); }
//===----------------------------------------------------------------------===//
// AArch64 Lowering public interface.
//===----------------------------------------------------------------------===//
-static std::unique_ptr<TargetLoweringObjectFile> createTLOF(const Triple &TT) {
+static std::unique_ptr<TargetLoweringObjectFile>
+createTLOF(const Triple &TT, const TargetOptions &Options) {
if (TT.isOSBinFormatMachO())
return std::make_unique<AArch64_MachoTargetObjectFile>();
if (TT.isOSBinFormatCOFF())
return std::make_unique<AArch64_COFFTargetObjectFile>();
- return std::make_unique<AArch64_ELFTargetObjectFile>();
+ return std::make_unique<AArch64_ELFTargetObjectFile>(
+ Options.SupportIndirectSymViaGOTPCRel_AArch64_ELF);
}
// Helper function to build a DataLayout string
@@ -367,7 +369,7 @@ AArch64TargetMachine::AArch64TargetMachine(const Target &T, const Triple &TT,
computeDefaultCPU(TT, CPU), FS, Options,
getEffectiveRelocModel(TT, RM),
getEffectiveAArch64CodeModel(TT, CM, JIT), OL),
- TLOF(createTLOF(getTargetTriple())), isLittle(LittleEndian) {
+ TLOF(createTLOF(getTargetTriple(), Options)), isLittle(LittleEndian) {
initAsmInfo();
if (TT.isOSBinFormatMachO()) {
diff --git a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp
index 85de2d5010286..0b94b76b1aae8 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp
+++ b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp
@@ -26,7 +26,6 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
const TargetMachine &TM) {
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
PLTRelativeSpecifier = AArch64::S_PLT;
- SupportIndirectSymViaGOTPCRel = true;
// AARCH64 ELF ABI does not define static relocation type for TLS offset
// within a module. Do not generate AT_location for TLS variables.
diff --git a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.h b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
index 6b3381452c70b..45fdcb949b402 100644
--- a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
+++ b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.h
@@ -20,6 +20,10 @@ class AArch64_ELFTargetObjectFile : public TargetLoweringObjectFileELF {
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
public:
+ AArch64_ELFTargetObjectFile(bool SupportIndirectSymViaGOTPCRel) {
+ this->SupportIndirectSymViaGOTPCRel = SupportIndirectSymViaGOTPCRel;
+ }
+
const MCExpr *getIndirectSymViaGOTPCRel(const GlobalValue *GV,
const MCSymbol *Sym,
const MCValue &MV, int64_t Offset,
More information about the llvm-commits
mailing list