blob: f5c7fc824ab47864ec11bbbaebfede5745be5b8f [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//==- llvm/CodeGen/TargetLoweringObjectFileImpl.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_TARGETLOWERINGOBJECTFILEIMPL_H
16#define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17
18#include "llvm/IR/Module.h"
19#include "llvm/MC/MCExpr.h"
20#include "llvm/Target/TargetLoweringObjectFile.h"
21
22namespace llvm {
23
24class GlobalValue;
25class MachineModuleInfo;
26class Mangler;
27class MCContext;
28class MCSection;
29class MCSymbol;
30class TargetMachine;
31
32class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
33 bool UseInitArray = false;
34 mutable unsigned NextUniqueID = 1; // ID 0 is reserved for execute-only sections
35
36protected:
37 MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
38 MCSymbolRefExpr::VK_None;
Andrew Scullcdfcccc2018-10-05 20:58:37 +010039 const TargetMachine *TM;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010040
41public:
42 TargetLoweringObjectFileELF() = default;
43 ~TargetLoweringObjectFileELF() override = default;
44
Andrew Scullcdfcccc2018-10-05 20:58:37 +010045 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010046
Andrew Scullcdfcccc2018-10-05 20:58:37 +010047 /// Emit Obj-C garbage collection and linker options.
48 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
49
50 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &DL,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010051 const MCSymbol *Sym) const override;
52
53 /// Given a constant with the SectionKind, return a section that it should be
54 /// placed in.
55 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
56 const Constant *C,
57 unsigned &Align) const override;
58
59 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
60 const TargetMachine &TM) const override;
61
62 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
63 const TargetMachine &TM) const override;
64
65 MCSection *getSectionForJumpTable(const Function &F,
66 const TargetMachine &TM) const override;
67
68 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
69 const Function &F) const override;
70
71 /// Return an MCExpr to use for a reference to the specified type info global
72 /// variable from exception handling information.
73 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
74 unsigned Encoding,
75 const TargetMachine &TM,
76 MachineModuleInfo *MMI,
77 MCStreamer &Streamer) const override;
78
79 // The symbol that gets passed to .cfi_personality.
80 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
81 const TargetMachine &TM,
82 MachineModuleInfo *MMI) const override;
83
84 void InitializeELF(bool UseInitArray_);
85 MCSection *getStaticCtorSection(unsigned Priority,
86 const MCSymbol *KeySym) const override;
87 MCSection *getStaticDtorSection(unsigned Priority,
88 const MCSymbol *KeySym) const override;
89
90 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
91 const GlobalValue *RHS,
92 const TargetMachine &TM) const override;
93};
94
95class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
96public:
97 TargetLoweringObjectFileMachO();
98 ~TargetLoweringObjectFileMachO() override = default;
99
100 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
101
102 /// Emit the module flags that specify the garbage collection information.
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100103 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100104
105 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
106 const TargetMachine &TM) const override;
107
108 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
109 const TargetMachine &TM) const override;
110
111 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
112 const Constant *C,
113 unsigned &Align) const override;
114
115 /// The mach-o version of this method defaults to returning a stub reference.
116 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
117 unsigned Encoding,
118 const TargetMachine &TM,
119 MachineModuleInfo *MMI,
120 MCStreamer &Streamer) const override;
121
122 // The symbol that gets passed to .cfi_personality.
123 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
124 const TargetMachine &TM,
125 MachineModuleInfo *MMI) const override;
126
127 /// Get MachO PC relative GOT entry relocation
128 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
129 const MCValue &MV, int64_t Offset,
130 MachineModuleInfo *MMI,
131 MCStreamer &Streamer) const override;
132
133 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
134 const TargetMachine &TM) const override;
135};
136
137class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
138 mutable unsigned NextUniqueID = 0;
139
140public:
141 ~TargetLoweringObjectFileCOFF() override = default;
142
143 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
144 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
145 const TargetMachine &TM) const override;
146
147 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
148 const TargetMachine &TM) const override;
149
150 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
151 const TargetMachine &TM) const override;
152
153 MCSection *getSectionForJumpTable(const Function &F,
154 const TargetMachine &TM) const override;
155
156 /// Emit Obj-C garbage collection and linker options.
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100157 void emitModuleMetadata(MCStreamer &Streamer, Module &M) const override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100158
159 MCSection *getStaticCtorSection(unsigned Priority,
160 const MCSymbol *KeySym) const override;
161 MCSection *getStaticDtorSection(unsigned Priority,
162 const MCSymbol *KeySym) const override;
163
164 void emitLinkerFlagsForGlobal(raw_ostream &OS,
165 const GlobalValue *GV) const override;
166
167 void emitLinkerFlagsForUsed(raw_ostream &OS,
168 const GlobalValue *GV) const override;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100169
170 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
171 const GlobalValue *RHS,
172 const TargetMachine &TM) const override;
173
174 /// Given a mergeable constant with the specified size and relocation
175 /// information, return a section that it should be placed in.
176 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
177 const Constant *C,
178 unsigned &Align) const override;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100179};
180
181class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile {
182 mutable unsigned NextUniqueID = 0;
183
184public:
185 TargetLoweringObjectFileWasm() = default;
186 ~TargetLoweringObjectFileWasm() override = default;
187
188 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
189 const TargetMachine &TM) const override;
190
191 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
192 const TargetMachine &TM) const override;
193
194 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
195 const Function &F) const override;
196
197 void InitializeWasm();
198 MCSection *getStaticCtorSection(unsigned Priority,
199 const MCSymbol *KeySym) const override;
200 MCSection *getStaticDtorSection(unsigned Priority,
201 const MCSymbol *KeySym) const override;
202
203 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
204 const GlobalValue *RHS,
205 const TargetMachine &TM) const override;
206};
207
208} // end namespace llvm
209
210#endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H