blob: 54562094fcf56b038c24149e3b65c7ac49df93fd [file] [log] [blame]
Tim Northover3b0846e2014-05-24 12:50:23 +00001//===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Tim Northover3b0846e2014-05-24 12:50:23 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "AArch64TargetObjectFile.h"
10#include "AArch64TargetMachine.h"
Zachary Turner264b5d92017-06-07 03:48:56 +000011#include "llvm/BinaryFormat/Dwarf.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000012#include "llvm/IR/Mangler.h"
13#include "llvm/MC/MCContext.h"
14#include "llvm/MC/MCExpr.h"
15#include "llvm/MC/MCStreamer.h"
Bruno Cardoso Lopes618c67a2015-03-06 13:49:05 +000016#include "llvm/MC/MCValue.h"
Tim Northover3b0846e2014-05-24 12:50:23 +000017using namespace llvm;
18using namespace dwarf;
19
20void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
21 const TargetMachine &TM) {
22 TargetLoweringObjectFileELF::Initialize(Ctx, TM);
23 InitializeELF(TM.Options.UseInitArray);
Lei Liu8e422b82018-08-01 23:46:49 +000024 // AARCH64 ELF ABI does not define static relocation type for TLS offset
25 // within a module. Do not generate AT_location for TLS variables.
26 SupportDebugThreadLocalLocation = false;
Tim Northover3b0846e2014-05-24 12:50:23 +000027}
28
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000029AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
30 : TargetLoweringObjectFileMachO() {
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000031 SupportGOTPCRelWithOffset = false;
32}
33
Tim Northover3b0846e2014-05-24 12:50:23 +000034const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000035 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
36 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Tim Northover3b0846e2014-05-24 12:50:23 +000037 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
38 // is an indirect pc-relative reference. The default implementation
39 // won't reference using the GOT, so we need this target-specific
40 // version.
41 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
Tim Northoverb64fb452016-11-22 16:17:20 +000042 const MCSymbol *Sym = TM.getSymbol(GV);
Tim Northover3b0846e2014-05-24 12:50:23 +000043 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000044 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
Jim Grosbach6f482002015-05-18 18:43:14 +000045 MCSymbol *PCSym = getContext().createTempSymbol();
Tim Northover3b0846e2014-05-24 12:50:23 +000046 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000047 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
48 return MCBinaryExpr::createSub(Res, PC, getContext());
Tim Northover3b0846e2014-05-24 12:50:23 +000049 }
50
51 return TargetLoweringObjectFileMachO::getTTypeGlobalReference(
Eric Christopher4367c7f2016-09-16 07:33:15 +000052 GV, Encoding, TM, MMI, Streamer);
Tim Northover3b0846e2014-05-24 12:50:23 +000053}
54
55MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol(
Eric Christopher4367c7f2016-09-16 07:33:15 +000056 const GlobalValue *GV, const TargetMachine &TM,
Tim Northover3b0846e2014-05-24 12:50:23 +000057 MachineModuleInfo *MMI) const {
Tim Northoverb64fb452016-11-22 16:17:20 +000058 return TM.getSymbol(GV);
Tim Northover3b0846e2014-05-24 12:50:23 +000059}
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000060
61const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel(
Francis Visoiu Mistrih5b5ee612019-08-22 16:59:00 +000062 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
63 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
Bruno Cardoso Lopes618c67a2015-03-06 13:49:05 +000064 assert((Offset+MV.getConstant() == 0) &&
65 "Arch64 does not support GOT PC rel with extra offset");
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000066 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
67 // is an indirect pc-relative reference.
68 const MCExpr *Res =
Jim Grosbach13760bd2015-05-30 01:25:56 +000069 MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext());
Jim Grosbach6f482002015-05-18 18:43:14 +000070 MCSymbol *PCSym = getContext().createTempSymbol();
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000071 Streamer.EmitLabel(PCSym);
Jim Grosbach13760bd2015-05-30 01:25:56 +000072 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
73 return MCBinaryExpr::createSub(Res, PC, getContext());
Bruno Cardoso Lopes52b13912015-03-06 13:48:45 +000074}
Tim Northover203c6f02017-05-15 21:51:38 +000075
76void AArch64_MachoTargetObjectFile::getNameWithPrefix(
77 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
78 const TargetMachine &TM) const {
79 // AArch64 does not use section-relative relocations so any global symbol must
80 // be accessed via at least a linker-private symbol.
81 getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
82}