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/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
23 class MachineModuleInfo;
35 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
37 mutable unsigned NextUniqueID = 0;
40 TargetLoweringObjectFileELF() : UseInitArray(false) {}
42 ~TargetLoweringObjectFileELF() override {}
44 void emitPersonalityValue(MCStreamer &Streamer, const TargetMachine &TM,
45 const MCSymbol *Sym) const override;
47 /// Given a constant with the SectionKind, return a section that it should be
49 const MCSection *getSectionForConstant(SectionKind Kind,
50 const Constant *C) const override;
52 const MCSection *getExplicitSectionGlobal(const GlobalValue *GV,
53 SectionKind Kind, Mangler &Mang,
54 const TargetMachine &TM) const override;
56 const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
57 SectionKind Kind, Mangler &Mang,
58 const TargetMachine &TM) const override;
61 getSectionForJumpTable(const Function &F, Mangler &Mang,
62 const TargetMachine &TM) const override;
64 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
65 const Function &F) const override;
67 /// Return an MCExpr to use for a reference to the specified type info global
68 /// variable from exception handling information.
70 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
71 Mangler &Mang, const TargetMachine &TM,
72 MachineModuleInfo *MMI,
73 MCStreamer &Streamer) const override;
75 // The symbol that gets passed to .cfi_personality.
76 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
77 const TargetMachine &TM,
78 MachineModuleInfo *MMI) const override;
80 void InitializeELF(bool UseInitArray_);
81 const MCSection *getStaticCtorSection(unsigned Priority,
82 const MCSymbol *KeySym) const override;
83 const MCSection *getStaticDtorSection(unsigned Priority,
84 const MCSymbol *KeySym) const override;
89 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
91 ~TargetLoweringObjectFileMachO() override {}
92 TargetLoweringObjectFileMachO();
94 /// Extract the dependent library name from a linker option string. Returns
95 /// StringRef() if the option does not specify a library.
96 StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
98 /// Emit the module flags that specify the garbage collection information.
99 void emitModuleFlags(MCStreamer &Streamer,
100 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
101 Mangler &Mang, const TargetMachine &TM) const override;
104 SelectSectionForGlobal(const GlobalValue *GV,
105 SectionKind Kind, Mangler &Mang,
106 const TargetMachine &TM) const override;
109 getExplicitSectionGlobal(const GlobalValue *GV,
110 SectionKind Kind, Mangler &Mang,
111 const TargetMachine &TM) const override;
113 const MCSection *getSectionForConstant(SectionKind Kind,
114 const Constant *C) const override;
116 /// The mach-o version of this method defaults to returning a stub reference.
118 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
119 Mangler &Mang, const TargetMachine &TM,
120 MachineModuleInfo *MMI,
121 MCStreamer &Streamer) const override;
123 // The symbol that gets passed to .cfi_personality.
124 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
125 const TargetMachine &TM,
126 MachineModuleInfo *MMI) const override;
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;
137 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
139 ~TargetLoweringObjectFileCOFF() override {}
142 getExplicitSectionGlobal(const GlobalValue *GV,
143 SectionKind Kind, Mangler &Mang,
144 const TargetMachine &TM) const override;
147 SelectSectionForGlobal(const GlobalValue *GV,
148 SectionKind Kind, Mangler &Mang,
149 const TargetMachine &TM) const override;
151 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
152 bool CannotUsePrivateLabel, Mangler &Mang,
153 const TargetMachine &TM) const override;
156 getSectionForJumpTable(const Function &F, Mangler &Mang,
157 const TargetMachine &TM) const override;
159 /// Extract the dependent library name from a linker option string. Returns
160 /// StringRef() if the option does not specify a library.
161 StringRef getDepLibFromLinkerOpt(StringRef LinkerOption) const override;
163 /// Emit Obj-C garbage collection and linker options. Only linker option
164 /// emission is implemented for COFF.
165 void emitModuleFlags(MCStreamer &Streamer,
166 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
167 Mangler &Mang, const TargetMachine &TM) const override;
169 const MCSection *getStaticCtorSection(unsigned Priority,
170 const MCSymbol *KeySym) const override;
171 const MCSection *getStaticDtorSection(unsigned Priority,
172 const MCSymbol *KeySym) const override;
175 } // end namespace llvm