1 //==- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info --*- C++ -*-==//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements classes used to handle lowerings specific to common
10 // object file formats.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
15 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17 #include "llvm/BinaryFormat/XCOFF.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/MC/MCExpr.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
25 class MachineModuleInfo
;
32 class TargetLoweringObjectFileELF
: public TargetLoweringObjectFile
{
33 bool UseInitArray
= false;
34 mutable unsigned NextUniqueID
= 1; // ID 0 is reserved for execute-only sections
37 MCSymbolRefExpr::VariantKind PLTRelativeVariantKind
=
38 MCSymbolRefExpr::VK_None
;
39 const TargetMachine
*TM
= nullptr;
42 TargetLoweringObjectFileELF() = default;
43 ~TargetLoweringObjectFileELF() override
= default;
45 void Initialize(MCContext
&Ctx
, const TargetMachine
&TM
) override
;
47 /// Emit Obj-C garbage collection and linker options.
48 void emitModuleMetadata(MCStreamer
&Streamer
, Module
&M
) const override
;
50 void emitPersonalityValue(MCStreamer
&Streamer
, const DataLayout
&DL
,
51 const MCSymbol
*Sym
) const override
;
53 /// Given a constant with the SectionKind, return a section that it should be
55 MCSection
*getSectionForConstant(const DataLayout
&DL
, SectionKind Kind
,
57 unsigned &Align
) const override
;
59 MCSection
*getExplicitSectionGlobal(const GlobalObject
*GO
, SectionKind Kind
,
60 const TargetMachine
&TM
) const override
;
62 MCSection
*SelectSectionForGlobal(const GlobalObject
*GO
, SectionKind Kind
,
63 const TargetMachine
&TM
) const override
;
65 MCSection
*getSectionForJumpTable(const Function
&F
,
66 const TargetMachine
&TM
) const override
;
68 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference
,
69 const Function
&F
) const override
;
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
,
75 const TargetMachine
&TM
,
76 MachineModuleInfo
*MMI
,
77 MCStreamer
&Streamer
) const override
;
79 // The symbol that gets passed to .cfi_personality.
80 MCSymbol
*getCFIPersonalitySymbol(const GlobalValue
*GV
,
81 const TargetMachine
&TM
,
82 MachineModuleInfo
*MMI
) const override
;
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
;
90 const MCExpr
*lowerRelativeReference(const GlobalValue
*LHS
,
91 const GlobalValue
*RHS
,
92 const TargetMachine
&TM
) const override
;
94 MCSection
*getSectionForCommandLines() const override
;
97 class TargetLoweringObjectFileMachO
: public TargetLoweringObjectFile
{
99 TargetLoweringObjectFileMachO();
100 ~TargetLoweringObjectFileMachO() override
= default;
102 void Initialize(MCContext
&Ctx
, const TargetMachine
&TM
) override
;
104 /// Emit the module flags that specify the garbage collection information.
105 void emitModuleMetadata(MCStreamer
&Streamer
, Module
&M
) const override
;
107 MCSection
*SelectSectionForGlobal(const GlobalObject
*GO
, SectionKind Kind
,
108 const TargetMachine
&TM
) const override
;
110 MCSection
*getExplicitSectionGlobal(const GlobalObject
*GO
, SectionKind Kind
,
111 const TargetMachine
&TM
) const override
;
113 MCSection
*getSectionForConstant(const DataLayout
&DL
, SectionKind Kind
,
115 unsigned &Align
) const override
;
117 /// The mach-o version of this method defaults to returning a stub reference.
118 const MCExpr
*getTTypeGlobalReference(const GlobalValue
*GV
,
120 const TargetMachine
&TM
,
121 MachineModuleInfo
*MMI
,
122 MCStreamer
&Streamer
) const override
;
124 // The symbol that gets passed to .cfi_personality.
125 MCSymbol
*getCFIPersonalitySymbol(const GlobalValue
*GV
,
126 const TargetMachine
&TM
,
127 MachineModuleInfo
*MMI
) const override
;
129 /// Get MachO PC relative GOT entry relocation
130 const MCExpr
*getIndirectSymViaGOTPCRel(const GlobalValue
*GV
,
132 const MCValue
&MV
, int64_t Offset
,
133 MachineModuleInfo
*MMI
,
134 MCStreamer
&Streamer
) const override
;
136 void getNameWithPrefix(SmallVectorImpl
<char> &OutName
, const GlobalValue
*GV
,
137 const TargetMachine
&TM
) const override
;
140 class TargetLoweringObjectFileCOFF
: public TargetLoweringObjectFile
{
141 mutable unsigned NextUniqueID
= 0;
144 ~TargetLoweringObjectFileCOFF() override
= default;
146 void Initialize(MCContext
&Ctx
, const TargetMachine
&TM
) override
;
147 MCSection
*getExplicitSectionGlobal(const GlobalObject
*GO
, SectionKind Kind
,
148 const TargetMachine
&TM
) const override
;
150 MCSection
*SelectSectionForGlobal(const GlobalObject
*GO
, SectionKind Kind
,
151 const TargetMachine
&TM
) const override
;
153 void getNameWithPrefix(SmallVectorImpl
<char> &OutName
, const GlobalValue
*GV
,
154 const TargetMachine
&TM
) const override
;
156 MCSection
*getSectionForJumpTable(const Function
&F
,
157 const TargetMachine
&TM
) const override
;
159 /// Emit Obj-C garbage collection and linker options.
160 void emitModuleMetadata(MCStreamer
&Streamer
, Module
&M
) const override
;
162 MCSection
*getStaticCtorSection(unsigned Priority
,
163 const MCSymbol
*KeySym
) const override
;
164 MCSection
*getStaticDtorSection(unsigned Priority
,
165 const MCSymbol
*KeySym
) const override
;
167 void emitLinkerFlagsForGlobal(raw_ostream
&OS
,
168 const GlobalValue
*GV
) const override
;
170 void emitLinkerFlagsForUsed(raw_ostream
&OS
,
171 const GlobalValue
*GV
) const override
;
173 const MCExpr
*lowerRelativeReference(const GlobalValue
*LHS
,
174 const GlobalValue
*RHS
,
175 const TargetMachine
&TM
) const override
;
177 /// Given a mergeable constant with the specified size and relocation
178 /// information, return a section that it should be placed in.
179 MCSection
*getSectionForConstant(const DataLayout
&DL
, SectionKind Kind
,
181 unsigned &Align
) const override
;
184 class TargetLoweringObjectFileWasm
: public TargetLoweringObjectFile
{
185 mutable unsigned NextUniqueID
= 0;
188 TargetLoweringObjectFileWasm() = default;
189 ~TargetLoweringObjectFileWasm() override
= default;
191 MCSection
*getExplicitSectionGlobal(const GlobalObject
*GO
, SectionKind Kind
,
192 const TargetMachine
&TM
) const override
;
194 MCSection
*SelectSectionForGlobal(const GlobalObject
*GO
, SectionKind Kind
,
195 const TargetMachine
&TM
) const override
;
197 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference
,
198 const Function
&F
) const override
;
200 void InitializeWasm();
201 MCSection
*getStaticCtorSection(unsigned Priority
,
202 const MCSymbol
*KeySym
) const override
;
203 MCSection
*getStaticDtorSection(unsigned Priority
,
204 const MCSymbol
*KeySym
) const override
;
206 const MCExpr
*lowerRelativeReference(const GlobalValue
*LHS
,
207 const GlobalValue
*RHS
,
208 const TargetMachine
&TM
) const override
;
211 class TargetLoweringObjectFileXCOFF
: public TargetLoweringObjectFile
{
213 TargetLoweringObjectFileXCOFF() = default;
214 ~TargetLoweringObjectFileXCOFF() override
= default;
216 void Initialize(MCContext
&Ctx
, const TargetMachine
&TM
) override
;
218 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference
,
219 const Function
&F
) const override
;
221 MCSection
*getExplicitSectionGlobal(const GlobalObject
*GO
, SectionKind Kind
,
222 const TargetMachine
&TM
) const override
;
224 MCSection
*getStaticCtorSection(unsigned Priority
,
225 const MCSymbol
*KeySym
) const override
;
226 MCSection
*getStaticDtorSection(unsigned Priority
,
227 const MCSymbol
*KeySym
) const override
;
229 const MCExpr
*lowerRelativeReference(const GlobalValue
*LHS
,
230 const GlobalValue
*RHS
,
231 const TargetMachine
&TM
) const override
;
233 MCSection
*SelectSectionForGlobal(const GlobalObject
*GO
, SectionKind Kind
,
234 const TargetMachine
&TM
) const override
;
236 static XCOFF::StorageClass
getStorageClassForGlobal(const GlobalObject
*GO
);
239 } // end namespace llvm
241 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H