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/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;
41 TargetLoweringObjectFileELF() = default;
42 ~TargetLoweringObjectFileELF() override = default;
44 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
45 const MCSymbol *Sym) const override;
47 /// Given a constant with the SectionKind, return a section that it should be
49 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
51 unsigned &Align) const override;
53 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
54 const TargetMachine &TM) const override;
56 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
57 const TargetMachine &TM) const override;
59 MCSection *getSectionForJumpTable(const Function &F,
60 const TargetMachine &TM) const override;
62 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
63 const Function &F) const override;
65 /// Return an MCExpr to use for a reference to the specified type info global
66 /// variable from exception handling information.
67 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
69 const TargetMachine &TM,
70 MachineModuleInfo *MMI,
71 MCStreamer &Streamer) const override;
73 // The symbol that gets passed to .cfi_personality.
74 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
75 const TargetMachine &TM,
76 MachineModuleInfo *MMI) const override;
78 void InitializeELF(bool UseInitArray_);
79 MCSection *getStaticCtorSection(unsigned Priority,
80 const MCSymbol *KeySym) const override;
81 MCSection *getStaticDtorSection(unsigned Priority,
82 const MCSymbol *KeySym) const override;
84 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
85 const GlobalValue *RHS,
86 const TargetMachine &TM) const override;
89 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
91 TargetLoweringObjectFileMachO();
92 ~TargetLoweringObjectFileMachO() override = default;
94 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
96 /// Emit the module flags that specify the garbage collection information.
97 void emitModuleFlags(MCStreamer &Streamer,
98 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
99 const TargetMachine &TM) const override;
101 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
102 const TargetMachine &TM) const override;
104 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
105 const TargetMachine &TM) const override;
107 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
109 unsigned &Align) const override;
111 /// The mach-o version of this method defaults to returning a stub reference.
112 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
114 const TargetMachine &TM,
115 MachineModuleInfo *MMI,
116 MCStreamer &Streamer) const override;
118 // The symbol that gets passed to .cfi_personality.
119 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
120 const TargetMachine &TM,
121 MachineModuleInfo *MMI) const override;
123 /// Get MachO PC relative GOT entry relocation
124 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
125 const MCValue &MV, int64_t Offset,
126 MachineModuleInfo *MMI,
127 MCStreamer &Streamer) const override;
129 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
130 const TargetMachine &TM) const override;
133 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
134 mutable unsigned NextUniqueID = 0;
137 ~TargetLoweringObjectFileCOFF() override = default;
139 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
140 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
141 const TargetMachine &TM) const override;
143 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
144 const TargetMachine &TM) const override;
146 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
147 const TargetMachine &TM) const override;
149 MCSection *getSectionForJumpTable(const Function &F,
150 const TargetMachine &TM) const override;
152 /// Emit Obj-C garbage collection and linker options. Only linker option
153 /// emission is implemented for COFF.
154 void emitModuleFlags(MCStreamer &Streamer,
155 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
156 const TargetMachine &TM) const override;
158 MCSection *getStaticCtorSection(unsigned Priority,
159 const MCSymbol *KeySym) const override;
160 MCSection *getStaticDtorSection(unsigned Priority,
161 const MCSymbol *KeySym) const override;
163 void emitLinkerFlagsForGlobal(raw_ostream &OS,
164 const GlobalValue *GV) const override;
167 class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile {
168 mutable unsigned NextUniqueID = 0;
171 TargetLoweringObjectFileWasm() = default;
172 ~TargetLoweringObjectFileWasm() override = default;
174 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
175 const TargetMachine &TM) const override;
177 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
178 const TargetMachine &TM) const override;
180 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
181 const Function &F) const override;
183 void InitializeWasm();
185 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
186 const GlobalValue *RHS,
187 const TargetMachine &TM) const override;
190 } // end namespace llvm
192 #endif // LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H