1 //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "AArch64TargetObjectFile.h"
11 #include "AArch64TargetMachine.h"
12 #include "llvm/IR/Mangler.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCExpr.h"
15 #include "llvm/MC/MCStreamer.h"
16 #include "llvm/Support/Dwarf.h"
18 using namespace dwarf;
20 void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
21 const TargetMachine &TM) {
22 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
23 InitializeELF(TM.Options.UseInitArray);
26 AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
27 : TargetLoweringObjectFileMachO() {
28 SupportIndirectSymViaGOTPCRel = true;
29 SupportGOTPCRelWithOffset = false;
32 const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
33 const GlobalValue *GV, unsigned Encoding, Mangler &Mang,
34 const TargetMachine &TM, MachineModuleInfo *MMI,
35 MCStreamer &Streamer) const {
36 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
37 // is an indirect pc-relative reference. The default implementation
38 // won't reference using the GOT, so we need this target-specific
40 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
41 const MCSymbol *Sym = TM.getSymbol(GV, Mang);
43 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
44 MCSymbol *PCSym = getContext().CreateTempSymbol();
45 Streamer.EmitLabel(PCSym);
46 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext());
47 return MCBinaryExpr::CreateSub(Res, PC, getContext());
50 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
51 GV, Encoding, Mang, TM, MMI, Streamer);
54 MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
55 const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM,
56 MachineModuleInfo *MMI) const {
57 return TM.getSymbol(GV, Mang);
60 const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
61 const MCSymbol *Sym, int64_t Offset, MCStreamer &Streamer) const {
62 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
63 // is an indirect pc-relative reference.
65 MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
66 MCSymbol *PCSym = getContext().CreateTempSymbol();
67 Streamer.EmitLabel(PCSym);
68 const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext());
69 return MCBinaryExpr::CreateSub(Res, PC, getContext());