convert ctors/dtors section to be in TLOF instead of
[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/ADT/SmallVector.h"
19 #include "llvm/ADT/StringMap.h"
20 #include "llvm/MC/SectionKind.h"
21
22 namespace llvm {
23   class MCSection;
24   class MCContext;
25   class GlobalValue;
26   class Mangler;
27   class TargetMachine;
28   
29  
30 class TargetLoweringObjectFile {
31   MCContext *Ctx;
32 protected:
33   
34   TargetLoweringObjectFile();
35   
36   /// TextSection - Section directive for standard text.
37   ///
38   const MCSection *TextSection;
39   
40   /// DataSection - Section directive for standard data.
41   ///
42   const MCSection *DataSection;
43   
44   /// BSSSection - Section that is default initialized to zero.
45   const MCSection *BSSSection;
46   
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;
52   
53   /// StaticCtorSection - This section contains the static constructor pointer
54   /// list.
55   const MCSection *StaticCtorSection;
56
57   /// StaticDtorSection - This section contains the static destructor pointer
58   /// list.
59   const MCSection *StaticDtorSection;
60   
61 public:
62   // FIXME: NONPUB.
63   const MCSection *getOrCreateSection(const char *Name,
64                                       bool isDirective,
65                                       SectionKind K) const;
66 public:
67   
68   virtual ~TargetLoweringObjectFile();
69   
70   /// Initialize - this method must be called before any actual lowering is
71   /// done.  This specifies the current context for codegen, and gives the
72   /// lowering implementations a chance to set up their default sections.
73   virtual void Initialize(MCContext &ctx, const TargetMachine &TM) {
74     Ctx = &ctx;
75   }
76   
77   
78   const MCSection *getTextSection() const { return TextSection; }
79   const MCSection *getDataSection() const { return DataSection; }
80
81   const MCSection *getStaticCtorSection() const { return StaticCtorSection; }
82   const MCSection *getStaticDtorSection() const { return StaticDtorSection; }
83
84   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
85   /// decide not to emit the UsedDirective for some symbols in llvm.used.
86   /// FIXME: REMOVE this (rdar://7071300)
87   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
88                                           Mangler *) const {
89     return GV != 0;
90   }
91   
92   /// getSectionForConstant - Given a constant with the SectionKind, return a
93   /// section that it should be placed in.
94   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
95   
96   /// getKindForNamedSection - If this target wants to be able to override
97   /// section flags based on the name of the section specified for a global
98   /// variable, it can implement this.  This is used on ELF systems so that
99   /// ".tbss" gets the TLS bit set etc.
100   virtual SectionKind getKindForNamedSection(const char *Section,
101                                              SectionKind K) const {
102     return K;
103   }
104   
105   /// SectionForGlobal - This method computes the appropriate section to emit
106   /// the specified global variable or function definition.  This should not
107   /// be passed external (or available externally) globals.
108   const MCSection *SectionForGlobal(const GlobalValue *GV,
109                                     Mangler *Mang,
110                                     const TargetMachine &TM) const;
111   
112   /// getSpecialCasedSectionGlobals - Allow the target to completely override
113   /// section assignment of a global.
114   /// FIXME: ELIMINATE this by making PIC16 implement ADDRESS with
115   /// getFlagsForNamedSection.
116   virtual const MCSection *
117   getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
118                                 SectionKind Kind) const {
119     return 0;
120   }
121   
122   /// getSectionFlagsAsString - Turn the flags in the specified SectionKind
123   /// into a string that can be printed to the assembly file after the
124   /// ".section foo" part of a section directive.
125   virtual void getSectionFlagsAsString(SectionKind Kind,
126                                        SmallVectorImpl<char> &Str) const {
127   }
128   
129 protected:
130   virtual const MCSection *
131   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
132                          Mangler *Mang, const TargetMachine &TM) const;
133 };
134   
135   
136   
137
138 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
139   bool AtIsCommentChar;  // True if @ is the comment character on this target.
140   bool HasCrazyBSS;
141 protected:
142   /// TLSDataSection - Section directive for Thread Local data.
143   ///
144   const MCSection *TLSDataSection;        // Defaults to ".tdata".
145   
146   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
147   /// Null if this target doesn't support a BSS section.
148   ///
149   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
150   
151   const MCSection *CStringSection;
152   
153   const MCSection *DataRelSection;
154   const MCSection *DataRelLocalSection;
155   const MCSection *DataRelROSection;
156   const MCSection *DataRelROLocalSection;
157   
158   const MCSection *MergeableConst4Section;
159   const MCSection *MergeableConst8Section;
160   const MCSection *MergeableConst16Section;
161 public:
162   /// ELF Constructor - AtIsCommentChar is true if the CommentCharacter from TAI
163   /// is "@".
164   TargetLoweringObjectFileELF(bool atIsCommentChar = false,
165                               // FIXME: REMOVE AFTER UNIQUING IS FIXED.
166                               bool hasCrazyBSS = false)
167     : AtIsCommentChar(atIsCommentChar), HasCrazyBSS(hasCrazyBSS) {}
168     
169   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
170   
171   
172   /// getSectionForConstant - Given a constant with the SectionKind, return a
173   /// section that it should be placed in.
174   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
175   
176   virtual SectionKind getKindForNamedSection(const char *Section,
177                                              SectionKind K) const;
178   void getSectionFlagsAsString(SectionKind Kind,
179                                SmallVectorImpl<char> &Str) const;
180   
181   virtual const MCSection *
182   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
183                          Mangler *Mang, const TargetMachine &TM) const;
184 };
185
186   
187   
188 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
189   const MCSection *CStringSection;
190   const MCSection *TextCoalSection;
191   const MCSection *ConstTextCoalSection;
192   const MCSection *ConstDataCoalSection;
193   const MCSection *ConstDataSection;
194   const MCSection *DataCoalSection;
195   const MCSection *FourByteConstantSection;
196   const MCSection *EightByteConstantSection;
197   const MCSection *SixteenByteConstantSection;
198 public:
199   
200   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
201
202   virtual const MCSection *
203   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
204                          Mangler *Mang, const TargetMachine &TM) const;
205   
206   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
207   
208   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
209   /// decide not to emit the UsedDirective for some symbols in llvm.used.
210   /// FIXME: REMOVE this (rdar://7071300)
211   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
212                                           Mangler *) const;
213 };
214
215
216
217 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
218 public:
219   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
220   
221   virtual void getSectionFlagsAsString(SectionKind Kind,
222                                        SmallVectorImpl<char> &Str) const;
223   
224   virtual const MCSection *
225   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
226                          Mangler *Mang, const TargetMachine &TM) const;
227 };
228
229 } // end namespace llvm
230
231 #endif