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