blob: 40b77c3d94a01a65a4d65787de0b27675f1a20a9 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
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// This file implements classes used to handle lowerings specific to common
11// object file formats.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
16#define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/IR/Module.h"
21#include "llvm/MC/MCObjectFileInfo.h"
22#include "llvm/MC/SectionKind.h"
23#include <cstdint>
24
25namespace llvm {
26
27class GlobalValue;
28class MachineModuleInfo;
29class Mangler;
30class MCContext;
31class MCExpr;
32class MCSection;
33class MCSymbol;
34class MCSymbolRefExpr;
35class MCStreamer;
36class MCValue;
37class TargetMachine;
38
39class TargetLoweringObjectFile : public MCObjectFileInfo {
40 MCContext *Ctx = nullptr;
41
42 /// Name-mangler for global names.
43 Mangler *Mang = nullptr;
44
45protected:
46 bool SupportIndirectSymViaGOTPCRel = false;
47 bool SupportGOTPCRelWithOffset = true;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010048 bool SupportDebugThreadLocalLocation = true;
49
50 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
51 /// for EH.
52 unsigned PersonalityEncoding = 0;
53 unsigned LSDAEncoding = 0;
54 unsigned TTypeEncoding = 0;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010055
56 /// This section contains the static constructor pointer list.
57 MCSection *StaticCtorSection = nullptr;
58
59 /// This section contains the static destructor pointer list.
60 MCSection *StaticDtorSection = nullptr;
61
62public:
63 TargetLoweringObjectFile() = default;
64 TargetLoweringObjectFile(const TargetLoweringObjectFile &) = delete;
65 TargetLoweringObjectFile &
66 operator=(const TargetLoweringObjectFile &) = delete;
67 virtual ~TargetLoweringObjectFile();
68
69 MCContext &getContext() const { return *Ctx; }
70 Mangler &getMangler() const { return *Mang; }
71
72 /// This method must be called before any actual lowering is done. This
73 /// specifies the current context for codegen, and gives the lowering
74 /// implementations a chance to set up their default sections.
75 virtual void Initialize(MCContext &ctx, const TargetMachine &TM);
76
77 virtual void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
78 const MCSymbol *Sym) const;
79
80 /// Emit the module-level metadata that the platform cares about.
Andrew Scullcdfcccc2018-10-05 20:58:37 +010081 virtual void emitModuleMetadata(MCStreamer &Streamer, Module &M) const {}
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010082
83 /// Given a constant with the SectionKind, return a section that it should be
84 /// placed in.
85 virtual MCSection *getSectionForConstant(const DataLayout &DL,
86 SectionKind Kind,
87 const Constant *C,
88 unsigned &Align) const;
89
90 /// Classify the specified global variable into a set of target independent
91 /// categories embodied in SectionKind.
92 static SectionKind getKindForGlobal(const GlobalObject *GO,
93 const TargetMachine &TM);
94
95 /// This method computes the appropriate section to emit the specified global
96 /// variable or function definition. This should not be passed external (or
97 /// available externally) globals.
98 MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
99 const TargetMachine &TM) const;
100
101 /// This method computes the appropriate section to emit the specified global
102 /// variable or function definition. This should not be passed external (or
103 /// available externally) globals.
104 MCSection *SectionForGlobal(const GlobalObject *GO,
105 const TargetMachine &TM) const {
106 return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM);
107 }
108
109 virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
110 const GlobalValue *GV,
111 const TargetMachine &TM) const;
112
113 virtual MCSection *getSectionForJumpTable(const Function &F,
114 const TargetMachine &TM) const;
115
116 virtual bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
117 const Function &F) const;
118
119 /// Targets should implement this method to assign a section to globals with
120 /// an explicit section specfied. The implementation of this method can
121 /// assume that GO->hasSection() is true.
122 virtual MCSection *
123 getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
124 const TargetMachine &TM) const = 0;
125
126 /// Return an MCExpr to use for a reference to the specified global variable
127 /// from exception handling information.
128 virtual const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
129 unsigned Encoding,
130 const TargetMachine &TM,
131 MachineModuleInfo *MMI,
132 MCStreamer &Streamer) const;
133
134 /// Return the MCSymbol for a private symbol with global value name as its
135 /// base, with the specified suffix.
136 MCSymbol *getSymbolWithGlobalValueBase(const GlobalValue *GV,
137 StringRef Suffix,
138 const TargetMachine &TM) const;
139
140 // The symbol that gets passed to .cfi_personality.
141 virtual MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
142 const TargetMachine &TM,
143 MachineModuleInfo *MMI) const;
144
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100145 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
146 unsigned getLSDAEncoding() const { return LSDAEncoding; }
147 unsigned getTTypeEncoding() const { return TTypeEncoding; }
148
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100149 const MCExpr *getTTypeReference(const MCSymbolRefExpr *Sym, unsigned Encoding,
150 MCStreamer &Streamer) const;
151
152 virtual MCSection *getStaticCtorSection(unsigned Priority,
153 const MCSymbol *KeySym) const {
154 return StaticCtorSection;
155 }
156
157 virtual MCSection *getStaticDtorSection(unsigned Priority,
158 const MCSymbol *KeySym) const {
159 return StaticDtorSection;
160 }
161
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100162 /// Create a symbol reference to describe the given TLS variable when
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100163 /// emitting the address in debug info.
164 virtual const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const;
165
166 virtual const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
167 const GlobalValue *RHS,
168 const TargetMachine &TM) const {
169 return nullptr;
170 }
171
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100172 /// Target supports replacing a data "PC"-relative access to a symbol
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100173 /// through another symbol, by accessing the later via a GOT entry instead?
174 bool supportIndirectSymViaGOTPCRel() const {
175 return SupportIndirectSymViaGOTPCRel;
176 }
177
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100178 /// Target GOT "PC"-relative relocation supports encoding an additional
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100179 /// binary expression with an offset?
180 bool supportGOTPCRelWithOffset() const {
181 return SupportGOTPCRelWithOffset;
182 }
183
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100184 /// Target supports TLS offset relocation in debug section?
185 bool supportDebugThreadLocalLocation() const {
186 return SupportDebugThreadLocalLocation;
187 }
188
189 /// Get the target specific PC relative GOT entry relocation
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100190 virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
191 const MCValue &MV,
192 int64_t Offset,
193 MachineModuleInfo *MMI,
194 MCStreamer &Streamer) const {
195 return nullptr;
196 }
197
198 virtual void emitLinkerFlagsForGlobal(raw_ostream &OS,
199 const GlobalValue *GV) const {}
200
201 virtual void emitLinkerFlagsForUsed(raw_ostream &OS,
202 const GlobalValue *GV) const {}
203
204protected:
205 virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
206 SectionKind Kind,
207 const TargetMachine &TM) const = 0;
208};
209
210} // end namespace llvm
211
212#endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILE_H