LLVM 19.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
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"
17using namespace llvm;
18using namespace dwarf;
19
20void 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.
26}
27
29 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
30 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
31 int64_t FinalOffset = Offset + MV.getConstant();
32 const MCExpr *Res =
34 const MCExpr *Off = MCConstantExpr::create(FinalOffset, getContext());
35 return MCBinaryExpr::createAdd(Res, Off, getContext());
36}
37
40}
41
43 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
44 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
45 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
46 // is an indirect pc-relative reference. The default implementation
47 // won't reference using the GOT, so we need this target-specific
48 // version.
49 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
50 const MCSymbol *Sym = TM.getSymbol(GV);
51 const MCExpr *Res =
54 Streamer.emitLabel(PCSym);
55 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
56 return MCBinaryExpr::createSub(Res, PC, getContext());
57 }
58
60 GV, Encoding, TM, MMI, Streamer);
61}
62
64 const GlobalValue *GV, const TargetMachine &TM,
65 MachineModuleInfo *MMI) const {
66 return TM.getSymbol(GV);
67}
68
70 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
71 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
72 assert((Offset+MV.getConstant() == 0) &&
73 "Arch64 does not support GOT PC rel with extra offset");
74 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
75 // is an indirect pc-relative reference.
76 const MCExpr *Res =
79 Streamer.emitLabel(PCSym);
80 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
81 return MCBinaryExpr::createSub(Res, PC, getContext());
82}
83
85 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
86 const TargetMachine &TM) const {
87 // AArch64 does not use section-relative relocations so any global symbol must
88 // be accessed via at least a linker-private symbol.
89 getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
90}
This file contains constants used for implementing Dwarf debug support.
Symbol * Sym
Definition: ELF_riscv.cpp:479
const char LLVMTargetMachineRef TM
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const MCExpr * getIndirectSymViaGOTPCRel(const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV, int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const override
Get the target specific PC relative GOT entry relocation.
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.
void getNameWithPrefix(SmallVectorImpl< char > &OutName, const GlobalValue *GV, const TargetMachine &TM) const override
MCSymbol * getCFIPersonalitySymbol(const GlobalValue *GV, const TargetMachine &TM, MachineModuleInfo *MMI) const override
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.
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:536
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:621
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:194
Context object for machine code objects.
Definition: MCContext.h:81
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:322
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
MCContext & getContext() const
Streaming machine code generation interface.
Definition: MCStreamer.h:212
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:424
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:397
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
This class contains meta information specific to a module.
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:120
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
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.
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:76
MCSymbol * getSymbol(const GlobalValue *GV) const
@ DW_EH_PE_pcrel
Definition: Dwarf.h:534
@ DW_EH_PE_indirect
Definition: Dwarf.h:539
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:456