diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index a49413c8a6527..7954efafd51d1 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -154,6 +154,7 @@ namespace llvm { XRayFunctionIndex(true), 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) {} @@ -389,6 +390,10 @@ namespace llvm { /// into the RO data section. unsigned XCOFFReadOnlyPointers : 1; + /// When set to true, enables indirect symbol replacement with GOTPCREL for + /// AArch64/ELF. + 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 5693a551e679f..c1bf4c9c0c233 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetMachine.cpp @@ -278,13 +278,15 @@ void AArch64TargetMachine::reset() { SubtargetMap.clear(); } //===----------------------------------------------------------------------===// // AArch64 Lowering public interface. //===----------------------------------------------------------------------===// -static std::unique_ptr createTLOF(const Triple &TT) { +static std::unique_ptr +createTLOF(const Triple &TT, const TargetOptions &Options) { if (TT.isOSBinFormatMachO()) return std::make_unique(); if (TT.isOSBinFormatCOFF()) return std::make_unique(); - return std::make_unique(); + return std::make_unique( + Options.SupportIndirectSymViaGOTPCRel_AArch64_ELF); } // Helper function to build a DataLayout string @@ -365,7 +367,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 8003f638ce46e..fc8b17e03cc68 100644 --- a/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp @@ -27,7 +27,6 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) { TargetLoweringObjectFileELF::Initialize(Ctx, TM); PLTRelativeSpecifier = AArch64MCExpr::VK_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 01700e98ce3bd..aeee7a1937706 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,