blob: 8ae72a7ddb573654c6b6d499dd11ab8bd85c8e12 [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);
Lei Liu8e422b82018-08-01 23:46:49 +000025 // AARCH64 ELF ABI does not define static relocation type for TLS offset
26 // within a module. Do not generate AT_location for TLS variables.
27 SupportDebugThreadLocalLocation = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000028}
29
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000030AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
31 : TargetLoweringObjectFileMachO() {
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000032 SupportGOTPCRelWithOffset = false;
33}
34
Tim Northover3b0846e2014-05-24 12:50:23 +000035const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000036 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
37 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Tim Northover3b0846e2014-05-24 12:50:23 +000038 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
39 // is an indirect pc-relative reference. The default implementation
40 // won't reference using the GOT, so we need this target-specific
41 // version.
42 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
Tim Northoverb64fb452016-11-22 16:17:20 +000043 const MCSymbol *Sym = TM.getSymbol(GV);
Tim Northover3b0846e2014-05-24 12:50:23 +000044 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000045 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
Jim Grosbach6f482002015-05-18 18:43:14 +000046 MCSymbol *PCSym = getContext().createTempSymbol();
Tim Northover3b0846e2014-05-24 12:50:23 +000047 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000048 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
49 return MCBinaryExpr::createSub(Res, PC, getContext());
Tim Northover3b0846e2014-05-24 12:50:23 +000050 }
51
52 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000053 GV, Encoding, TM, MMI, Streamer);
Tim Northover3b0846e2014-05-24 12:50:23 +000054}
55
56MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
Eric Christopher4367c7f2016-09-16 07:33:15 +000057 const GlobalValue *GV, const TargetMachine &TM,
Tim Northover3b0846e2014-05-24 12:50:23 +000058 MachineModuleInfo *MMI) const {
Tim Northoverb64fb452016-11-22 16:17:20 +000059 return TM.getSymbol(GV);
Tim Northover3b0846e2014-05-24 12:50:23 +000060}
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000061
62const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
Bruno Cardoso Lopes618c67a2015-03-06 13:49:05 +000063 const MCSymbol *Sym, const MCValue &MV, int64_t Offset,
64 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
65 assert((Offset+MV.getConstant() == 0) &&
66 "Arch64 does not support GOT PC rel with extra offset");
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000067 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
68 // is an indirect pc-relative reference.
69 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000070 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
Jim Grosbach6f482002015-05-18 18:43:14 +000071 MCSymbol *PCSym = getContext().createTempSymbol();
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000072 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000073 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
74 return MCBinaryExpr::createSub(Res, PC, getContext());
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000075}
Tim Northover203c6f02017-05-15 21:51:38 +000076
77void AArch64_MachoTargetObjectFile::getNameWithPrefix(
78 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
79 const TargetMachine &TM) const {
80 // AArch64 does not use section-relative relocations so any global symbol must
81 // be accessed via at least a linker-private symbol.
82 getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
83}