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