LLVM 20.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
15#include "llvm/IR/Mangler.h"
16#include "llvm/IR/Module.h"
17#include "llvm/MC/MCContext.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCStreamer.h"
20#include "llvm/MC/MCValue.h"
21using namespace llvm;
22using namespace dwarf;
23
24void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
25 const TargetMachine &TM) {
27 // AARCH64 ELF ABI does not define static relocation type for TLS offset
28 // within a module. Do not generate AT_location for TLS variables.
30}
31
33 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
34 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
35 int64_t FinalOffset = Offset + MV.getConstant();
36 const MCExpr *Res =
38 const MCExpr *Off = MCConstantExpr::create(FinalOffset, getContext());
39 return MCBinaryExpr::createAdd(Res, Off, getContext());
40}
41
44}
45
47 const GlobalValue *GV, unsigned Encoding, const TargetMachine &TM,
48 MachineModuleInfo *MMI, MCStreamer &Streamer) const {
49 // On Darwin, we can reference dwarf symbols with foo@GOT-., which
50 // is an indirect pc-relative reference. The default implementation
51 // won't reference using the GOT, so we need this target-specific
52 // version.
53 if (Encoding & (DW_EH_PE_indirect | DW_EH_PE_pcrel)) {
54 const MCSymbol *Sym = TM.getSymbol(GV);
55 const MCExpr *Res =
58 Streamer.emitLabel(PCSym);
59 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
60 return MCBinaryExpr::createSub(Res, PC, getContext());
61 }
62
64 GV, Encoding, TM, MMI, Streamer);
65}
66
68 const GlobalValue *GV, const TargetMachine &TM,
69 MachineModuleInfo *MMI) const {
70 return TM.getSymbol(GV);
71}
72
74 const GlobalValue *GV, const MCSymbol *Sym, const MCValue &MV,
75 int64_t Offset, MachineModuleInfo *MMI, MCStreamer &Streamer) const {
76 assert((Offset+MV.getConstant() == 0) &&
77 "Arch64 does not support GOT PC rel with extra offset");
78 // On ARM64 Darwin, we can reference symbols with foo@GOT-., which
79 // is an indirect pc-relative reference.
80 const MCExpr *Res =
83 Streamer.emitLabel(PCSym);
84 const MCExpr *PC = MCSymbolRefExpr::create(PCSym, getContext());
85 return MCBinaryExpr::createSub(Res, PC, getContext());
86}
87
89 SmallVectorImpl<char> &OutName, const GlobalValue *GV,
90 const TargetMachine &TM) const {
91 // AArch64 does not use section-relative relocations so any global symbol must
92 // be accessed via at least a linker-private symbol.
93 getMangler().getNameWithPrefix(OutName, GV, /* CannotUsePrivateLabel */ true);
94}
95
96template <typename MachineModuleInfoTarget>
98 MCContext &Ctx, const TargetMachine &TM, MachineModuleInfo *MMI,
99 MachineModuleInfoTarget &TargetMMI, const MCSymbol *RawSym,
100 AArch64PACKey::ID Key, uint16_t Discriminator) {
101 const DataLayout &DL = MMI->getModule()->getDataLayout();
102
103 MCSymbol *StubSym = Ctx.getOrCreateSymbol(
104 DL.getLinkerPrivateGlobalPrefix() + RawSym->getName() +
105 Twine("$auth_ptr$") + AArch64PACKeyIDToString(Key) + Twine('$') +
106 Twine(Discriminator));
107
108 const MCExpr *&StubAuthPtrRef = TargetMMI.getAuthPtrStubEntry(StubSym);
109
110 if (StubAuthPtrRef)
111 return StubSym;
112
113 const MCExpr *Sym = MCSymbolRefExpr::create(RawSym, Ctx);
114
115 StubAuthPtrRef =
116 AArch64AuthMCExpr::create(Sym, Discriminator, Key,
117 /*HasAddressDiversity=*/false, Ctx);
118 return StubSym;
119}
120
122 const TargetMachine &TM, MachineModuleInfo *MMI, const MCSymbol *RawSym,
123 AArch64PACKey::ID Key, uint16_t Discriminator) const {
124 auto &ELFMMI = MMI->getObjFileInfo<MachineModuleInfoELF>();
125 return getAuthPtrSlotSymbolHelper(getContext(), TM, MMI, ELFMMI, RawSym, Key,
126 Discriminator);
127}
128
130 const TargetMachine &TM, MachineModuleInfo *MMI, const MCSymbol *RawSym,
131 AArch64PACKey::ID Key, uint16_t Discriminator) const {
132 auto &MachOMMI = MMI->getObjFileInfo<MachineModuleInfoMachO>();
133 return getAuthPtrSlotSymbolHelper(getContext(), TM, MMI, MachOMMI, RawSym,
134 Key, Discriminator);
135}
static MCSymbol * getAuthPtrSlotSymbolHelper(MCContext &Ctx, const TargetMachine &TM, MachineModuleInfo *MMI, MachineModuleInfoTarget &TargetMMI, const MCSymbol *RawSym, AArch64PACKey::ID Key, uint16_t Discriminator)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains constants used for implementing Dwarf debug support.
Symbol * Sym
Definition: ELF_riscv.cpp:479
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some functions that are useful when dealing with strings.
static const AArch64AuthMCExpr * create(const MCExpr *Expr, uint16_t Discriminator, AArch64PACKey::ID Key, bool HasAddressDiversity, MCContext &Ctx)
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.
MCSymbol * getAuthPtrSlotSymbol(const TargetMachine &TM, MachineModuleInfo *MMI, const MCSymbol *RawSym, AArch64PACKey::ID Key, uint16_t Discriminator) const
MCSymbol * getAuthPtrSlotSymbol(const TargetMachine &TM, MachineModuleInfo *MMI, const MCSymbol *RawSym, AArch64PACKey::ID Key, uint16_t Discriminator) const
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.
A parsed version of the target data layout string in and methods for querying it.
Definition: DataLayout.h:63
static const MCBinaryExpr * createAdd(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:532
static const MCBinaryExpr * createSub(const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx)
Definition: MCExpr.h:617
static const MCConstantExpr * create(int64_t Value, MCContext &Ctx, bool PrintInHex=false, unsigned SizeInBytes=0)
Definition: MCExpr.cpp:193
Context object for machine code objects.
Definition: MCContext.h:83
MCSymbol * createTempSymbol()
Create a temporary symbol with a unique name.
Definition: MCContext.cpp:346
MCSymbol * getOrCreateSymbol(const Twine &Name)
Lookup the symbol inside with the specified Name.
Definition: MCContext.cpp:213
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
MCContext & getContext() const
Streaming machine code generation interface.
Definition: MCStreamer.h:213
virtual void emitLabel(MCSymbol *Symbol, SMLoc Loc=SMLoc())
Emit a label for Symbol into the current section.
Definition: MCStreamer.cpp:414
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:393
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
StringRef getName() const
getName - Get the symbol name.
Definition: MCSymbol.h:205
This represents an "assembler immediate".
Definition: MCValue.h:36
int64_t getConstant() const
Definition: MCValue.h:43
MachineModuleInfoELF - This is a MachineModuleInfoImpl implementation for ELF targets.
MachineModuleInfoMachO - This is a MachineModuleInfoImpl implementation for MachO targets.
This class contains meta information specific to a module.
const Module * getModule() const
Ty & getObjFileInfo()
Keep track of various per-module pieces of information for backends that would like to do so.
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
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Definition: Module.h:291
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:77
MCSymbol * getSymbol(const GlobalValue *GV) const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
@ DW_EH_PE_pcrel
Definition: Dwarf.h:851
@ DW_EH_PE_indirect
Definition: Dwarf.h:856
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
static StringRef AArch64PACKeyIDToString(AArch64PACKey::ID KeyID)
Return 2-letter identifier string for numeric key ID.