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 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,
50 const Constant *C) const override;
52 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
54 const TargetMachine &TM) const override;
56 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
58 const TargetMachine &TM) const override;
60 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
61 const TargetMachine &TM) const override;
63 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
64 const Function &F) const override;
66 /// Return an MCExpr to use for a reference to the specified type info global
67 /// variable from exception handling information.
69 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
70 Mangler &Mang, const TargetMachine &TM,
71 MachineModuleInfo *MMI,
72 MCStreamer &Streamer) const override;
74 // The symbol that gets passed to .cfi_personality.
75 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
76 const TargetMachine &TM,
77 MachineModuleInfo *MMI) const override;
79 void InitializeELF(bool UseInitArray_);
80 MCSection *getStaticCtorSection(unsigned Priority,
81 const MCSymbol *KeySym) const override;
82 MCSection *getStaticDtorSection(unsigned Priority,
83 const MCSymbol *KeySym) const override;
88 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
90 ~TargetLoweringObjectFileMachO() override {}
91 TargetLoweringObjectFileMachO();
93 /// Emit the module flags that specify the garbage collection information.
94 void emitModuleFlags(MCStreamer &Streamer,
95 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
96 Mangler &Mang, const TargetMachine &TM) const override;
98 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
100 const TargetMachine &TM) const override;
102 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
104 const TargetMachine &TM) const override;
106 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
107 const Constant *C) const override;
109 /// The mach-o version of this method defaults to returning a stub reference.
111 getTTypeGlobalReference(const GlobalValue *GV, unsigned Encoding,
112 Mangler &Mang, const TargetMachine &TM,
113 MachineModuleInfo *MMI,
114 MCStreamer &Streamer) const override;
116 // The symbol that gets passed to .cfi_personality.
117 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV, Mangler &Mang,
118 const TargetMachine &TM,
119 MachineModuleInfo *MMI) const override;
121 /// Get MachO PC relative GOT entry relocation
122 const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
123 const MCValue &MV, int64_t Offset,
124 MachineModuleInfo *MMI,
125 MCStreamer &Streamer) const override;
130 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
132 ~TargetLoweringObjectFileCOFF() override {}
134 MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
136 const TargetMachine &TM) const override;
138 MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
140 const TargetMachine &TM) const override;
142 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
143 bool CannotUsePrivateLabel, Mangler &Mang,
144 const TargetMachine &TM) const override;
146 MCSection *getSectionForJumpTable(const Function &F, Mangler &Mang,
147 const TargetMachine &TM) const override;
149 /// Emit Obj-C garbage collection and linker options. Only linker option
150 /// emission is implemented for COFF.
151 void emitModuleFlags(MCStreamer &Streamer,
152 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
153 Mangler &Mang, const TargetMachine &TM) const override;
155 MCSection *getStaticCtorSection(unsigned Priority,
156 const MCSymbol *KeySym) const override;
157 MCSection *getStaticDtorSection(unsigned Priority,
158 const MCSymbol *KeySym) const override;
160 void emitLinkerFlagsForGlobal(raw_ostream &OS, const GlobalValue *GV,
161 const Mangler &Mang) const override;
164 } // end namespace llvm