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 = 1; // ID 0 is reserved for execute-only sections
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 GlobalObject *GO, SectionKind Kind,
57 const TargetMachine &TM) const override;
59 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
60 const TargetMachine &TM) const override;
62 MCSection *getSectionForJumpTable(const Function &F,
63 const TargetMachine &TM) const override;
65 bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference,
66 const Function &F) const override;
68 /// Return an MCExpr to use for a reference to the specified type info global
69 /// variable from exception handling information.
70 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
72 const TargetMachine &TM,
73 MachineModuleInfo *MMI,
74 MCStreamer &Streamer) const override;
76 // The symbol that gets passed to .cfi_personality.
77 MCSymbol *getCFIPersonalitySymbol(const GlobalValue *GV,
78 const TargetMachine &TM,
79 MachineModuleInfo *MMI) const override;
81 void InitializeELF(bool UseInitArray_);
82 MCSection *getStaticCtorSection(unsigned Priority,
83 const MCSymbol *KeySym) const override;
84 MCSection *getStaticDtorSection(unsigned Priority,
85 const MCSymbol *KeySym) const override;
87 const MCExpr *lowerRelativeReference(const GlobalValue *LHS,
88 const GlobalValue *RHS,
89 const TargetMachine &TM) const override;
94 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
96 ~TargetLoweringObjectFileMachO() override {}
97 TargetLoweringObjectFileMachO();
99 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
101 /// Emit the module flags that specify the garbage collection information.
102 void emitModuleFlags(MCStreamer &Streamer,
103 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
104 const TargetMachine &TM) const override;
106 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
107 const TargetMachine &TM) const override;
109 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
110 const TargetMachine &TM) const override;
112 MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
114 unsigned &Align) const override;
116 /// The mach-o version of this method defaults to returning a stub reference.
117 const MCExpr *getTTypeGlobalReference(const GlobalValue *GV,
119 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,
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;
134 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
135 const TargetMachine &TM) const override;
140 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
141 mutable unsigned NextUniqueID = 0;
144 ~TargetLoweringObjectFileCOFF() override {}
146 void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
147 MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
148 const TargetMachine &TM) const override;
150 MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
151 const TargetMachine &TM) const override;
153 void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
154 const TargetMachine &TM) const override;
156 MCSection *getSectionForJumpTable(const Function &F,
157 const TargetMachine &TM) const override;
159 /// Emit Obj-C garbage collection and linker options. Only linker option
160 /// emission is implemented for COFF.
161 void emitModuleFlags(MCStreamer &Streamer,
162 ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
163 const TargetMachine &TM) const override;
165 MCSection *getStaticCtorSection(unsigned Priority,
166 const MCSymbol *KeySym) const override;
167 MCSection *getStaticDtorSection(unsigned Priority,
168 const MCSymbol *KeySym) const override;
170 void emitLinkerFlagsForGlobal(raw_ostream &OS,
171 const GlobalValue *GV) const override;
174 } // end namespace llvm