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" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 12 | #include "llvm/BinaryFormat/Dwarf.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 13 | #include "llvm/IR/Mangler.h" |
| 14 | #include "llvm/MC/MCContext.h" |
| 15 | #include "llvm/MC/MCExpr.h" |
| 16 | #include "llvm/MC/MCStreamer.h" |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCValue.h" |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 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); |
Lei Liu | 8e422b8 | 2018-08-01 23:46:49 +0000 | [diff] [blame] | 25 | // AARCH64 ELF ABI does not define static relocation type for TLS offset |
| 26 | // within a module. Do not generate AT_location for TLS variables. |
| 27 | SupportDebugThreadLocalLocation = false; |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 28 | } |
| 29 | |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 30 | AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile() |
| 31 | : TargetLoweringObjectFileMachO() { |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 32 | SupportGOTPCRelWithOffset = false; |
| 33 | } |
| 34 | |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 35 | const MCExpr *AArch64_MachoTargetObjectFile::getTTypeGlobalReference( |
Eric Christopher | 4367c7f | 2016-09-16 07:33:15 +0000 | [diff] [blame] | 36 | const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, |
| 37 | MachineModuleInfo *MMI, MCStreamer &Streamer) const { |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 38 | // On Darwin, we can reference dwarf symbols with foo@GOT-., which |
| 39 | // is an indirect pc-relative reference. The default implementation |
| 40 | // won't reference using the GOT, so we need this target-specific |
| 41 | // version. |
| 42 | if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) { |
Tim Northover | b64fb45 | 2016-11-22 16:17:20 +0000 | [diff] [blame] | 43 | const MCSymbol *Sym = TM.getSymbol(GV); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 44 | const MCExpr *Res = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 45 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 46 | MCSymbol *PCSym = getContext().createTempSymbol(); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 47 | Streamer.EmitLabel(PCSym); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 48 | const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); |
| 49 | return MCBinaryExpr::createSub(Res, PC, getContext()); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return TargetLoweringObjectFileMachO::getTTypeGlobalReference( |
Eric Christopher | 4367c7f | 2016-09-16 07:33:15 +0000 | [diff] [blame] | 53 | GV, Encoding, TM, MMI, Streamer); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | MCSymbol *AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol( |
Eric Christopher | 4367c7f | 2016-09-16 07:33:15 +0000 | [diff] [blame] | 57 | const GlobalValue *GV, const TargetMachine &TM, |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 58 | MachineModuleInfo *MMI) const { |
Tim Northover | b64fb45 | 2016-11-22 16:17:20 +0000 | [diff] [blame] | 59 | return TM.getSymbol(GV); |
Tim Northover | 3b0846e | 2014-05-24 12:50:23 +0000 | [diff] [blame] | 60 | } |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 61 | |
| 62 | const MCExpr *AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel( |
Bruno Cardoso Lopes | 618c67a | 2015-03-06 13:49:05 +0000 | [diff] [blame] | 63 | const MCSymbol *Sym, const MCValue &MV, int64_t Offset, |
| 64 | MachineModuleInfo *MMI, MCStreamer &Streamer) const { |
| 65 | assert((Offset+MV.getConstant() == 0) && |
| 66 | "Arch64 does not support GOT PC rel with extra offset"); |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 67 | // On ARM64 Darwin, we can reference symbols with foo@GOT-., which |
| 68 | // is an indirect pc-relative reference. |
| 69 | const MCExpr *Res = |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 70 | MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_GOT, getContext()); |
Jim Grosbach | 6f48200 | 2015-05-18 18:43:14 +0000 | [diff] [blame] | 71 | MCSymbol *PCSym = getContext().createTempSymbol(); |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 72 | Streamer.EmitLabel(PCSym); |
Jim Grosbach | 13760bd | 2015-05-30 01:25:56 +0000 | [diff] [blame] | 73 | const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext()); |
| 74 | return MCBinaryExpr::createSub(Res, PC, getContext()); |
Bruno Cardoso Lopes | 52b1391 | 2015-03-06 13:48:45 +0000 | [diff] [blame] | 75 | } |
Tim Northover | 203c6f0 | 2017-05-15 21:51:38 +0000 | [diff] [blame] | 76 | |
| 77 | void AArch64_MachoTargetObjectFile::getNameWithPrefix( |
| 78 | SmallVectorImpl<char> &OutName, const GlobalValue *GV, |
| 79 | const TargetMachine &TM) const { |
| 80 | // AArch64 does not use section-relative relocations so any global symbol must |
| 81 | // be accessed via at least a linker-private symbol. |
| 82 | getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true); |
| 83 | } |