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