LLVM  14.0.0git
AArch64TargetObjectFile.cpp
Go to the documentation of this file.
1 //===-- AArch64TargetObjectFile.cpp - AArch64 Object Info -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #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"
16 #include "llvm/MC/MCValue.h"
17 using namespace llvm;
18 using namespace dwarf;
19 
20 void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
21  const TargetMachine &TM) {
23  // AARCH64 ELF ABI does not define static relocation type for TLS offset
24  // within a module. Do not generate AT_location for TLS variables.
25  SupportDebugThreadLocalLocation = false;
26 }
27 
31 }
32 
34  const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
35  MachineModuleInfo *MMI, 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);
42  const MCExpr *Res =
45  Streamer.emitLabel(PCSym);
46  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
47  return MCBinaryExpr::createSub(Res, PC, getContext());
48  }
49 
51  GV, Encoding, TM, MMI, Streamer);
52 }
53 
55  const GlobalValue *GV, const TargetMachine &TM,
56  MachineModuleInfo *MMI) const {
57  return TM.getSymbol(GV);
58 }
59 
61  const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
62  int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
63  assert((Offset+MV.getConstant() == 0) &&
64  "Arch64 does not support GOT PC rel with extra offset");
65  // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
66  // is an indirect pc-relative reference.
67  const MCExpr *Res =
70  Streamer.emitLabel(PCSym);
71  const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
72  return MCBinaryExpr::createSub(Res, PC, getContext());
73 }
74 
76  SmallVectorImpl<char> &OutName, const GlobalValue *GV,
77  const TargetMachine &TM) const {
78  // AArch64 does not use section-relative relocations so any global symbol must
79  // be accessed via at least a linker-private symbol.
80  getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
81 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCSymbolRefExpr::VK_GOT
@ VK_GOT
Definition: MCExpr.h:198
llvm::MCContext
Context object for machine code objects.
Definition: MCContext.h:72
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:81
llvm::TargetLoweringObjectFileMachO::getTTypeGlobalReference
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
Definition: TargetLoweringObjectFileImpl.cpp:1357
llvm::MCObjectFileInfo::getContext
MCContext & getContext() const
Definition: MCObjectFileInfo.h:235
llvm::TargetLoweringObjectFileMachO
Definition: TargetLoweringObjectFileImpl.h:114
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
AArch64TargetMachine.h
llvm::dwarf::DW_EH_PE_indirect
@ DW_EH_PE_indirect
Definition: Dwarf.h:448
MCContext.h
llvm::MCStreamer::emitLabel
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:415
llvm::Mangler::getNameWithPrefix
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:119
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
AArch64TargetObjectFile.h
llvm::MCValue::getConstant
int64_t getConstant() const
Definition: MCValue.h:44
llvm::TargetMachine::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: TargetMachine.cpp:209
llvm::TargetLoweringObjectFile::TM
const TargetMachine * TM
Definition: TargetLoweringObjectFile.h:67
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::dwarf::DW_EH_PE_pcrel
@ DW_EH_PE_pcrel
Definition: Dwarf.h:443
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::TargetMachine
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:79
llvm::MCBinaryExpr::createSub
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:609
Mangler.h
llvm::AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile
AArch64_MachoTargetObjectFile()
Definition: AArch64TargetObjectFile.cpp:28
llvm::TargetLoweringObjectFile::getMangler
Mangler & getMangler() const
Definition: TargetLoweringObjectFile.h:76
Dwarf.h
llvm::AArch64_MachoTargetObjectFile::getIndirectSymViaGOTPCRel
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get MachO PC relative GOT entry relocation.
Definition: AArch64TargetObjectFile.cpp:60
llvm::AArch64_MachoTargetObjectFile::getTTypeGlobalReference
const MCExpr * getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
The mach-o version of this method defaults to returning a stub reference.
Definition: AArch64TargetObjectFile.cpp:33
llvm::MCContext::createTempSymbol
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:303
llvm::TargetLoweringObjectFileELF::Initialize
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Definition: TargetLoweringObjectFileImpl.cpp:116
llvm::MCSymbolRefExpr::create
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:385
MCValue.h
MCStreamer.h
llvm::TargetLoweringObjectFile::SupportGOTPCRelWithOffset
bool SupportGOTPCRelWithOffset
Definition: TargetLoweringObjectFile.h:50
llvm::SmallVectorImpl< char >
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
MCExpr.h
llvm::AArch64_MachoTargetObjectFile::getNameWithPrefix
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
Definition: AArch64TargetObjectFile.cpp:75
llvm::MCExpr
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
llvm::AArch64_MachoTargetObjectFile::getCFIPersonalitySymbol
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
Definition: AArch64TargetObjectFile.cpp:54