1*9880d681SAndroid Build Coastguard Worker //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker // The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker #include "AArch64TargetObjectFile.h"
11*9880d681SAndroid Build Coastguard Worker #include "AArch64TargetMachine.h"
12*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Mangler.h"
13*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCContext.h"
14*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCExpr.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCStreamer.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/MC/MCValue.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/Support/Dwarf.h"
18*9880d681SAndroid Build Coastguard Worker using namespace llvm;
19*9880d681SAndroid Build Coastguard Worker using namespace dwarf;
20*9880d681SAndroid Build Coastguard Worker
Initialize(MCContext & Ctx,const TargetMachine & TM)21*9880d681SAndroid Build Coastguard Worker void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
22*9880d681SAndroid Build Coastguard Worker const TargetMachine &TM) {
23*9880d681SAndroid Build Coastguard Worker TargetLoweringObjectFileELF::Initialize(Ctx, TM);
24*9880d681SAndroid Build Coastguard Worker InitializeELF(TM.Options.UseInitArray);
25*9880d681SAndroid Build Coastguard Worker }
26*9880d681SAndroid Build Coastguard Worker
AArch64_MachoTargetObjectFile()27*9880d681SAndroid Build Coastguard Worker AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
28*9880d681SAndroid Build Coastguard Worker : TargetLoweringObjectFileMachO() {
29*9880d681SAndroid Build Coastguard Worker SupportGOTPCRelWithOffset = false;
30*9880d681SAndroid Build Coastguard Worker }
31*9880d681SAndroid Build Coastguard Worker
getTTypeGlobalReference(const GlobalValue * GV,unsigned Encoding,Mangler & Mang,const TargetMachine & TM,MachineModuleInfo * MMI,MCStreamer & Streamer) const32*9880d681SAndroid Build Coastguard Worker const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
33*9880d681SAndroid Build Coastguard Worker const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
34*9880d681SAndroid Build Coastguard Worker const TargetMachine &TM, MachineModuleInfo *MMI,
35*9880d681SAndroid Build Coastguard Worker MCStreamer &Streamer) const {
36*9880d681SAndroid Build Coastguard Worker // On Darwin, we can reference dwarf symbols with foo@GOT-., which
37*9880d681SAndroid Build Coastguard Worker // is an indirect pc-relative reference. The default implementation
38*9880d681SAndroid Build Coastguard Worker // won't reference using the GOT, so we need this target-specific
39*9880d681SAndroid Build Coastguard Worker // version.
40*9880d681SAndroid Build Coastguard Worker if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
41*9880d681SAndroid Build Coastguard Worker const MCSymbol *Sym = TM.getSymbol(GV, Mang);
42*9880d681SAndroid Build Coastguard Worker const MCExpr *Res =
43*9880d681SAndroid Build Coastguard Worker MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
44*9880d681SAndroid Build Coastguard Worker MCSymbol *PCSym = getContext().createTempSymbol();
45*9880d681SAndroid Build Coastguard Worker Streamer.EmitLabel(PCSym);
46*9880d681SAndroid Build Coastguard Worker const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
47*9880d681SAndroid Build Coastguard Worker return MCBinaryExpr::createSub(Res, PC, getContext());
48*9880d681SAndroid Build Coastguard Worker }
49*9880d681SAndroid Build Coastguard Worker
50*9880d681SAndroid Build Coastguard Worker return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
51*9880d681SAndroid Build Coastguard Worker GV, Encoding, Mang, TM, MMI, Streamer);
52*9880d681SAndroid Build Coastguard Worker }
53*9880d681SAndroid Build Coastguard Worker
getCFIPersonalitySymbol(const GlobalValue * GV,Mangler & Mang,const TargetMachine & TM,MachineModuleInfo * MMI) const54*9880d681SAndroid Build Coastguard Worker MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
55*9880d681SAndroid Build Coastguard Worker const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
56*9880d681SAndroid Build Coastguard Worker MachineModuleInfo *MMI) const {
57*9880d681SAndroid Build Coastguard Worker return TM.getSymbol(GV, Mang);
58*9880d681SAndroid Build Coastguard Worker }
59*9880d681SAndroid Build Coastguard Worker
getIndirectSymViaGOTPCRel(const MCSymbol * Sym,const MCValue & MV,int64_t Offset,MachineModuleInfo * MMI,MCStreamer & Streamer) const60*9880d681SAndroid Build Coastguard Worker const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
61*9880d681SAndroid Build Coastguard Worker const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
62*9880d681SAndroid Build Coastguard Worker MachineModuleInfo *MMI, MCStreamer &Streamer) const {
63*9880d681SAndroid Build Coastguard Worker assert((Offset+MV.getConstant() == 0) &&
64*9880d681SAndroid Build Coastguard Worker "Arch64 does not support GOT PC rel with extra offset");
65*9880d681SAndroid Build Coastguard Worker // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
66*9880d681SAndroid Build Coastguard Worker // is an indirect pc-relative reference.
67*9880d681SAndroid Build Coastguard Worker const MCExpr *Res =
68*9880d681SAndroid Build Coastguard Worker MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
69*9880d681SAndroid Build Coastguard Worker MCSymbol *PCSym = getContext().createTempSymbol();
70*9880d681SAndroid Build Coastguard Worker Streamer.EmitLabel(PCSym);
71*9880d681SAndroid Build Coastguard Worker const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
72*9880d681SAndroid Build Coastguard Worker return MCBinaryExpr::createSub(Res, PC, getContext());
73*9880d681SAndroid Build Coastguard Worker }
74