Add a method to return BSSSection from TargetLoweringObjectFile
[oota-llvm.git] / include / llvm / Target / TargetLoweringObjectFile.h
1 //===-- llvm/Target/TargetLoweringObjectFile.h - Object Info ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements classes used to handle lowerings specific to common
11 // object file formats.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
16 #define LLVM_TARGET_TARGETLOWERINGOBJECTFILE_H
17
18 #include "llvm/MC/SectionKind.h"
19
20 namespace llvm {
21   class Mangler;
22   class MCSection;
23   class MCSectionMachO;
24   class MCContext;
25   class GlobalValue;
26   class StringRef;
27   class TargetMachine;
28   class TargetAsmInfo;
29   
30 class TargetLoweringObjectFile {
31   MCContext *Ctx;
32   
33   TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
34   void operator=(const TargetLoweringObjectFile&);           // DO NOT IMPLEMENT
35 protected:
36   
37   TargetLoweringObjectFile();
38   
39   /// TextSection - Section directive for standard text.
40   ///
41   const MCSection *TextSection;
42   
43   /// DataSection - Section directive for standard data.
44   ///
45   const MCSection *DataSection;
46   
47   /// BSSSection - Section that is default initialized to zero.
48   const MCSection *BSSSection;
49   
50   /// ReadOnlySection - Section that is readonly and can contain arbitrary
51   /// initialized data.  Targets are not required to have a readonly section.
52   /// If they don't, various bits of code will fall back to using the data
53   /// section for constants.
54   const MCSection *ReadOnlySection;
55   
56   /// StaticCtorSection - This section contains the static constructor pointer
57   /// list.
58   const MCSection *StaticCtorSection;
59
60   /// StaticDtorSection - This section contains the static destructor pointer
61   /// list.
62   const MCSection *StaticDtorSection;
63   
64   /// LSDASection - If exception handling is supported by the target, this is
65   /// the section the Language Specific Data Area information is emitted to.
66   const MCSection *LSDASection;
67   
68   /// EHFrameSection - If exception handling is supported by the target, this is
69   /// the section the EH Frame is emitted to.
70   const MCSection *EHFrameSection;
71   
72   // Dwarf sections for debug info.  If a target supports debug info, these must
73   // be set.
74   const MCSection *DwarfAbbrevSection;
75   const MCSection *DwarfInfoSection;
76   const MCSection *DwarfLineSection;
77   const MCSection *DwarfFrameSection;
78   const MCSection *DwarfPubNamesSection;
79   const MCSection *DwarfPubTypesSection;
80   const MCSection *DwarfDebugInlineSection;
81   const MCSection *DwarfStrSection;
82   const MCSection *DwarfLocSection;
83   const MCSection *DwarfARangesSection;
84   const MCSection *DwarfRangesSection;
85   const MCSection *DwarfMacroInfoSection;
86   
87 public:
88   
89   MCContext &getContext() const { return *Ctx; }
90   
91
92   virtual ~TargetLoweringObjectFile();
93   
94   /// Initialize - this method must be called before any actual lowering is
95   /// done.  This specifies the current context for codegen, and gives the
96   /// lowering implementations a chance to set up their default sections.
97   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
98     Ctx = &ctx;
99   }
100   
101   
102   const MCSection *getTextSection() const { return TextSection; }
103   const MCSection *getDataSection() const { return DataSection; }
104   const MCSection *getBSSSection() const { return BSSSection; }
105   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
106   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
107   const MCSection *getLSDASection() const { return LSDASection; }
108   const MCSection *getEHFrameSection() const { return EHFrameSection; }
109   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
110   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
111   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
112   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
113   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
114   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
115   const MCSection *getDwarfDebugInlineSection() const {
116     return DwarfDebugInlineSection;
117   }
118   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
119   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
120   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
121   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
122   const MCSection *getDwarfMacroInfoSection() const {
123     return DwarfMacroInfoSection;
124   }
125   
126   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
127   /// decide not to emit the UsedDirective for some symbols in llvm.used.
128   /// FIXME: REMOVE this (rdar://7071300)
129   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
130                                           Mangler *) const {
131     return GV != 0;
132   }
133   
134   /// getSectionForConstant - Given a constant with the SectionKind, return a
135   /// section that it should be placed in.
136   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
137   
138   /// getKindForGlobal - Classify the specified global variable into a set of
139   /// target independent categories embodied in SectionKind.
140   static SectionKind getKindForGlobal(const GlobalValue *GV,
141                                       const TargetMachine &TM);
142   
143   /// SectionForGlobal - This method computes the appropriate section to emit
144   /// the specified global variable or function definition.  This should not
145   /// be passed external (or available externally) globals.
146   const MCSection *SectionForGlobal(const GlobalValue *GV,
147                                     SectionKind Kind, Mangler *Mang,
148                                     const TargetMachine &TM) const;
149   
150   /// SectionForGlobal - This method computes the appropriate section to emit
151   /// the specified global variable or function definition.  This should not
152   /// be passed external (or available externally) globals.
153   const MCSection *SectionForGlobal(const GlobalValue *GV,
154                                     Mangler *Mang,
155                                     const TargetMachine &TM) const {
156     return SectionForGlobal(GV, getKindForGlobal(GV, TM), Mang, TM);
157   }
158   
159   
160   
161   /// getExplicitSectionGlobal - Targets should implement this method to assign
162   /// a section to globals with an explicit section specfied.  The
163   /// implementation of this method can assume that GV->hasSection() is true.
164   virtual const MCSection *
165   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
166                            Mangler *Mang, const TargetMachine &TM) const = 0;
167   
168   /// getSpecialCasedSectionGlobals - Allow the target to completely override
169   /// section assignment of a global.
170   virtual const MCSection *
171   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
172                                 SectionKind Kind) const {
173     return 0;
174   }
175   
176 protected:
177   virtual const MCSection *
178   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
179                          Mangler *Mang, const TargetMachine &TM) const;
180 };
181   
182   
183   
184
185 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
186   bool HasCrazyBSS;
187   mutable void *UniquingMap;
188 protected:
189   /// TLSDataSection - Section directive for Thread Local data.
190   ///
191   const MCSection *TLSDataSection;        // Defaults to ".tdata".
192   
193   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
194   /// Null if this target doesn't support a BSS section.
195   ///
196   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
197   
198   const MCSection *DataRelSection;
199   const MCSection *DataRelLocalSection;
200   const MCSection *DataRelROSection;
201   const MCSection *DataRelROLocalSection;
202   
203   const MCSection *MergeableConst4Section;
204   const MCSection *MergeableConst8Section;
205   const MCSection *MergeableConst16Section;
206   
207 protected:
208   const MCSection *getELFSection(StringRef Section, unsigned Type, 
209                                  unsigned Flags, SectionKind Kind,
210                                  bool IsExplicit = false) const;
211 public:
212   TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
213                               bool hasCrazyBSS = false)
214     : HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {}
215   
216   ~TargetLoweringObjectFileELF();
217   
218   
219   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
220   
221   /// getSectionForConstant - Given a constant with the SectionKind, return a
222   /// section that it should be placed in.
223   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
224   
225   
226   virtual const MCSection *
227   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
228                            Mangler *Mang, const TargetMachine &TM) const;
229   
230   virtual const MCSection *
231   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
232                          Mangler *Mang, const TargetMachine &TM) const;
233 };
234
235   
236   
237 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
238   mutable void *UniquingMap;
239   
240   const MCSection *CStringSection;
241   const MCSection *UStringSection;
242   const MCSection *TextCoalSection;
243   const MCSection *ConstTextCoalSection;
244   const MCSection *ConstDataCoalSection;
245   const MCSection *ConstDataSection;
246   const MCSection *DataCoalSection;
247   const MCSection *FourByteConstantSection;
248   const MCSection *EightByteConstantSection;
249   const MCSection *SixteenByteConstantSection;
250   
251   const MCSection *LazySymbolPointerSection;
252   const MCSection *NonLazySymbolPointerSection;
253 public:
254   TargetLoweringObjectFileMachO() : UniquingMap(0) {}
255   ~TargetLoweringObjectFileMachO();
256   
257   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
258
259   virtual const MCSection *
260   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
261                          Mangler *Mang, const TargetMachine &TM) const;
262   
263   virtual const MCSection *
264   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
265                            Mangler *Mang, const TargetMachine &TM) const;
266   
267   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
268   
269   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
270   /// decide not to emit the UsedDirective for some symbols in llvm.used.
271   /// FIXME: REMOVE this (rdar://7071300)
272   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
273                                           Mangler *) const;
274
275   /// getMachOSection - Return the MCSection for the specified mach-o section.
276   /// This requires the operands to be valid.
277   const MCSectionMachO *getMachOSection(const StringRef &Segment,
278                                         const StringRef &Section,
279                                         unsigned TypeAndAttributes,
280                                         SectionKind K) const {
281     return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
282   }
283   const MCSectionMachO *getMachOSection(const StringRef &Segment,
284                                         const StringRef &Section,
285                                         unsigned TypeAndAttributes,
286                                         unsigned Reserved2,
287                                         SectionKind K) const;
288
289   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
290   /// symbols into.
291   const MCSection *getTextCoalSection() const {
292     return TextCoalSection;
293   }
294   
295   /// getLazySymbolPointerSection - Return the section corresponding to
296   /// the .lazy_symbol_pointer directive.
297   const MCSection *getLazySymbolPointerSection() const {
298     return LazySymbolPointerSection;
299   }
300   
301   /// getNonLazySymbolPointerSection - Return the section corresponding to
302   /// the .non_lazy_symbol_pointer directive.
303   const MCSection *getNonLazySymbolPointerSection() const {
304     return NonLazySymbolPointerSection;
305   }
306 };
307
308
309
310 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
311   mutable void *UniquingMap;
312 public:
313   TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
314   ~TargetLoweringObjectFileCOFF();
315   
316   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
317   
318   virtual const MCSection *
319   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind, 
320                            Mangler *Mang, const TargetMachine &TM) const;
321   
322   virtual const MCSection *
323   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
324                          Mangler *Mang, const TargetMachine &TM) const;
325
326   /// getCOFFSection - Return the MCSection for the specified COFF section.
327   /// FIXME: Switch this to a semantic view eventually.
328   const MCSection *getCOFFSection(const char *Name, bool isDirective,
329                                   SectionKind K) const;
330 };
331
332 } // end namespace llvm
333
334 #endif