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