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/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
22 class MachineModuleInfo;
32 class TargetLoweringObjectFile {
35 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
36 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
39 TargetLoweringObjectFile();
41 /// TextSection - Section directive for standard text.
43 const MCSection *TextSection;
45 /// DataSection - Section directive for standard data.
47 const MCSection *DataSection;
49 /// BSSSection - Section that is default initialized to zero.
50 const MCSection *BSSSection;
52 /// ReadOnlySection - Section that is readonly and can contain arbitrary
53 /// initialized data. Targets are not required to have a readonly section.
54 /// If they don't, various bits of code will fall back to using the data
55 /// section for constants.
56 const MCSection *ReadOnlySection;
58 /// StaticCtorSection - This section contains the static constructor pointer
60 const MCSection *StaticCtorSection;
62 /// StaticDtorSection - This section contains the static destructor pointer
64 const MCSection *StaticDtorSection;
66 /// LSDASection - If exception handling is supported by the target, this is
67 /// the section the Language Specific Data Area information is emitted to.
68 const MCSection *LSDASection;
70 /// EHFrameSection - If exception handling is supported by the target, this is
71 /// the section the EH Frame is emitted to.
72 const MCSection *EHFrameSection;
74 // Dwarf sections for debug info. If a target supports debug info, these must
76 const MCSection *DwarfAbbrevSection;
77 const MCSection *DwarfInfoSection;
78 const MCSection *DwarfLineSection;
79 const MCSection *DwarfFrameSection;
80 const MCSection *DwarfPubNamesSection;
81 const MCSection *DwarfPubTypesSection;
82 const MCSection *DwarfDebugInlineSection;
83 const MCSection *DwarfStrSection;
84 const MCSection *DwarfLocSection;
85 const MCSection *DwarfARangesSection;
86 const MCSection *DwarfRangesSection;
87 const MCSection *DwarfMacroInfoSection;
91 MCContext &getContext() const { return *Ctx; }
94 virtual ~TargetLoweringObjectFile();
96 /// Initialize - this method must be called before any actual lowering is
97 /// done. This specifies the current context for codegen, and gives the
98 /// lowering implementations a chance to set up their default sections.
99 virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
104 const MCSection *getTextSection() const { return TextSection; }
105 const MCSection *getDataSection() const { return DataSection; }
106 const MCSection *getBSSSection() const { return BSSSection; }
107 const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
108 const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
109 const MCSection *getLSDASection() const { return LSDASection; }
110 const MCSection *getEHFrameSection() const { return EHFrameSection; }
111 const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
112 const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
113 const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
114 const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
115 const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
116 const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
117 const MCSection *getDwarfDebugInlineSection() const {
118 return DwarfDebugInlineSection;
120 const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
121 const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
122 const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
123 const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
124 const MCSection *getDwarfMacroInfoSection() const {
125 return DwarfMacroInfoSection;
128 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
129 /// decide not to emit the UsedDirective for some symbols in llvm.used.
130 /// FIXME: REMOVE this (rdar://7071300)
131 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
136 /// getSectionForConstant - Given a constant with the SectionKind, return a
137 /// section that it should be placed in.
138 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
140 /// getKindForGlobal - Classify the specified global variable into a set of
141 /// target independent categories embodied in SectionKind.
142 static SectionKind getKindForGlobal(const GlobalValue *GV,
143 const TargetMachine &TM);
145 /// SectionForGlobal - This method computes the appropriate section to emit
146 /// the specified global variable or function definition. This should not
147 /// be passed external (or available externally) globals.
148 const MCSection *SectionForGlobal(const GlobalValue *GV,
149 SectionKind Kind, Mangler *Mang,
150 const TargetMachine &TM) const;
152 /// SectionForGlobal - This method computes the appropriate section to emit
153 /// the specified global variable or function definition. This should not
154 /// be passed external (or available externally) globals.
155 const MCSection *SectionForGlobal(const GlobalValue *GV,
157 const TargetMachine &TM) const {
158 return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
163 /// getExplicitSectionGlobal - Targets should implement this method to assign
164 /// a section to globals with an explicit section specfied. The
165 /// implementation of this method can assume that GV->hasSection() is true.
166 virtual const MCSection *
167 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
168 Mangler *Mang, const TargetMachine &TM) const = 0;
170 /// getSpecialCasedSectionGlobals - Allow the target to completely override
171 /// section assignment of a global.
172 virtual const MCSection *
173 getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
174 SectionKind Kind) const {
178 /// getSymbolForDwarfGlobalReference - Return an MCExpr to use for a
179 /// pc-relative reference to the specified global variable from exception
180 /// handling information. In addition to the symbol, this returns
183 /// IsIndirect - True if the returned symbol is actually a stub that contains
184 /// the address of the symbol, false if the symbol is the global itself.
186 /// IsPCRel - True if the symbol reference is already pc-relative, false if
187 /// the caller needs to subtract off the address of the reference from the
190 virtual const MCExpr *
191 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
192 MachineModuleInfo *MMI,
193 bool &IsIndirect, bool &IsPCRel) const;
196 virtual const MCSection *
197 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
198 Mangler *Mang, const TargetMachine &TM) const;
204 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
205 mutable void *UniquingMap;
207 /// TLSDataSection - Section directive for Thread Local data.
209 const MCSection *TLSDataSection; // Defaults to ".tdata".
211 /// TLSBSSSection - Section directive for Thread Local uninitialized data.
212 /// Null if this target doesn't support a BSS section.
214 const MCSection *TLSBSSSection; // Defaults to ".tbss".
216 const MCSection *DataRelSection;
217 const MCSection *DataRelLocalSection;
218 const MCSection *DataRelROSection;
219 const MCSection *DataRelROLocalSection;
221 const MCSection *MergeableConst4Section;
222 const MCSection *MergeableConst8Section;
223 const MCSection *MergeableConst16Section;
226 const MCSection *getELFSection(StringRef Section, unsigned Type,
227 unsigned Flags, SectionKind Kind,
228 bool IsExplicit = false) const;
230 TargetLoweringObjectFileELF() : UniquingMap(0) {}
231 ~TargetLoweringObjectFileELF();
233 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
235 /// getSectionForConstant - Given a constant with the SectionKind, return a
236 /// section that it should be placed in.
237 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
240 virtual const MCSection *
241 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
242 Mangler *Mang, const TargetMachine &TM) const;
244 virtual const MCSection *
245 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
246 Mangler *Mang, const TargetMachine &TM) const;
251 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
252 mutable void *UniquingMap;
254 const MCSection *CStringSection;
255 const MCSection *UStringSection;
256 const MCSection *TextCoalSection;
257 const MCSection *ConstTextCoalSection;
258 const MCSection *ConstDataCoalSection;
259 const MCSection *ConstDataSection;
260 const MCSection *DataCoalSection;
261 const MCSection *FourByteConstantSection;
262 const MCSection *EightByteConstantSection;
263 const MCSection *SixteenByteConstantSection;
265 const MCSection *LazySymbolPointerSection;
266 const MCSection *NonLazySymbolPointerSection;
268 TargetLoweringObjectFileMachO() : UniquingMap(0) {}
269 ~TargetLoweringObjectFileMachO();
271 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
273 virtual const MCSection *
274 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
275 Mangler *Mang, const TargetMachine &TM) const;
277 virtual const MCSection *
278 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
279 Mangler *Mang, const TargetMachine &TM) const;
281 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
283 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
284 /// decide not to emit the UsedDirective for some symbols in llvm.used.
285 /// FIXME: REMOVE this (rdar://7071300)
286 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
289 /// getMachOSection - Return the MCSection for the specified mach-o section.
290 /// This requires the operands to be valid.
291 const MCSectionMachO *getMachOSection(StringRef Segment,
293 unsigned TypeAndAttributes,
294 SectionKind K) const {
295 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
297 const MCSectionMachO *getMachOSection(StringRef Segment,
299 unsigned TypeAndAttributes,
301 SectionKind K) const;
303 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
304 /// text symbols into.
305 const MCSection *getTextCoalSection() const {
306 return TextCoalSection;
309 /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
310 /// we put weak read-only symbols into.
311 const MCSection *getConstTextCoalSection() const {
312 return ConstTextCoalSection;
315 /// getLazySymbolPointerSection - Return the section corresponding to
316 /// the .lazy_symbol_pointer directive.
317 const MCSection *getLazySymbolPointerSection() const {
318 return LazySymbolPointerSection;
321 /// getNonLazySymbolPointerSection - Return the section corresponding to
322 /// the .non_lazy_symbol_pointer directive.
323 const MCSection *getNonLazySymbolPointerSection() const {
324 return NonLazySymbolPointerSection;
327 /// getSymbolForDwarfGlobalReference - The mach-o version of this method
328 /// defaults to returning a stub reference.
329 virtual const MCExpr *
330 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
331 MachineModuleInfo *MMI,
332 bool &IsIndirect, bool &IsPCRel) const;
337 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
338 mutable void *UniquingMap;
340 TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
341 ~TargetLoweringObjectFileCOFF();
343 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
345 virtual const MCSection *
346 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
347 Mangler *Mang, const TargetMachine &TM) const;
349 virtual const MCSection *
350 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
351 Mangler *Mang, const TargetMachine &TM) const;
353 /// getCOFFSection - Return the MCSection for the specified COFF section.
354 /// FIXME: Switch this to a semantic view eventually.
355 const MCSection *getCOFFSection(const char *Name, bool isDirective,
356 SectionKind K) const;
359 } // end namespace llvm