blob: 4bc2c060a0684ec2d9b5f263bc7edd1b9d565e7e [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "AArch64TargetObjectFile.h"
11#include "AArch64TargetMachine.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000012#include "llvm/BinaryFormat/Dwarf.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000013#include "llvm/IR/Mangler.h"
14#include "llvm/MC/MCContext.h"
15#include "llvm/MC/MCExpr.h"
16#include "llvm/MC/MCStreamer.h"
Bruno Cardoso Lopes618c67a2015-03-06 13:49:05 +000017#include "llvm/MC/MCValue.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000018using namespace llvm;
19using namespace dwarf;
20
21void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
22 const TargetMachine &TM) {
23 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
24 InitializeELF(TM.Options.UseInitArray);
25}
26
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000027AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
28 : TargetLoweringObjectFileMachO() {
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000029 SupportGOTPCRelWithOffset = false;
30}
31
Tim Northover3b0846e2014-05-24 12:50:23 +000032const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000033 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
34 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Tim Northover3b0846e2014-05-24 12:50:23 +000035 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
36 // is an indirect pc-relative reference. The default implementation
37 // won't reference using the GOT, so we need this target-specific
38 // version.
39 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
Tim Northoverb64fb452016-11-22 16:17:20 +000040 const MCSymbol *Sym = TM.getSymbol(GV);
Tim Northover3b0846e2014-05-24 12:50:23 +000041 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000042 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
Jim Grosbach6f482002015-05-18 18:43:14 +000043 MCSymbol *PCSym = getContext().createTempSymbol();
Tim Northover3b0846e2014-05-24 12:50:23 +000044 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000045 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
46 return MCBinaryExpr::createSub(Res, PC, getContext());
Tim Northover3b0846e2014-05-24 12:50:23 +000047 }
48
49 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000050 GV, Encoding, TM, MMI, Streamer);
Tim Northover3b0846e2014-05-24 12:50:23 +000051}
52
53MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
Eric Christopher4367c7f2016-09-16 07:33:15 +000054 const GlobalValue *GV, const TargetMachine &TM,
Tim Northover3b0846e2014-05-24 12:50:23 +000055 MachineModuleInfo *MMI) const {
Tim Northoverb64fb452016-11-22 16:17:20 +000056 return TM.getSymbol(GV);
Tim Northover3b0846e2014-05-24 12:50:23 +000057}
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000058
59const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
Bruno Cardoso Lopes618c67a2015-03-06 13:49:05 +000060 const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
61 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
62 assert((Offset+MV.getConstant() == 0) &&
63 "Arch64 does not support GOT PC rel with extra offset");
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000064 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
65 // is an indirect pc-relative reference.
66 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000067 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
Jim Grosbach6f482002015-05-18 18:43:14 +000068 MCSymbol *PCSym = getContext().createTempSymbol();
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000069 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000070 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
71 return MCBinaryExpr::createSub(Res, PC, getContext());
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000072}
Tim Northover203c6f02017-05-15 21:51:38 +000073
74void AArch64_MachoTargetObjectFile::getNameWithPrefix(
75 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
76 const TargetMachine &TM) const {
77 // AArch64 does not use section-relative relocations so any global symbol must
78 // be accessed via at least a linker-private symbol.
79 getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
80}