Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 1 | //===-- 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" |
| 12 | #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 Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCValue.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Dwarf.h" |
| 18 | using namespace llvm; |
| 19 | using namespace dwarf; |
| 20 | |
| 21 | void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx, |
| 22 | const TargetMachine &TM) { |
| 23 | TargetLoweringObjectFileELF::Initialize(Ctx, TM); |
| 24 | InitializeELF(TM.Options.UseInitArray); |
| 25 | } |
| 26 | |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 27 | AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() |
| 28 | : TargetLoweringObjectFileMachO() { |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 29 | SupportGOTPCRelWithOffset = false; |
| 30 | } |
| 31 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 32 | const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference( |
| 33 | const GlobalValue *GV, unsigned Encoding, Mangler &Mang, |
| 34 | const TargetMachine &TM, MachineModuleInfo *MMI, |
| 35 | MCStreamer &Streamer) const { |
| 36 | // On Darwin, we can reference dwarf symbols with foo@GOT-., which |
| 37 | // is an indirect pc-relative reference. The default implementation |
| 38 | // won't reference using the GOT, so we need this target-specific |
| 39 | // version. |
| 40 | if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { |
| 41 | const MCSymbol *Sym = TM.getSymbol(GV, Mang); |
| 42 | const MCExpr *Res = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame^] | 43 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 44 | MCSymbol *PCSym = getContext().createTempSymbol(); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 45 | Streamer.EmitLabel(PCSym); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame^] | 46 | const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); |
| 47 | return MCBinaryExpr::createSub(Res, PC, getContext()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | return TargetLoweringObjectFileMachO::getTTypeGlobalReference( |
| 51 | GV, Encoding, Mang, TM, MMI, Streamer); |
| 52 | } |
| 53 | |
| 54 | MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol( |
| 55 | const GlobalValue *GV, Mangler &Mang, const TargetMachine &TM, |
| 56 | MachineModuleInfo *MMI) const { |
| 57 | return TM.getSymbol(GV, Mang); |
| 58 | } |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 59 | |
| 60 | const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel( |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 61 | const MCSymbol *Sym, const MCValue &MV, int64_t Offset, |
| 62 | MachineModuleInfo *MMI, MCStreamer &Streamer) const { |
| 63 | assert((Offset+MV.getConstant() == 0) && |
| 64 | "Arch64 does not support GOT PC rel with extra offset"); |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 65 | // On ARM64 Darwin, we can reference symbols with foo@GOT-., which |
| 66 | // is an indirect pc-relative reference. |
| 67 | const MCExpr *Res = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame^] | 68 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 69 | MCSymbol *PCSym = getContext().createTempSymbol(); |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 70 | Streamer.EmitLabel(PCSym); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame^] | 71 | const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); |
| 72 | return MCBinaryExpr::createSub(Res, PC, getContext()); |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 73 | } |