1*0b57cec5SDimitry Andric //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===// 2*0b57cec5SDimitry Andric // 3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*0b57cec5SDimitry Andric // 7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 8*0b57cec5SDimitry Andric 9*0b57cec5SDimitry Andric #include "AArch64TargetObjectFile.h" 10*0b57cec5SDimitry Andric #include "AArch64TargetMachine.h" 11*0b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h" 12*0b57cec5SDimitry Andric #include "llvm/IR/Mangler.h" 13*0b57cec5SDimitry Andric #include "llvm/MC/MCContext.h" 14*0b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h" 15*0b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h" 16*0b57cec5SDimitry Andric #include "llvm/MC/MCValue.h" 17*0b57cec5SDimitry Andric using namespace llvm; 18*0b57cec5SDimitry Andric using namespace dwarf; 19*0b57cec5SDimitry Andric 20*0b57cec5SDimitry Andric void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx, 21*0b57cec5SDimitry Andric const TargetMachine &TM) { 22*0b57cec5SDimitry Andric TargetLoweringObjectFileELF::Initialize(Ctx, TM); 23*0b57cec5SDimitry Andric InitializeELF(TM.Options.UseInitArray); 24*0b57cec5SDimitry Andric // AARCH64 ELF ABI does not define static relocation type for TLS offset 25*0b57cec5SDimitry Andric // within a module. Do not generate AT_location for TLS variables. 26*0b57cec5SDimitry Andric SupportDebugThreadLocalLocation = false; 27*0b57cec5SDimitry Andric } 28*0b57cec5SDimitry Andric 29*0b57cec5SDimitry Andric AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() 30*0b57cec5SDimitry Andric : TargetLoweringObjectFileMachO() { 31*0b57cec5SDimitry Andric SupportGOTPCRelWithOffset = false; 32*0b57cec5SDimitry Andric } 33*0b57cec5SDimitry Andric 34*0b57cec5SDimitry Andric const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference( 35*0b57cec5SDimitry Andric const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, 36*0b57cec5SDimitry Andric MachineModuleInfo *MMI, MCStreamer &Streamer) const { 37*0b57cec5SDimitry Andric // On Darwin, we can reference dwarf symbols with foo@GOT-., which 38*0b57cec5SDimitry Andric // is an indirect pc-relative reference. The default implementation 39*0b57cec5SDimitry Andric // won't reference using the GOT, so we need this target-specific 40*0b57cec5SDimitry Andric // version. 41*0b57cec5SDimitry Andric if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { 42*0b57cec5SDimitry Andric const MCSymbol *Sym = TM.getSymbol(GV); 43*0b57cec5SDimitry Andric const MCExpr *Res = 44*0b57cec5SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); 45*0b57cec5SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol(); 46*0b57cec5SDimitry Andric Streamer.EmitLabel(PCSym); 47*0b57cec5SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); 48*0b57cec5SDimitry Andric return MCBinaryExpr::createSub(Res, PC, getContext()); 49*0b57cec5SDimitry Andric } 50*0b57cec5SDimitry Andric 51*0b57cec5SDimitry Andric return TargetLoweringObjectFileMachO::getTTypeGlobalReference( 52*0b57cec5SDimitry Andric GV, Encoding, TM, MMI, Streamer); 53*0b57cec5SDimitry Andric } 54*0b57cec5SDimitry Andric 55*0b57cec5SDimitry Andric MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol( 56*0b57cec5SDimitry Andric const GlobalValue *GV, const TargetMachine &TM, 57*0b57cec5SDimitry Andric MachineModuleInfo *MMI) const { 58*0b57cec5SDimitry Andric return TM.getSymbol(GV); 59*0b57cec5SDimitry Andric } 60*0b57cec5SDimitry Andric 61*0b57cec5SDimitry Andric const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel( 62*0b57cec5SDimitry Andric const MCSymbol *Sym, const MCValue &MV, int64_t Offset, 63*0b57cec5SDimitry Andric MachineModuleInfo *MMI, MCStreamer &Streamer) const { 64*0b57cec5SDimitry Andric assert((Offset+MV.getConstant() == 0) && 65*0b57cec5SDimitry Andric "Arch64 does not support GOT PC rel with extra offset"); 66*0b57cec5SDimitry Andric // On ARM64 Darwin, we can reference symbols with foo@GOT-., which 67*0b57cec5SDimitry Andric // is an indirect pc-relative reference. 68*0b57cec5SDimitry Andric const MCExpr *Res = 69*0b57cec5SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); 70*0b57cec5SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol(); 71*0b57cec5SDimitry Andric Streamer.EmitLabel(PCSym); 72*0b57cec5SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); 73*0b57cec5SDimitry Andric return MCBinaryExpr::createSub(Res, PC, getContext()); 74*0b57cec5SDimitry Andric } 75*0b57cec5SDimitry Andric 76*0b57cec5SDimitry Andric void AArch64_MachoTargetObjectFile::getNameWithPrefix( 77*0b57cec5SDimitry Andric SmallVectorImpl<char> &OutName, const GlobalValue *GV, 78*0b57cec5SDimitry Andric const TargetMachine &TM) const { 79*0b57cec5SDimitry Andric // AArch64 does not use section-relative relocations so any global symbol must 80*0b57cec5SDimitry Andric // be accessed via at least a linker-private symbol. 81*0b57cec5SDimitry Andric getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true); 82*0b57cec5SDimitry Andric } 83