13b0846e8STim Northover //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===// 23b0846e8STim Northover // 33b0846e8STim Northover // The LLVM Compiler Infrastructure 43b0846e8STim Northover // 53b0846e8STim Northover // This file is distributed under the University of Illinois Open Source 63b0846e8STim Northover // License. See LICENSE.TXT for details. 73b0846e8STim Northover // 83b0846e8STim Northover //===----------------------------------------------------------------------===// 93b0846e8STim Northover 103b0846e8STim Northover #include "AArch64TargetObjectFile.h" 113b0846e8STim Northover #include "AArch64TargetMachine.h" 123b0846e8STim Northover #include "llvm/IR/Mangler.h" 133b0846e8STim Northover #include "llvm/MC/MCContext.h" 143b0846e8STim Northover #include "llvm/MC/MCExpr.h" 153b0846e8STim Northover #include "llvm/MC/MCStreamer.h" 16618c67a0SBruno Cardoso Lopes #include "llvm/MC/MCValue.h" 173b0846e8STim Northover #include "llvm/Support/Dwarf.h" 183b0846e8STim Northover using namespace llvm; 193b0846e8STim Northover using namespace dwarf; 203b0846e8STim Northover 213b0846e8STim Northover void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx, 223b0846e8STim Northover const TargetMachine &TM) { 233b0846e8STim Northover TargetLoweringObjectFileELF::Initialize(Ctx, TM); 243b0846e8STim Northover InitializeELF(TM.Options.UseInitArray); 253b0846e8STim Northover } 263b0846e8STim Northover 2752b1391dSBruno Cardoso Lopes AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() 2852b1391dSBruno Cardoso Lopes : TargetLoweringObjectFileMachO() { 2952b1391dSBruno Cardoso Lopes SupportGOTPCRelWithOffset = false; 3052b1391dSBruno Cardoso Lopes } 3152b1391dSBruno Cardoso Lopes 323b0846e8STim Northover const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference( 333b0846e8STim Northover const GlobalValue *GV, unsigned Encoding, Mangler &Mang, 343b0846e8STim Northover const TargetMachine &TM, MachineModuleInfo *MMI, 353b0846e8STim Northover MCStreamer &Streamer) const { 363b0846e8STim Northover // On Darwin, we can reference dwarf symbols with foo@GOT-., which 373b0846e8STim Northover // is an indirect pc-relative reference. The default implementation 383b0846e8STim Northover // won't reference using the GOT, so we need this target-specific 393b0846e8STim Northover // version. 403b0846e8STim Northover if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { 413b0846e8STim Northover const MCSymbol *Sym = TM.getSymbol(GV, Mang); 423b0846e8STim Northover const MCExpr *Res = 433b0846e8STim Northover MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); 44*6f482000SJim Grosbach MCSymbol *PCSym = getContext().createTempSymbol(); 453b0846e8STim Northover Streamer.EmitLabel(PCSym); 463b0846e8STim Northover const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext()); 473b0846e8STim Northover return MCBinaryExpr::CreateSub(Res, PC, getContext()); 483b0846e8STim Northover } 493b0846e8STim Northover 503b0846e8STim Northover return TargetLoweringObjectFileMachO::getTTypeGlobalReference( 513b0846e8STim Northover GV, Encoding, Mang, TM, MMI, Streamer); 523b0846e8STim Northover } 533b0846e8STim Northover 543b0846e8STim Northover MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol( 553b0846e8STim Northover const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, 563b0846e8STim Northover MachineModuleInfo *MMI) const { 573b0846e8STim Northover return TM.getSymbol(GV, Mang); 583b0846e8STim Northover } 5952b1391dSBruno Cardoso Lopes 6052b1391dSBruno Cardoso Lopes const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel( 61618c67a0SBruno Cardoso Lopes const MCSymbol *Sym, const MCValue &MV, int64_t Offset, 62618c67a0SBruno Cardoso Lopes MachineModuleInfo *MMI, MCStreamer &Streamer) const { 63618c67a0SBruno Cardoso Lopes assert((Offset+MV.getConstant() == 0) && 64618c67a0SBruno Cardoso Lopes "Arch64 does not support GOT PC rel with extra offset"); 6552b1391dSBruno Cardoso Lopes // On ARM64 Darwin, we can reference symbols with foo@GOT-., which 6652b1391dSBruno Cardoso Lopes // is an indirect pc-relative reference. 6752b1391dSBruno Cardoso Lopes const MCExpr *Res = 6852b1391dSBruno Cardoso Lopes MCSymbolRefExpr::Create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); 69*6f482000SJim Grosbach MCSymbol *PCSym = getContext().createTempSymbol(); 7052b1391dSBruno Cardoso Lopes Streamer.EmitLabel(PCSym); 7152b1391dSBruno Cardoso Lopes const MCExpr *PC = MCSymbolRefExpr::Create(PCSym, getContext()); 7252b1391dSBruno Cardoso Lopes return MCBinaryExpr::CreateSub(Res, PC, getContext()); 7352b1391dSBruno Cardoso Lopes } 74