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:
TargetLoweringObjectFileELF()55   TargetLoweringObjectFileELF() {}
~TargetLoweringObjectFileELF()56   ~TargetLoweringObjectFileELF() {}
57 
58   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
59 
getDataRelSection()60   const MCSection *getDataRelSection() const { return DataRelSection; }
61 
62   /// getSectionForConstant - Given a constant with the SectionKind, return a
63   /// section that it should be placed in.
64   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
65 
66 
67   virtual const MCSection *
68   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
69                            Mangler *Mang, const TargetMachine &TM) const;
70 
71   virtual const MCSection *
72   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
73                          Mangler *Mang, const TargetMachine &TM) const;
74 
75   /// getExprForDwarfGlobalReference - Return an MCExpr to use for a reference
76   /// to the specified global variable from exception handling information.
77   ///
78   virtual const MCExpr *
79   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
80                                  MachineModuleInfo *MMI, unsigned Encoding,
81                                  MCStreamer &Streamer) const;
82 };
83 
84 
85 
86 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
87   /// TLSDataSection - Section for thread local data.
88   ///
89   const MCSection *TLSDataSection;        // Defaults to ".tdata".
90 
91   /// TLSBSSSection - Section for thread local uninitialized data.
92   ///
93   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
94 
95   /// TLSTLVSection - Section for thread local structure infomation.
96   /// Contains the source code name of the variable, visibility and a pointer
97   /// to the initial value (.tdata or .tbss).
98   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
99 
100   /// TLSThreadInitSection - Section for thread local data initialization
101   /// functions.
102   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
103 
104   const MCSection *CStringSection;
105   const MCSection *UStringSection;
106   const MCSection *TextCoalSection;
107   const MCSection *ConstTextCoalSection;
108   const MCSection *ConstDataSection;
109   const MCSection *DataCoalSection;
110   const MCSection *DataCommonSection;
111   const MCSection *DataBSSSection;
112   const MCSection *FourByteConstantSection;
113   const MCSection *EightByteConstantSection;
114   const MCSection *SixteenByteConstantSection;
115 
116   const MCSection *LazySymbolPointerSection;
117   const MCSection *NonLazySymbolPointerSection;
118 public:
TargetLoweringObjectFileMachO()119   TargetLoweringObjectFileMachO() {}
~TargetLoweringObjectFileMachO()120   ~TargetLoweringObjectFileMachO() {}
121 
122   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
123 
124   virtual const MCSection *
125   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
126                          Mangler *Mang, const TargetMachine &TM) const;
127 
128   virtual const MCSection *
129   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
130                            Mangler *Mang, const TargetMachine &TM) const;
131 
132   virtual const MCSection *getSectionForConstant(SectionKind Kind) const;
133 
134   /// shouldEmitUsedDirectiveFor - This hook allows targets to selectively
135   /// decide not to emit the UsedDirective for some symbols in llvm.used.
136   /// FIXME: REMOVE this (rdar://7071300)
137   virtual bool shouldEmitUsedDirectiveFor(const GlobalValue *GV,
138                                           Mangler *) const;
139 
140   /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
141   /// text symbols into.
getTextCoalSection()142   const MCSection *getTextCoalSection() const {
143     return TextCoalSection;
144   }
145 
146   /// getConstTextCoalSection - Return the "__TEXT,__const_coal" section
147   /// we put weak read-only symbols into.
getConstTextCoalSection()148   const MCSection *getConstTextCoalSection() const {
149     return ConstTextCoalSection;
150   }
151 
152   /// getLazySymbolPointerSection - Return the section corresponding to
153   /// the .lazy_symbol_pointer directive.
getLazySymbolPointerSection()154   const MCSection *getLazySymbolPointerSection() const {
155     return LazySymbolPointerSection;
156   }
157 
158   /// getNonLazySymbolPointerSection - Return the section corresponding to
159   /// the .non_lazy_symbol_pointer directive.
getNonLazySymbolPointerSection()160   const MCSection *getNonLazySymbolPointerSection() const {
161     return NonLazySymbolPointerSection;
162   }
163 
164   /// getExprForDwarfGlobalReference - The mach-o version of this method
165   /// defaults to returning a stub reference.
166   virtual const MCExpr *
167   getExprForDwarfGlobalReference(const GlobalValue *GV, Mangler *Mang,
168                                  MachineModuleInfo *MMI, unsigned Encoding,
169                                  MCStreamer &Streamer) const;
170 
171   virtual unsigned getPersonalityEncoding() const;
172   virtual unsigned getLSDAEncoding() const;
173   virtual unsigned getFDEEncoding() const;
174   virtual unsigned getTTypeEncoding() const;
175 };
176 
177 
178 
179 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
180   const MCSection *DrectveSection;
181 public:
TargetLoweringObjectFileCOFF()182   TargetLoweringObjectFileCOFF() {}
~TargetLoweringObjectFileCOFF()183   ~TargetLoweringObjectFileCOFF() {}
184 
185   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
186 
getDrectveSection()187   virtual const MCSection *getDrectveSection() const { return DrectveSection; }
188 
189   virtual const MCSection *
190   getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
191                            Mangler *Mang, const TargetMachine &TM) const;
192 
193   virtual const MCSection *
194   SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
195                          Mangler *Mang, const TargetMachine &TM) const;
196 };
197 
198 } // end namespace llvm
199 
200 #endif
201