1 //===-- llvm/MC/MCObjectFileInfo.h - Object File 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 describes common object file formats.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MC_MCOBJECTFILEINFO_H
15 #define LLVM_MC_MCOBJECTFILEINFO_H
16 
17 #include "llvm/ADT/Triple.h"
18 #include "llvm/Support/CodeGen.h"
19 
20 namespace llvm {
21   class MCContext;
22   class MCSection;
23   class StringRef;
24 
25 class MCObjectFileInfo {
26 protected:
27   /// CommDirectiveSupportsAlignment - True if .comm supports alignment.  This
28   /// is a hack for as long as we support 10.4 Tiger, whose assembler doesn't
29   /// support alignment on comm.
30   bool CommDirectiveSupportsAlignment;
31 
32   /// SupportsWeakEmptyEHFrame - True if target object file supports a
33   /// weak_definition of constant 0 for an omitted EH frame.
34   bool SupportsWeakOmittedEHFrame;
35 
36   /// SupportsCompactUnwindWithoutEHFrame - True if the target object file
37   /// supports emitting a compact unwind section without an associated EH frame
38   /// section.
39   bool SupportsCompactUnwindWithoutEHFrame;
40 
41   /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
42   /// for EH.
43   unsigned PersonalityEncoding;
44   unsigned LSDAEncoding;
45   unsigned FDECFIEncoding;
46   unsigned TTypeEncoding;
47 
48   /// Section flags for eh_frame
49   unsigned EHSectionType;
50   unsigned EHSectionFlags;
51 
52   /// CompactUnwindDwarfEHFrameOnly - Compact unwind encoding indicating that we
53   /// should emit only an EH frame.
54   unsigned CompactUnwindDwarfEHFrameOnly;
55 
56   /// TextSection - Section directive for standard text.
57   ///
58   const MCSection *TextSection;
59 
60   /// DataSection - Section directive for standard data.
61   ///
62   const MCSection *DataSection;
63 
64   /// BSSSection - Section that is default initialized to zero.
65   const MCSection *BSSSection;
66 
67   /// ReadOnlySection - Section that is readonly and can contain arbitrary
68   /// initialized data.  Targets are not required to have a readonly section.
69   /// If they don't, various bits of code will fall back to using the data
70   /// section for constants.
71   const MCSection *ReadOnlySection;
72 
73   /// StaticCtorSection - This section contains the static constructor pointer
74   /// list.
75   const MCSection *StaticCtorSection;
76 
77   /// StaticDtorSection - This section contains the static destructor pointer
78   /// list.
79   const MCSection *StaticDtorSection;
80 
81   /// LSDASection - If exception handling is supported by the target, this is
82   /// the section the Language Specific Data Area information is emitted to.
83   const MCSection *LSDASection;
84 
85   /// CompactUnwindSection - If exception handling is supported by the target
86   /// and the target can support a compact representation of the CIE and FDE,
87   /// this is the section to emit them into.
88   const MCSection *CompactUnwindSection;
89 
90   // Dwarf sections for debug info.  If a target supports debug info, these must
91   // be set.
92   const MCSection *DwarfAbbrevSection;
93   const MCSection *DwarfInfoSection;
94   const MCSection *DwarfLineSection;
95   const MCSection *DwarfFrameSection;
96   const MCSection *DwarfPubTypesSection;
97   const MCSection *DwarfDebugInlineSection;
98   const MCSection *DwarfStrSection;
99   const MCSection *DwarfLocSection;
100   const MCSection *DwarfARangesSection;
101   const MCSection *DwarfRangesSection;
102   const MCSection *DwarfMacroInfoSection;
103   // The pubnames section is no longer generated by default.  The generation
104   // can be enabled by a compiler flag.
105   const MCSection *DwarfPubNamesSection;
106 
107   // DWARF5 Experimental Debug Info Sections
108   /// DwarfAccelNamesSection, DwarfAccelObjCSection,
109   /// DwarfAccelNamespaceSection, DwarfAccelTypesSection -
110   /// If we use the DWARF accelerated hash tables then we want to emit these
111   /// sections.
112   const MCSection *DwarfAccelNamesSection;
113   const MCSection *DwarfAccelObjCSection;
114   const MCSection *DwarfAccelNamespaceSection;
115   const MCSection *DwarfAccelTypesSection;
116 
117   /// These are used for the Fission separate debug information files.
118   const MCSection *DwarfInfoDWOSection;
119   const MCSection *DwarfTypesDWOSection;
120   const MCSection *DwarfAbbrevDWOSection;
121   const MCSection *DwarfStrDWOSection;
122   const MCSection *DwarfLineDWOSection;
123   const MCSection *DwarfLocDWOSection;
124   const MCSection *DwarfStrOffDWOSection;
125   const MCSection *DwarfAddrSection;
126 
127   /// Sections for newer gnu pubnames and pubtypes.
128   const MCSection *DwarfGnuPubNamesSection;
129   const MCSection *DwarfGnuPubTypesSection;
130 
131   const MCSection *COFFDebugSymbolsSection;
132 
133   // Extra TLS Variable Data section.  If the target needs to put additional
134   // information for a TLS variable, it'll go here.
135   const MCSection *TLSExtraDataSection;
136 
137   /// TLSDataSection - Section directive for Thread Local data.
138   /// ELF, MachO and COFF.
139   const MCSection *TLSDataSection;        // Defaults to ".tdata".
140 
141   /// TLSBSSSection - Section directive for Thread Local uninitialized data.
142   /// Null if this target doesn't support a BSS section.
143   /// ELF and MachO only.
144   const MCSection *TLSBSSSection;         // Defaults to ".tbss".
145 
146   /// StackMap section.
147   const MCSection *StackMapSection;
148 
149   /// EHFrameSection - EH frame section. It is initialized on demand so it
150   /// can be overwritten (with uniquing).
151   const MCSection *EHFrameSection;
152 
153   /// ELF specific sections.
154   ///
155   const MCSection *DataRelSection;
156   const MCSection *DataRelLocalSection;
157   const MCSection *DataRelROSection;
158   const MCSection *DataRelROLocalSection;
159   const MCSection *MergeableConst4Section;
160   const MCSection *MergeableConst8Section;
161   const MCSection *MergeableConst16Section;
162 
163   /// MachO specific sections.
164   ///
165 
166   /// TLSTLVSection - Section for thread local structure information.
167   /// Contains the source code name of the variable, visibility and a pointer
168   /// to the initial value (.tdata or .tbss).
169   const MCSection *TLSTLVSection;         // Defaults to ".tlv".
170 
171   /// TLSThreadInitSection - Section for thread local data initialization
172   /// functions.
173   const MCSection *TLSThreadInitSection;  // Defaults to ".thread_init_func".
174 
175   const MCSection *CStringSection;
176   const MCSection *UStringSection;
177   const MCSection *TextCoalSection;
178   const MCSection *ConstTextCoalSection;
179   const MCSection *ConstDataSection;
180   const MCSection *DataCoalSection;
181   const MCSection *DataCommonSection;
182   const MCSection *DataBSSSection;
183   const MCSection *FourByteConstantSection;
184   const MCSection *EightByteConstantSection;
185   const MCSection *SixteenByteConstantSection;
186   const MCSection *LazySymbolPointerSection;
187   const MCSection *NonLazySymbolPointerSection;
188 
189   /// COFF specific sections.
190   ///
191   const MCSection *DrectveSection;
192   const MCSection *PDataSection;
193   const MCSection *XDataSection;
194 
195 public:
196   void InitMCObjectFileInfo(StringRef TT, Reloc::Model RM, CodeModel::Model CM,
197                             MCContext &ctx);
198 
getSupportsWeakOmittedEHFrame()199   bool getSupportsWeakOmittedEHFrame() const {
200     return SupportsWeakOmittedEHFrame;
201   }
getSupportsCompactUnwindWithoutEHFrame()202   bool getSupportsCompactUnwindWithoutEHFrame() const {
203     return SupportsCompactUnwindWithoutEHFrame;
204   }
getCommDirectiveSupportsAlignment()205   bool getCommDirectiveSupportsAlignment() const {
206     return CommDirectiveSupportsAlignment;
207   }
208 
getPersonalityEncoding()209   unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
getLSDAEncoding()210   unsigned getLSDAEncoding() const { return LSDAEncoding; }
getFDEEncoding()211   unsigned getFDEEncoding() const { return FDECFIEncoding; }
getTTypeEncoding()212   unsigned getTTypeEncoding() const { return TTypeEncoding; }
213 
getCompactUnwindDwarfEHFrameOnly()214   unsigned getCompactUnwindDwarfEHFrameOnly() const {
215     return CompactUnwindDwarfEHFrameOnly;
216   }
217 
getTextSection()218   const MCSection *getTextSection() const { return TextSection; }
getDataSection()219   const MCSection *getDataSection() const { return DataSection; }
getBSSSection()220   const MCSection *getBSSSection() const { return BSSSection; }
getLSDASection()221   const MCSection *getLSDASection() const { return LSDASection; }
getCompactUnwindSection()222   const MCSection *getCompactUnwindSection() const{
223     return CompactUnwindSection;
224   }
getDwarfAbbrevSection()225   const MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
getDwarfInfoSection()226   const MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
getDwarfLineSection()227   const MCSection *getDwarfLineSection() const { return DwarfLineSection; }
getDwarfFrameSection()228   const MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
getDwarfPubNamesSection()229   const MCSection *getDwarfPubNamesSection() const{return DwarfPubNamesSection;}
getDwarfPubTypesSection()230   const MCSection *getDwarfPubTypesSection() const{return DwarfPubTypesSection;}
getDwarfGnuPubNamesSection()231   const MCSection *getDwarfGnuPubNamesSection() const {
232     return DwarfGnuPubNamesSection;
233   }
getDwarfGnuPubTypesSection()234   const MCSection *getDwarfGnuPubTypesSection() const {
235     return DwarfGnuPubTypesSection;
236   }
getDwarfDebugInlineSection()237   const MCSection *getDwarfDebugInlineSection() const {
238     return DwarfDebugInlineSection;
239   }
getDwarfStrSection()240   const MCSection *getDwarfStrSection() const { return DwarfStrSection; }
getDwarfLocSection()241   const MCSection *getDwarfLocSection() const { return DwarfLocSection; }
getDwarfARangesSection()242   const MCSection *getDwarfARangesSection() const { return DwarfARangesSection;}
getDwarfRangesSection()243   const MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
getDwarfMacroInfoSection()244   const MCSection *getDwarfMacroInfoSection() const {
245     return DwarfMacroInfoSection;
246   }
247 
248   // DWARF5 Experimental Debug Info Sections
getDwarfAccelNamesSection()249   const MCSection *getDwarfAccelNamesSection() const {
250     return DwarfAccelNamesSection;
251   }
getDwarfAccelObjCSection()252   const MCSection *getDwarfAccelObjCSection() const {
253     return DwarfAccelObjCSection;
254   }
getDwarfAccelNamespaceSection()255   const MCSection *getDwarfAccelNamespaceSection() const {
256     return DwarfAccelNamespaceSection;
257   }
getDwarfAccelTypesSection()258   const MCSection *getDwarfAccelTypesSection() const {
259     return DwarfAccelTypesSection;
260   }
getDwarfInfoDWOSection()261   const MCSection *getDwarfInfoDWOSection() const {
262     return DwarfInfoDWOSection;
263   }
264   const MCSection *getDwarfTypesSection(uint64_t Hash) const;
getDwarfTypesDWOSection()265   const MCSection *getDwarfTypesDWOSection() const {
266     return DwarfTypesDWOSection;
267   }
getDwarfAbbrevDWOSection()268   const MCSection *getDwarfAbbrevDWOSection() const {
269     return DwarfAbbrevDWOSection;
270   }
getDwarfStrDWOSection()271   const MCSection *getDwarfStrDWOSection() const {
272     return DwarfStrDWOSection;
273   }
getDwarfLineDWOSection()274   const MCSection *getDwarfLineDWOSection() const {
275     return DwarfLineDWOSection;
276   }
getDwarfLocDWOSection()277   const MCSection *getDwarfLocDWOSection() const {
278     return DwarfLocDWOSection;
279   }
getDwarfStrOffDWOSection()280   const MCSection *getDwarfStrOffDWOSection() const {
281     return DwarfStrOffDWOSection;
282   }
getDwarfAddrSection()283   const MCSection *getDwarfAddrSection() const {
284     return DwarfAddrSection;
285   }
286 
getCOFFDebugSymbolsSection()287   const MCSection *getCOFFDebugSymbolsSection() const {
288     return COFFDebugSymbolsSection;
289   }
290 
getTLSExtraDataSection()291   const MCSection *getTLSExtraDataSection() const {
292     return TLSExtraDataSection;
293   }
getTLSDataSection()294   const MCSection *getTLSDataSection() const { return TLSDataSection; }
getTLSBSSSection()295   const MCSection *getTLSBSSSection() const { return TLSBSSSection; }
296 
getStackMapSection()297   const MCSection *getStackMapSection() const { return StackMapSection; }
298 
299   /// ELF specific sections.
300   ///
getDataRelSection()301   const MCSection *getDataRelSection() const { return DataRelSection; }
getDataRelLocalSection()302   const MCSection *getDataRelLocalSection() const {
303     return DataRelLocalSection;
304   }
getDataRelROSection()305   const MCSection *getDataRelROSection() const { return DataRelROSection; }
getDataRelROLocalSection()306   const MCSection *getDataRelROLocalSection() const {
307     return DataRelROLocalSection;
308   }
getMergeableConst4Section()309   const MCSection *getMergeableConst4Section() const {
310     return MergeableConst4Section;
311   }
getMergeableConst8Section()312   const MCSection *getMergeableConst8Section() const {
313     return MergeableConst8Section;
314   }
getMergeableConst16Section()315   const MCSection *getMergeableConst16Section() const {
316     return MergeableConst16Section;
317   }
318 
319   /// MachO specific sections.
320   ///
getTLSTLVSection()321   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
getTLSThreadInitSection()322   const MCSection *getTLSThreadInitSection() const {
323     return TLSThreadInitSection;
324   }
getCStringSection()325   const MCSection *getCStringSection() const { return CStringSection; }
getUStringSection()326   const MCSection *getUStringSection() const { return UStringSection; }
getTextCoalSection()327   const MCSection *getTextCoalSection() const { return TextCoalSection; }
getConstTextCoalSection()328   const MCSection *getConstTextCoalSection() const {
329     return ConstTextCoalSection;
330   }
getConstDataSection()331   const MCSection *getConstDataSection() const { return ConstDataSection; }
getDataCoalSection()332   const MCSection *getDataCoalSection() const { return DataCoalSection; }
getDataCommonSection()333   const MCSection *getDataCommonSection() const { return DataCommonSection; }
getDataBSSSection()334   const MCSection *getDataBSSSection() const { return DataBSSSection; }
getFourByteConstantSection()335   const MCSection *getFourByteConstantSection() const {
336     return FourByteConstantSection;
337   }
getEightByteConstantSection()338   const MCSection *getEightByteConstantSection() const {
339     return EightByteConstantSection;
340   }
getSixteenByteConstantSection()341   const MCSection *getSixteenByteConstantSection() const {
342     return SixteenByteConstantSection;
343   }
getLazySymbolPointerSection()344   const MCSection *getLazySymbolPointerSection() const {
345     return LazySymbolPointerSection;
346   }
getNonLazySymbolPointerSection()347   const MCSection *getNonLazySymbolPointerSection() const {
348     return NonLazySymbolPointerSection;
349   }
350 
351   /// COFF specific sections.
352   ///
getDrectveSection()353   const MCSection *getDrectveSection() const { return DrectveSection; }
getPDataSection()354   const MCSection *getPDataSection() const { return PDataSection; }
getXDataSection()355   const MCSection *getXDataSection() const { return XDataSection; }
356 
getEHFrameSection()357   const MCSection *getEHFrameSection() {
358     if (!EHFrameSection)
359       InitEHFrameSection();
360     return EHFrameSection;
361   }
362 
363   enum Environment { IsMachO, IsELF, IsCOFF };
getObjectFileType()364   Environment getObjectFileType() const {
365     return Env;
366   }
367 
getRelocM()368   Reloc::Model getRelocM() const {
369     return RelocM;
370   }
371 
372 private:
373   Environment Env;
374   Reloc::Model RelocM;
375   CodeModel::Model CMModel;
376   MCContext *Ctx;
377   Triple TT;
378 
379   void InitMachOMCObjectFileInfo(Triple T);
380   void InitELFMCObjectFileInfo(Triple T);
381   void InitCOFFMCObjectFileInfo(Triple T);
382 
383   /// InitEHFrameSection - Initialize EHFrameSection on demand.
384   ///
385   void InitEHFrameSection();
386 
387 public:
getTargetTriple()388   const Triple &getTargetTriple() const { return TT; }
389 };
390 
391 } // end namespace llvm
392 
393 #endif
394