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/MC/MCExpr.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
23 class MachineModuleInfo;
34 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36 mutable unsigned NextUniqueID = 0;
39 MCSymbolRefExpr::VariantKind PLTRelativeVariantKind =
40 MCSymbolRefExpr::VK_None;
43 TargetLoweringObjectFileELF() : UseInitArray(false) {}
45 ~TargetLoweringObjectFileELF() override {}
47 void emitPersonalityValue(MCStreamer &Streamer, const DataLayout &TM,
48 const MCSymbol *Sym) const override;
50 /// Given a constant with the SectionKind, return a section that it should be
52 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
54 unsigned &Align) const override;
56 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
58 const TargetMachine &TM) const override;
60 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
62 const TargetMachine &TM) const override;
64 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
65 const TargetMachine &TM) const override;
67 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
68 const Function &F) const override;
70 /// Return an MCExpr to use for a reference to the specified type info global
71 /// variable from exception handling information.
73 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
74 Mangler &Mang, const TargetMachine &TM,
75 MachineModuleInfo *MMI,
76 MCStreamer &Streamer) const override;
78 // The symbol that gets passed to .cfi_personality.
79 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
80 const TargetMachine &TM,
81 MachineModuleInfo *MMI) const override;
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;
89 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
90 const GlobalValue *RHS, Mangler &Mang,
91 const TargetMachine &TM) const override;
96 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
98 ~TargetLoweringObjectFileMachO() override {}
99 TargetLoweringObjectFileMachO();
101 /// Emit the module flags that specify the garbage collection information.
102 void emitModuleFlags(MCStreamer &Streamer,
103 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
104 Mangler &Mang, const TargetMachine &TM) const override;
106 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
108 const TargetMachine &TM) const override;
110 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
112 const TargetMachine &TM) const override;
114 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
116 unsigned &Align) const override;
118 /// The mach-o version of this method defaults to returning a stub reference.
120 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
121 Mangler &Mang, const TargetMachine &TM,
122 MachineModuleInfo *MMI,
123 MCStreamer &Streamer) const override;
125 // The symbol that gets passed to .cfi_personality.
126 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
127 const TargetMachine &TM,
128 MachineModuleInfo *MMI) const override;
130 /// Get MachO PC relative GOT entry relocation
131 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
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 Mangler &Mang, const TargetMachine &TM) const override;
142 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
143 mutable unsigned NextUniqueID = 0;
146 ~TargetLoweringObjectFileCOFF() override {}
148 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
150 const TargetMachine &TM) const override;
152 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
154 const TargetMachine &TM) const override;
156 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
157 Mangler &Mang, const TargetMachine &TM) const override;
159 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
160 const TargetMachine &TM) const override;
162 /// Emit Obj-C garbage collection and linker options. Only linker option
163 /// emission is implemented for COFF.
164 void emitModuleFlags(MCStreamer &Streamer,
165 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
166 Mangler &Mang, const TargetMachine &TM) const override;
168 MCSection *getStaticCtorSection(unsigned Priority,
169 const MCSymbol *KeySym) const override;
170 MCSection *getStaticDtorSection(unsigned Priority,
171 const MCSymbol *KeySym) const override;
173 void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
174 const Mangler &Mang) const override;
177 } // end namespace llvm