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 *DataCommonSection;
262 const MCSection *FourByteConstantSection;
263 const MCSection *EightByteConstantSection;
264 const MCSection *SixteenByteConstantSection;
266 const MCSection *LazySymbolPointerSection;
267 const MCSection *NonLazySymbolPointerSection;
269 TargetLoweringObjectFileMachO() : UniquingMap(0) {}
270 ~TargetLoweringObjectFileMachO();
272 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
274 virtual const MCSection *
275 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
276 Mangler *Mang, const TargetMachine &TM) const;
278 virtual const MCSection *
279 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
280 Mangler *Mang, const TargetMachine &TM) const;
282 virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
284 /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
285 /// decide not to emit the UsedDirective for some symbols in llvm.used.
286 /// FIXME: REMOVE this (rdar://7071300)
287 virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
290 /// getMachOSection - Return the MCSection for the specified mach-o section.
291 /// This requires the operands to be valid.
292 const MCSectionMachO *getMachOSection(StringRef Segment,
294 unsigned TypeAndAttributes,
295 SectionKind K) const {
296 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
298 const MCSectionMachO *getMachOSection(StringRef Segment,
300 unsigned TypeAndAttributes,
302 SectionKind K) const;
304 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
305 /// text symbols into.
306 const MCSection *getTextCoalSection() const {
307 return TextCoalSection;
310 /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
311 /// we put weak read-only symbols into.
312 const MCSection *getConstTextCoalSection() const {
313 return ConstTextCoalSection;
316 /// getDataCommonSection - Return the "__DATA,__common" section we put
317 /// zerofill (aka bss) data into.
318 bool isDataCommonSection(const MCSection *Section) const {
319 return Section == DataCommonSection;
322 /// getLazySymbolPointerSection - Return the section corresponding to
323 /// the .lazy_symbol_pointer directive.
324 const MCSection *getLazySymbolPointerSection() const {
325 return LazySymbolPointerSection;
328 /// getNonLazySymbolPointerSection - Return the section corresponding to
329 /// the .non_lazy_symbol_pointer directive.
330 const MCSection *getNonLazySymbolPointerSection() const {
331 return NonLazySymbolPointerSection;
334 /// getSymbolForDwarfGlobalReference - The mach-o version of this method
335 /// defaults to returning a stub reference.
336 virtual const MCExpr *
337 getSymbolForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
338 MachineModuleInfo *MMI,
339 bool &IsIndirect, bool &IsPCRel) const;
344 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
345 mutable void *UniquingMap;
347 TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
348 ~TargetLoweringObjectFileCOFF();
350 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
352 virtual const MCSection *
353 getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
354 Mangler *Mang, const TargetMachine &TM) const;
356 virtual const MCSection *
357 SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
358 Mangler *Mang, const TargetMachine &TM) const;
360 /// getCOFFSection - Return the MCSection for the specified COFF section.
361 /// FIXME: Switch this to a semantic view eventually.
362 const MCSection *getCOFFSection(StringRef Name, bool isDirective,
363 SectionKind K) const;
366 } // end namespace llvm