Add .pdata and .xdata sections to the COFF TLOF implementation.
[oota-llvm.git] / include / llvm / CodeGen / TargetLoweringObjectFileImpl.h
1 //==-- llvm/CodeGen/TargetLoweringObjectFileImpl.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_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
16 #define LLVM_CODEGEN_TARGETLOWERINGOBJECTFILEIMPL_H
17
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/SectionKind.h"
20 #include "llvm/Target/TargetLoweringObjectFile.h"
21
22 namespace llvm {
23   class MachineModuleInfo;
24   class Mangler;
25   class MCAsmInfo;
26   class MCExpr;
27   class MCSection;
28   class MCSectionMachO;
29   class MCSymbol;
30   class MCContext;
31   class GlobalValue;
32   class TargetMachine;
33
34
35 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
36 protected:
37   /// TLSDataSection - Section directive for Thread Local data.
38   ///
39   const MCSection *TLSDataSection;        // Defaults to ".tdata".
40
41   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
42   /// Null if this target doesn't support a BSS section.
43   ///
44   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
45
46   const MCSection *DataRelSection;
47   const MCSection *DataRelLocalSection;
48   const MCSection *DataRelROSection;
49   const MCSection *DataRelROLocalSection;
50
51   const MCSection *MergeableConst4Section;
52   const MCSection *MergeableConst8Section;
53   const MCSection *MergeableConst16Section;
54 public:
55   TargetLoweringObjectFileELF() {}
56   ~TargetLoweringObjectFileELF() {}
57
58   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
59
60   virtual const MCSection *getEHFrameSection() const;
61   virtual const MCSection *getWin64EHFuncTableSection() const { return NULL; }
62   virtual const MCSection *getWin64EHTableSection() const { return NULL; }
63
64   virtual void emitPersonalityValue(MCStreamer &Streamer,
65                                     const TargetMachine &TM,
66                                     const MCSymbol *Sym) const;
67
68   const MCSection *getDataRelSection() const { return DataRelSection; }
69
70   /// getSectionForConstant - Given a constant with the SectionKind, return a
71   /// section that it should be placed in.
72   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
73
74
75   virtual const MCSection *
76   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
77                            Mangler *Mang, const TargetMachine &TM) const;
78
79   virtual const MCSection *
80   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
81                          Mangler *Mang, const TargetMachine &TM) const;
82
83   /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
84   /// to the specified global variable from exception handling information.
85   ///
86   virtual const MCExpr *
87   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
88                                  MachineModuleInfo *MMI, unsigned Encoding,
89                                  MCStreamer &Streamer) const;
90
91   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
92   virtual MCSymbol *
93   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
94                           MachineModuleInfo *MMI) const;
95 };
96
97
98
99 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
100   /// TLSDataSection - Section for thread local data.
101   ///
102   const MCSection *TLSDataSection;        // Defaults to ".tdata".
103
104   /// TLSBSSSection - Section for thread local uninitialized data.
105   ///
106   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
107   
108   /// TLSTLVSection - Section for thread local structure information.
109   /// Contains the source code name of the variable, visibility and a pointer
110   /// to the initial value (.tdata or .tbss).
111   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
112   
113   /// TLSThreadInitSection - Section for thread local data initialization
114   /// functions.
115   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
116   
117   const MCSection *CStringSection;
118   const MCSection *UStringSection;
119   const MCSection *TextCoalSection;
120   const MCSection *ConstTextCoalSection;
121   const MCSection *ConstDataSection;
122   const MCSection *DataCoalSection;
123   const MCSection *DataCommonSection;
124   const MCSection *DataBSSSection;
125   const MCSection *FourByteConstantSection;
126   const MCSection *EightByteConstantSection;
127   const MCSection *SixteenByteConstantSection;
128
129   const MCSection *LazySymbolPointerSection;
130   const MCSection *NonLazySymbolPointerSection;
131 public:
132   TargetLoweringObjectFileMachO() {}
133   ~TargetLoweringObjectFileMachO() {}
134
135   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
136
137   virtual const MCSection *getEHFrameSection() const;
138   virtual const MCSection *getWin64EHFuncTableSection() const { return NULL; }
139   virtual const MCSection *getWin64EHTableSection() const { return NULL; }
140
141   virtual const MCSection *
142   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
143                          Mangler *Mang, const TargetMachine &TM) const;
144
145   virtual const MCSection *
146   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
147                            Mangler *Mang, const TargetMachine &TM) const;
148
149   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
150
151   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
152   /// decide not to emit the UsedDirective for some symbols in llvm.used.
153   /// FIXME: REMOVE this (rdar://7071300)
154   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
155                                           Mangler *) const;
156
157   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
158   /// text symbols into.
159   const MCSection *getTextCoalSection() const {
160     return TextCoalSection;
161   }
162
163   /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
164   /// we put weak read-only symbols into.
165   const MCSection *getConstTextCoalSection() const {
166     return ConstTextCoalSection;
167   }
168
169   /// getLazySymbolPointerSection - Return the section corresponding to
170   /// the .lazy_symbol_pointer directive.
171   const MCSection *getLazySymbolPointerSection() const {
172     return LazySymbolPointerSection;
173   }
174
175   /// getNonLazySymbolPointerSection - Return the section corresponding to
176   /// the .non_lazy_symbol_pointer directive.
177   const MCSection *getNonLazySymbolPointerSection() const {
178     return NonLazySymbolPointerSection;
179   }
180
181   /// getExprForDwarfGlobalReference - The mach-o version of this method
182   /// defaults to returning a stub reference.
183   virtual const MCExpr *
184   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
185                                  MachineModuleInfo *MMI, unsigned Encoding,
186                                  MCStreamer &Streamer) const;
187
188   // getCFIPersonalitySymbol - The symbol that gets passed to .cfi_personality.
189   virtual MCSymbol *
190   getCFIPersonalitySymbol(const GlobalValue *GV, Mangler *Mang,
191                           MachineModuleInfo *MMI) const;
192
193   virtual unsigned getPersonalityEncoding() const;
194   virtual unsigned getLSDAEncoding() const;
195   virtual unsigned getFDEEncoding(bool CFI) const;
196   virtual unsigned getTTypeEncoding() const;
197 };
198
199
200
201 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
202   const MCSection *DrectveSection;
203   const MCSection *PDataSection;
204   const MCSection *XDataSection;
205 public:
206   TargetLoweringObjectFileCOFF() {}
207   ~TargetLoweringObjectFileCOFF() {}
208
209   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
210
211   virtual const MCSection *getEHFrameSection() const;
212   virtual const MCSection *getWin64EHFuncTableSection() const {
213     return PDataSection;
214   }
215   virtual const MCSection *getWin64EHTableSection() const {return XDataSection;}
216
217   virtual const MCSection *getDrectveSection() const { return DrectveSection; }
218
219   virtual const MCSection *
220   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
221                            Mangler *Mang, const TargetMachine &TM) const;
222
223   virtual const MCSection *
224   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
225                          Mangler *Mang, const TargetMachine &TM) const;
226 };
227
228 } // end namespace llvm
229
230 #endif