1 //==- llvm/CodeGen/TargetLoweringObjectFileImpl.h - Object Info --*- C++ -*-==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
18 #include "llvm/CodeGen/TargetLoweringObjectFile.h"
19 #include "llvm/IR/Module.h"
20 #include "llvm/MC/MCExpr.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;
41 TargetLoweringObjectFileELF() = default;
42 ~TargetLoweringObjectFileELF() override = default;
44 /// Emit Obj-C garbage collection and linker options.
45 void emitModuleMetadata(MCStreamer &Streamer, Module &M,
46 const TargetMachine &TM) const override;
48 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
49 const MCSymbol *Sym) const override;
51 /// Given a constant with the SectionKind, return a section that it should be
53 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
55 unsigned &Align) const override;
57 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
58 const TargetMachine &TM) const override;
60 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
61 const TargetMachine &TM) const override;
63 MCSection *getSectionForJumpTable(const Function &F,
64 const TargetMachine &TM) const override;
66 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
67 const Function &F) const override;
69 /// Return an MCExpr to use for a reference to the specified type info global
70 /// variable from exception handling information.
71 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
73 const TargetMachine &TM,
74 MachineModuleInfo *MMI,
75 MCStreamer &Streamer) const override;
77 // The symbol that gets passed to .cfi_personality.
78 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
79 const TargetMachine &TM,
80 MachineModuleInfo *MMI) const override;
82 void InitializeELF(bool UseInitArray_);
83 MCSection *getStaticCtorSection(unsigned Priority,
84 const MCSymbol *KeySym) const override;
85 MCSection *getStaticDtorSection(unsigned Priority,
86 const MCSymbol *KeySym) const override;
88 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
89 const GlobalValue *RHS,
90 const TargetMachine &TM) const override;
93 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
95 TargetLoweringObjectFileMachO();
96 ~TargetLoweringObjectFileMachO() override = default;
98 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
100 /// Emit the module flags that specify the garbage collection information.
101 void emitModuleMetadata(MCStreamer &Streamer, Module &M,
102 const TargetMachine &TM) const override;
104 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
105 const TargetMachine &TM) const override;
107 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
108 const TargetMachine &TM) const override;
110 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
112 unsigned &Align) const override;
114 /// The mach-o version of this method defaults to returning a stub reference.
115 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
117 const TargetMachine &TM,
118 MachineModuleInfo *MMI,
119 MCStreamer &Streamer) const override;
121 // The symbol that gets passed to .cfi_personality.
122 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
123 const TargetMachine &TM,
124 MachineModuleInfo *MMI) const override;
126 /// Get MachO PC relative GOT entry relocation
127 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
128 const MCValue &MV, int64_t Offset,
129 MachineModuleInfo *MMI,
130 MCStreamer &Streamer) const override;
132 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
133 const TargetMachine &TM) const override;
136 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
137 mutable unsigned NextUniqueID = 0;
140 ~TargetLoweringObjectFileCOFF() override = default;
142 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
143 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
144 const TargetMachine &TM) const override;
146 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
147 const TargetMachine &TM) const override;
149 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
150 const TargetMachine &TM) const override;
152 MCSection *getSectionForJumpTable(const Function &F,
153 const TargetMachine &TM) const override;
155 /// Emit Obj-C garbage collection and linker options.
156 void emitModuleMetadata(MCStreamer &Streamer, Module &M,
157 const TargetMachine &TM) const override;
159 MCSection *getStaticCtorSection(unsigned Priority,
160 const MCSymbol *KeySym) const override;
161 MCSection *getStaticDtorSection(unsigned Priority,
162 const MCSymbol *KeySym) const override;
164 void emitLinkerFlagsForGlobal(raw_ostream &OS,
165 const GlobalValue *GV) const override;
168 class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile {
169 mutable unsigned NextUniqueID = 0;
172 TargetLoweringObjectFileWasm() = default;
173 ~TargetLoweringObjectFileWasm() override = default;
175 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
176 const TargetMachine &TM) const override;
178 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
179 const TargetMachine &TM) const override;
181 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
182 const Function &F) const override;
184 void InitializeWasm();
185 MCSection *getStaticCtorSection(unsigned Priority,
186 const MCSymbol *KeySym) const override;
187 MCSection *getStaticDtorSection(unsigned Priority,
188 const MCSymbol *KeySym) const override;
190 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
191 const GlobalValue *RHS,
192 const TargetMachine &TM) const override;
195 } // end namespace llvm
197 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H