1 //===-- llvm/Target/TargetLoweringObjectFile.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_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/MC/SectionKind.h"
30 class TargetLoweringObjectFile {
34 TargetLoweringObjectFile();
36 /// TextSection - Section directive for standard text.
38 const MCSection *TextSection;
40 /// DataSection - Section directive for standard data.
42 const MCSection *DataSection;
44 /// BSSSection - Section that is default initialized to zero.
45 const MCSection *BSSSection;
47 /// ReadOnlySection - Section that is readonly and can contain arbitrary
48 /// initialized data. Targets are not required to have a readonly section.
49 /// If they don't, various bits of code will fall back to using the data
50 /// section for constants.
51 const MCSection *ReadOnlySection;
53 /// StaticCtorSection - This section contains the static constructor pointer
55 const MCSection *StaticCtorSection;
57 /// StaticDtorSection - This section contains the static destructor pointer
59 const MCSection *StaticDtorSection;
61 /// LSDASection - If exception handling is supported by the target, this is
62 /// the section the Language Specific Data Area information is emitted to.
63 const MCSection *LSDASection;
65 /// EHFrameSection - If exception handling is supported by the target, this is
66 /// the section the EH Frame is emitted to.
67 const MCSection *EHFrameSection;
69 // Dwarf sections for debug info. If a target supports debug info, these must
71 const MCSection *DwarfAbbrevSection;
72 const MCSection *DwarfInfoSection;
73 const MCSection *DwarfLineSection;
74 const MCSection *DwarfFrameSection;
75 const MCSection *DwarfPubNamesSection;
76 const MCSection *DwarfPubTypesSection;
77 const MCSection *DwarfDebugInlineSection;
78 const MCSection *DwarfStrSection;
79 const MCSection *DwarfLocSection;
80 const MCSection *DwarfARangesSection;
81 const MCSection *DwarfRangesSection;
82 const MCSection *DwarfMacroInfoSection;
86 MCContext &getContext() const { return *Ctx; }
89 virtual ~TargetLoweringObjectFile();
91 /// Initialize - this method must be called before any actual lowering is
92 /// done. This specifies the current context for codegen, and gives the
93 /// lowering implementations a chance to set up their default sections.
94 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
99 const MCSection *getTextSection() const { return TextSection; }
100 const MCSection *getDataSection() const { return DataSection; }
101 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
102 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
103 const MCSection *getLSDASection() const { return LSDASection; }
104 const MCSection *getEHFrameSection() const { return EHFrameSection; }
105 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
106 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
107 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
108 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
109 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
110 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
111 const MCSection *getDwarfDebugInlineSection() const {
112 return DwarfDebugInlineSection;
114 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
115 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
116 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
117 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
118 const MCSection *getDwarfMacroInfoSection() const {
119 return DwarfMacroInfoSection;
122 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
123 /// decide not to emit the UsedDirective for some symbols in llvm.used.
124 /// FIXME: REMOVE this (rdar://7071300)
125 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
130 /// getSectionForConstant - Given a constant with the SectionKind, return a
131 /// section that it should be placed in.
132 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
134 /// getKindForGlobal - Classify the specified global variable into a set of
135 /// target independent categories embodied in SectionKind.
136 static SectionKind getKindForGlobal(const GlobalValue *GV,
137 const TargetMachine &TM);
139 /// SectionForGlobal - This method computes the appropriate section to emit
140 /// the specified global variable or function definition. This should not
141 /// be passed external (or available externally) globals.
142 const MCSection *SectionForGlobal(const GlobalValue *GV,
143 SectionKind Kind, Mangler *Mang,
144 const TargetMachine &TM) const;
146 /// SectionForGlobal - This method computes the appropriate section to emit
147 /// the specified global variable or function definition. This should not
148 /// be passed external (or available externally) globals.
149 const MCSection *SectionForGlobal(const GlobalValue *GV,
151 const TargetMachine &TM) const {
152 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
157 /// getExplicitSectionGlobal - Targets should implement this method to assign
158 /// a section to globals with an explicit section specfied. The
159 /// implementation of this method can assume that GV->hasSection() is true.
160 virtual const MCSection *
161 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
162 Mangler *Mang, const TargetMachine &TM) const = 0;
164 /// getSpecialCasedSectionGlobals - Allow the target to completely override
165 /// section assignment of a global.
166 virtual const MCSection *
167 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
168 SectionKind Kind) const {
173 virtual const MCSection *
174 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
175 Mangler *Mang, const TargetMachine &TM) const;
181 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
184 /// TLSDataSection - Section directive for Thread Local data.
186 const MCSection *TLSDataSection; // Defaults to ".tdata".
188 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
189 /// Null if this target doesn't support a BSS section.
191 const MCSection *TLSBSSSection; // Defaults to ".tbss".
193 const MCSection *DataRelSection;
194 const MCSection *DataRelLocalSection;
195 const MCSection *DataRelROSection;
196 const MCSection *DataRelROLocalSection;
198 const MCSection *MergeableConst4Section;
199 const MCSection *MergeableConst8Section;
200 const MCSection *MergeableConst16Section;
203 const MCSection *getELFSection(const char *Name, bool isDirective,
204 SectionKind Kind) const;
206 TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
207 bool hasCrazyBSS = false)
208 : HasCrazyBSS(hasCrazyBSS) {}
210 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
212 /// getSectionForConstant - Given a constant with the SectionKind, return a
213 /// section that it should be placed in.
214 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
217 virtual const MCSection *
218 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
219 Mangler *Mang, const TargetMachine &TM) const;
221 virtual const MCSection *
222 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
223 Mangler *Mang, const TargetMachine &TM) const;
228 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
229 const MCSection *CStringSection;
230 const MCSection *UStringSection;
231 const MCSection *TextCoalSection;
232 const MCSection *ConstTextCoalSection;
233 const MCSection *ConstDataCoalSection;
234 const MCSection *ConstDataSection;
235 const MCSection *DataCoalSection;
236 const MCSection *FourByteConstantSection;
237 const MCSection *EightByteConstantSection;
238 const MCSection *SixteenByteConstantSection;
241 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
243 virtual const MCSection *
244 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
245 Mangler *Mang, const TargetMachine &TM) const;
247 virtual const MCSection *
248 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
249 Mangler *Mang, const TargetMachine &TM) const;
251 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
253 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
254 /// decide not to emit the UsedDirective for some symbols in llvm.used.
255 /// FIXME: REMOVE this (rdar://7071300)
256 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
259 /// getMachOSection - Return the MCSection for the specified mach-o section.
260 /// FIXME: Switch this to a semantic view eventually.
261 const MCSection *getMachOSection(const char *Name, bool isDirective,
262 SectionKind K) const;
267 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
269 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
271 virtual const MCSection *
272 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
273 Mangler *Mang, const TargetMachine &TM) const;
275 virtual const MCSection *
276 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
277 Mangler *Mang, const TargetMachine &TM) const;
279 /// getCOFFSection - Return the MCSection for the specified COFF section.
280 /// FIXME: Switch this to a semantic view eventually.
281 const MCSection *getCOFFSection(const char *Name, bool isDirective,
282 SectionKind K) const;
285 } // end namespace llvm