13b0846e8STim Northover //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
23b0846e8STim Northover //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
63b0846e8STim Northover //
73b0846e8STim Northover //===----------------------------------------------------------------------===//
83b0846e8STim Northover
93b0846e8STim Northover #include "AArch64TargetObjectFile.h"
103b0846e8STim Northover #include "AArch64TargetMachine.h"
11264b5d9eSZachary Turner #include "llvm/BinaryFormat/Dwarf.h"
123b0846e8STim Northover #include "llvm/IR/Mangler.h"
133b0846e8STim Northover #include "llvm/MC/MCContext.h"
143b0846e8STim Northover #include "llvm/MC/MCExpr.h"
153b0846e8STim Northover #include "llvm/MC/MCStreamer.h"
16618c67a0SBruno Cardoso Lopes #include "llvm/MC/MCValue.h"
173b0846e8STim Northover using namespace llvm;
183b0846e8STim Northover using namespace dwarf;
193b0846e8STim Northover
Initialize(MCContext & Ctx,const TargetMachine & TM)203b0846e8STim Northover void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
213b0846e8STim Northover const TargetMachine &TM) {
223b0846e8STim Northover TargetLoweringObjectFileELF::Initialize(Ctx, TM);
238e422b84SLei Liu // AARCH64 ELF ABI does not define static relocation type for TLS offset
248e422b84SLei Liu // within a module. Do not generate AT_location for TLS variables.
258e422b84SLei Liu SupportDebugThreadLocalLocation = false;
263b0846e8STim Northover }
273b0846e8STim Northover
AArch64_MachoTargetObjectFile()28*f3a344d2SKazu Hirata AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() {
2952b1391dSBruno Cardoso Lopes SupportGOTPCRelWithOffset = false;
3052b1391dSBruno Cardoso Lopes }
3152b1391dSBruno Cardoso Lopes
getTTypeGlobalReference(const GlobalValue * GV,unsigned Encoding,const TargetMachine & TM,MachineModuleInfo * MMI,MCStreamer & Streamer) const323b0846e8STim Northover const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
334367c7fbSEric Christopher const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
344367c7fbSEric Christopher MachineModuleInfo *MMI, MCStreamer &Streamer) const {
353b0846e8STim Northover // On Darwin, we can reference dwarf symbols with foo@GOT-., which
363b0846e8STim Northover // is an indirect pc-relative reference. The default implementation
373b0846e8STim Northover // won't reference using the GOT, so we need this target-specific
383b0846e8STim Northover // version.
393b0846e8STim Northover if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
40b64fb453STim Northover const MCSymbol *Sym = TM.getSymbol(GV);
413b0846e8STim Northover const MCExpr *Res =
4213760bd1SJim Grosbach MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
436f482000SJim Grosbach MCSymbol *PCSym = getContext().createTempSymbol();
446d2d589bSFangrui Song Streamer.emitLabel(PCSym);
4513760bd1SJim Grosbach const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
4613760bd1SJim Grosbach return MCBinaryExpr::createSub(Res, PC, getContext());
473b0846e8STim Northover }
483b0846e8STim Northover
493b0846e8STim Northover return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
504367c7fbSEric Christopher GV, Encoding, TM, MMI, Streamer);
513b0846e8STim Northover }
523b0846e8STim Northover
getCFIPersonalitySymbol(const GlobalValue * GV,const TargetMachine & TM,MachineModuleInfo * MMI) const533b0846e8STim Northover MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
544367c7fbSEric Christopher const GlobalValue *GV, const TargetMachine &TM,
553b0846e8STim Northover MachineModuleInfo *MMI) const {
56b64fb453STim Northover return TM.getSymbol(GV);
573b0846e8STim Northover }
5852b1391dSBruno Cardoso Lopes
getIndirectSymViaGOTPCRel(const GlobalValue * GV,const MCSymbol * Sym,const MCValue & MV,int64_t Offset,MachineModuleInfo * MMI,MCStreamer & Streamer) const5952b1391dSBruno Cardoso Lopes const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
605b5ee61bSFrancis Visoiu Mistrih const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
615b5ee61bSFrancis Visoiu Mistrih int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
62618c67a0SBruno Cardoso Lopes assert((Offset+MV.getConstant() == 0) &&
63618c67a0SBruno Cardoso Lopes "Arch64 does not support GOT PC rel with extra offset");
6452b1391dSBruno Cardoso Lopes // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
6552b1391dSBruno Cardoso Lopes // is an indirect pc-relative reference.
6652b1391dSBruno Cardoso Lopes const MCExpr *Res =
6713760bd1SJim Grosbach MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
686f482000SJim Grosbach MCSymbol *PCSym = getContext().createTempSymbol();
696d2d589bSFangrui Song Streamer.emitLabel(PCSym);
7013760bd1SJim Grosbach const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
7113760bd1SJim Grosbach return MCBinaryExpr::createSub(Res, PC, getContext());
7252b1391dSBruno Cardoso Lopes }
73203c6f05STim Northover
getNameWithPrefix(SmallVectorImpl<char> & OutName,const GlobalValue * GV,const TargetMachine & TM) const74203c6f05STim Northover void AArch64_MachoTargetObjectFile::getNameWithPrefix(
75203c6f05STim Northover SmallVectorImpl<char> &OutName, const GlobalValue *GV,
76203c6f05STim Northover const TargetMachine &TM) const {
77203c6f05STim Northover // AArch64 does not use section-relative relocations so any global symbol must
78203c6f05STim Northover // be accessed via at least a linker-private symbol.
79203c6f05STim Northover getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
80203c6f05STim Northover }
81