1139f7f9bSDimitry Andric //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
2139f7f9bSDimitry Andric //
3139f7f9bSDimitry Andric // The LLVM Compiler Infrastructure
4139f7f9bSDimitry Andric //
5139f7f9bSDimitry Andric // This file is distributed under the University of Illinois Open Source
6139f7f9bSDimitry Andric // License. See LICENSE.TXT for details.
7139f7f9bSDimitry Andric //
8139f7f9bSDimitry Andric //===----------------------------------------------------------------------===//
9139f7f9bSDimitry Andric
10139f7f9bSDimitry Andric #include "AArch64TargetObjectFile.h"
1191bc56edSDimitry Andric #include "AArch64TargetMachine.h"
12db17bf38SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h"
1391bc56edSDimitry Andric #include "llvm/IR/Mangler.h"
1491bc56edSDimitry Andric #include "llvm/MC/MCContext.h"
1591bc56edSDimitry Andric #include "llvm/MC/MCExpr.h"
1691bc56edSDimitry Andric #include "llvm/MC/MCStreamer.h"
17ff0cc061SDimitry Andric #include "llvm/MC/MCValue.h"
18139f7f9bSDimitry Andric using namespace llvm;
1991bc56edSDimitry Andric using namespace dwarf;
20139f7f9bSDimitry Andric
Initialize(MCContext & Ctx,const TargetMachine & TM)2191bc56edSDimitry Andric void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
22139f7f9bSDimitry Andric const TargetMachine &TM) {
23139f7f9bSDimitry Andric TargetLoweringObjectFileELF::Initialize(Ctx, TM);
24139f7f9bSDimitry Andric InitializeELF(TM.Options.UseInitArray);
25*b5893f02SDimitry Andric // AARCH64 ELF ABI does not define static relocation type for TLS offset
26*b5893f02SDimitry Andric // within a module. Do not generate AT_location for TLS variables.
27*b5893f02SDimitry Andric SupportDebugThreadLocalLocation = false;
28139f7f9bSDimitry Andric }
2985d60e68SDimitry Andric
AArch64_MachoTargetObjectFile()30ff0cc061SDimitry Andric AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
31ff0cc061SDimitry Andric : TargetLoweringObjectFileMachO() {
32ff0cc061SDimitry Andric SupportGOTPCRelWithOffset = false;
33ff0cc061SDimitry Andric }
34ff0cc061SDimitry Andric
getTTypeGlobalReference(const GlobalValue * GV,unsigned Encoding,const TargetMachine & TM,MachineModuleInfo * MMI,MCStreamer & Streamer) const3591bc56edSDimitry Andric const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
36d88c1a5aSDimitry Andric const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
37d88c1a5aSDimitry Andric MachineModuleInfo *MMI, MCStreamer &Streamer) const {
3891bc56edSDimitry Andric // On Darwin, we can reference dwarf symbols with foo@GOT-., which
3991bc56edSDimitry Andric // is an indirect pc-relative reference. The default implementation
4091bc56edSDimitry Andric // won't reference using the GOT, so we need this target-specific
4191bc56edSDimitry Andric // version.
4291bc56edSDimitry Andric if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
43d88c1a5aSDimitry Andric const MCSymbol *Sym = TM.getSymbol(GV);
4491bc56edSDimitry Andric const MCExpr *Res =
4597bc6c73SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
46ff0cc061SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol();
4791bc56edSDimitry Andric Streamer.EmitLabel(PCSym);
4897bc6c73SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
4997bc6c73SDimitry Andric return MCBinaryExpr::createSub(Res, PC, getContext());
5091bc56edSDimitry Andric }
5191bc56edSDimitry Andric
5291bc56edSDimitry Andric return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
53d88c1a5aSDimitry Andric GV, Encoding, TM, MMI, Streamer);
5491bc56edSDimitry Andric }
5591bc56edSDimitry Andric
getCFIPersonalitySymbol(const GlobalValue * GV,const TargetMachine & TM,MachineModuleInfo * MMI) const5691bc56edSDimitry Andric MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
57d88c1a5aSDimitry Andric const GlobalValue *GV, const TargetMachine &TM,
5891bc56edSDimitry Andric MachineModuleInfo *MMI) const {
59d88c1a5aSDimitry Andric return TM.getSymbol(GV);
6085d60e68SDimitry Andric }
61ff0cc061SDimitry Andric
getIndirectSymViaGOTPCRel(const MCSymbol * Sym,const MCValue & MV,int64_t Offset,MachineModuleInfo * MMI,MCStreamer & Streamer) const62ff0cc061SDimitry Andric const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
63ff0cc061SDimitry Andric const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
64ff0cc061SDimitry Andric MachineModuleInfo *MMI, MCStreamer &Streamer) const {
65ff0cc061SDimitry Andric assert((Offset+MV.getConstant() == 0) &&
66ff0cc061SDimitry Andric "Arch64 does not support GOT PC rel with extra offset");
67ff0cc061SDimitry Andric // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
68ff0cc061SDimitry Andric // is an indirect pc-relative reference.
69ff0cc061SDimitry Andric const MCExpr *Res =
7097bc6c73SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
71ff0cc061SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol();
72ff0cc061SDimitry Andric Streamer.EmitLabel(PCSym);
7397bc6c73SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
7497bc6c73SDimitry Andric return MCBinaryExpr::createSub(Res, PC, getContext());
75ff0cc061SDimitry Andric }
765517e702SDimitry Andric
getNameWithPrefix(SmallVectorImpl<char> & OutName,const GlobalValue * GV,const TargetMachine & TM) const775517e702SDimitry Andric void AArch64_MachoTargetObjectFile::getNameWithPrefix(
785517e702SDimitry Andric SmallVectorImpl<char> &OutName, const GlobalValue *GV,
795517e702SDimitry Andric const TargetMachine &TM) const {
805517e702SDimitry Andric // AArch64 does not use section-relative relocations so any global symbol must
815517e702SDimitry Andric // be accessed via at least a linker-private symbol.
825517e702SDimitry Andric getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
835517e702SDimitry Andric }
84