10b57cec5SDimitry Andric //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "AArch64TargetObjectFile.h" 100b57cec5SDimitry Andric #include "AArch64TargetMachine.h" 110b57cec5SDimitry Andric #include "llvm/BinaryFormat/Dwarf.h" 120b57cec5SDimitry Andric #include "llvm/IR/Mangler.h" 130b57cec5SDimitry Andric #include "llvm/MC/MCContext.h" 140b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h" 150b57cec5SDimitry Andric #include "llvm/MC/MCStreamer.h" 160b57cec5SDimitry Andric #include "llvm/MC/MCValue.h" 170b57cec5SDimitry Andric using namespace llvm; 180b57cec5SDimitry Andric using namespace dwarf; 190b57cec5SDimitry Andric 200b57cec5SDimitry Andric void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx, 210b57cec5SDimitry Andric const TargetMachine &TM) { 220b57cec5SDimitry Andric TargetLoweringObjectFileELF::Initialize(Ctx, TM); 230b57cec5SDimitry Andric // AARCH64 ELF ABI does not define static relocation type for TLS offset 240b57cec5SDimitry Andric // within a module. Do not generate AT_location for TLS variables. 250b57cec5SDimitry Andric SupportDebugThreadLocalLocation = false; 260b57cec5SDimitry Andric } 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() 290b57cec5SDimitry Andric : TargetLoweringObjectFileMachO() { 300b57cec5SDimitry Andric SupportGOTPCRelWithOffset = false; 310b57cec5SDimitry Andric } 320b57cec5SDimitry Andric 330b57cec5SDimitry Andric const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference( 340b57cec5SDimitry Andric const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, 350b57cec5SDimitry Andric MachineModuleInfo *MMI, MCStreamer &Streamer) const { 360b57cec5SDimitry Andric // On Darwin, we can reference dwarf symbols with foo@GOT-., which 370b57cec5SDimitry Andric // is an indirect pc-relative reference. The default implementation 380b57cec5SDimitry Andric // won't reference using the GOT, so we need this target-specific 390b57cec5SDimitry Andric // version. 400b57cec5SDimitry Andric if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { 410b57cec5SDimitry Andric const MCSymbol *Sym = TM.getSymbol(GV); 420b57cec5SDimitry Andric const MCExpr *Res = 430b57cec5SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); 440b57cec5SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol(); 45*5ffd83dbSDimitry Andric Streamer.emitLabel(PCSym); 460b57cec5SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); 470b57cec5SDimitry Andric return MCBinaryExpr::createSub(Res, PC, getContext()); 480b57cec5SDimitry Andric } 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric return TargetLoweringObjectFileMachO::getTTypeGlobalReference( 510b57cec5SDimitry Andric GV, Encoding, TM, MMI, Streamer); 520b57cec5SDimitry Andric } 530b57cec5SDimitry Andric 540b57cec5SDimitry Andric MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol( 550b57cec5SDimitry Andric const GlobalValue *GV, const TargetMachine &TM, 560b57cec5SDimitry Andric MachineModuleInfo *MMI) const { 570b57cec5SDimitry Andric return TM.getSymbol(GV); 580b57cec5SDimitry Andric } 590b57cec5SDimitry Andric 600b57cec5SDimitry Andric const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel( 618bcb0991SDimitry Andric const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, 628bcb0991SDimitry Andric int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const { 630b57cec5SDimitry Andric assert((Offset+MV.getConstant() == 0) && 640b57cec5SDimitry Andric "Arch64 does not support GOT PC rel with extra offset"); 650b57cec5SDimitry Andric // On ARM64 Darwin, we can reference symbols with foo@GOT-., which 660b57cec5SDimitry Andric // is an indirect pc-relative reference. 670b57cec5SDimitry Andric const MCExpr *Res = 680b57cec5SDimitry Andric MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); 690b57cec5SDimitry Andric MCSymbol *PCSym = getContext().createTempSymbol(); 70*5ffd83dbSDimitry Andric Streamer.emitLabel(PCSym); 710b57cec5SDimitry Andric const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); 720b57cec5SDimitry Andric return MCBinaryExpr::createSub(Res, PC, getContext()); 730b57cec5SDimitry Andric } 740b57cec5SDimitry Andric 750b57cec5SDimitry Andric void AArch64_MachoTargetObjectFile::getNameWithPrefix( 760b57cec5SDimitry Andric SmallVectorImpl<char> &OutName, const GlobalValue *GV, 770b57cec5SDimitry Andric const TargetMachine &TM) const { 780b57cec5SDimitry Andric // AArch64 does not use section-relative relocations so any global symbol must 790b57cec5SDimitry Andric // be accessed via at least a linker-private symbol. 800b57cec5SDimitry Andric getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true); 810b57cec5SDimitry Andric } 82