1 //===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes common object file formats.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_MC_MCOBJECTFILEINFO_H
15 #define LLVM_MC_MCOBJECTFILEINFO_H
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/MC/MCSymbol.h"
20 #include "llvm/Support/CodeGen.h"
26 class MCObjectFileInfo {
28 /// True if .comm supports alignment. This is a hack for as long as we
29 /// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
30 bool CommDirectiveSupportsAlignment;
32 /// True if target object file supports a weak_definition of constant 0 for an
34 bool SupportsWeakOmittedEHFrame;
36 /// True if the target object file supports emitting a compact unwind section
37 /// without an associated EH frame section.
38 bool SupportsCompactUnwindWithoutEHFrame;
40 /// OmitDwarfIfHaveCompactUnwind - True if the target object file
41 /// supports having some functions with compact unwind and other with
43 bool OmitDwarfIfHaveCompactUnwind;
45 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values
47 unsigned PersonalityEncoding;
48 unsigned LSDAEncoding;
49 unsigned FDECFIEncoding;
50 unsigned TTypeEncoding;
52 /// Compact unwind encoding indicating that we should emit only an EH frame.
53 unsigned CompactUnwindDwarfEHFrameOnly;
55 /// Section directive for standard text.
56 MCSection *TextSection;
58 /// Section directive for standard data.
59 MCSection *DataSection;
61 /// Section that is default initialized to zero.
62 MCSection *BSSSection;
64 /// Section that is readonly and can contain arbitrary initialized data.
65 /// Targets are not required to have a readonly section. If they don't,
66 /// various bits of code will fall back to using the data section for
68 MCSection *ReadOnlySection;
70 /// If exception handling is supported by the target, this is the section the
71 /// Language Specific Data Area information is emitted to.
72 MCSection *LSDASection;
74 /// If exception handling is supported by the target and the target can
75 /// support a compact representation of the CIE and FDE, this is the section
76 /// to emit them into.
77 MCSection *CompactUnwindSection;
79 // Dwarf sections for debug info. If a target supports debug info, these must
81 MCSection *DwarfAbbrevSection;
82 MCSection *DwarfInfoSection;
83 MCSection *DwarfLineSection;
84 MCSection *DwarfLineStrSection;
85 MCSection *DwarfFrameSection;
86 MCSection *DwarfPubTypesSection;
87 const MCSection *DwarfDebugInlineSection;
88 MCSection *DwarfStrSection;
89 MCSection *DwarfLocSection;
90 MCSection *DwarfARangesSection;
91 MCSection *DwarfRangesSection;
92 MCSection *DwarfMacinfoSection;
93 // The pubnames section is no longer generated by default. The generation
94 // can be enabled by a compiler flag.
95 MCSection *DwarfPubNamesSection;
97 /// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5
98 /// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection,
99 /// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5
101 MCSection *DwarfDebugNamesSection;
102 MCSection *DwarfAccelNamesSection;
103 MCSection *DwarfAccelObjCSection;
104 MCSection *DwarfAccelNamespaceSection;
105 MCSection *DwarfAccelTypesSection;
107 // These are used for the Fission separate debug information files.
108 MCSection *DwarfInfoDWOSection;
109 MCSection *DwarfTypesDWOSection;
110 MCSection *DwarfAbbrevDWOSection;
111 MCSection *DwarfStrDWOSection;
112 MCSection *DwarfLineDWOSection;
113 MCSection *DwarfLocDWOSection;
114 MCSection *DwarfStrOffDWOSection;
116 /// The DWARF v5 string offset and address table sections.
117 MCSection *DwarfStrOffSection;
118 MCSection *DwarfAddrSection;
119 /// The DWARF v5 range list section.
120 MCSection *DwarfRnglistsSection;
122 /// The DWARF v5 range list section for fission.
123 MCSection *DwarfRnglistsDWOSection;
125 // These are for Fission DWP files.
126 MCSection *DwarfCUIndexSection;
127 MCSection *DwarfTUIndexSection;
129 /// Section for newer gnu pubnames.
130 MCSection *DwarfGnuPubNamesSection;
131 /// Section for newer gnu pubtypes.
132 MCSection *DwarfGnuPubTypesSection;
134 // Section for Swift AST
135 MCSection *DwarfSwiftASTSection;
137 MCSection *COFFDebugSymbolsSection;
138 MCSection *COFFDebugTypesSection;
139 MCSection *COFFGlobalTypeHashesSection;
141 /// Extra TLS Variable Data section.
143 /// If the target needs to put additional information for a TLS variable,
145 MCSection *TLSExtraDataSection;
147 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
148 MCSection *TLSDataSection; // Defaults to ".tdata".
150 /// Section directive for Thread Local uninitialized data.
152 /// Null if this target doesn't support a BSS section. ELF and MachO only.
153 MCSection *TLSBSSSection; // Defaults to ".tbss".
155 /// StackMap section.
156 MCSection *StackMapSection;
158 /// FaultMap section.
159 MCSection *FaultMapSection;
161 /// EH frame section.
163 /// It is initialized on demand so it can be overwritten (with uniquing).
164 MCSection *EHFrameSection;
166 /// Section containing metadata on function stack sizes.
167 MCSection *StackSizesSection;
168 mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing;
170 // ELF specific sections.
171 MCSection *DataRelROSection;
172 MCSection *MergeableConst4Section;
173 MCSection *MergeableConst8Section;
174 MCSection *MergeableConst16Section;
175 MCSection *MergeableConst32Section;
177 // MachO specific sections.
179 /// Section for thread local structure information.
181 /// Contains the source code name of the variable, visibility and a pointer to
182 /// the initial value (.tdata or .tbss).
183 MCSection *TLSTLVSection; // Defaults to ".tlv".
185 /// Section for thread local data initialization functions.
186 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
188 MCSection *CStringSection;
189 MCSection *UStringSection;
190 MCSection *TextCoalSection;
191 MCSection *ConstTextCoalSection;
192 MCSection *ConstDataSection;
193 MCSection *DataCoalSection;
194 MCSection *ConstDataCoalSection;
195 MCSection *DataCommonSection;
196 MCSection *DataBSSSection;
197 MCSection *FourByteConstantSection;
198 MCSection *EightByteConstantSection;
199 MCSection *SixteenByteConstantSection;
200 MCSection *LazySymbolPointerSection;
201 MCSection *NonLazySymbolPointerSection;
202 MCSection *ThreadLocalPointerSection;
204 /// COFF specific sections.
205 MCSection *DrectveSection;
206 MCSection *PDataSection;
207 MCSection *XDataSection;
208 MCSection *SXDataSection;
209 MCSection *GFIDsSection;
212 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
213 bool LargeCodeModel = false);
215 bool getSupportsWeakOmittedEHFrame() const {
216 return SupportsWeakOmittedEHFrame;
218 bool getSupportsCompactUnwindWithoutEHFrame() const {
219 return SupportsCompactUnwindWithoutEHFrame;
221 bool getOmitDwarfIfHaveCompactUnwind() const {
222 return OmitDwarfIfHaveCompactUnwind;
225 bool getCommDirectiveSupportsAlignment() const {
226 return CommDirectiveSupportsAlignment;
229 unsigned getPersonalityEncoding() const { return PersonalityEncoding; }
230 unsigned getLSDAEncoding() const { return LSDAEncoding; }
231 unsigned getFDEEncoding() const { return FDECFIEncoding; }
232 unsigned getTTypeEncoding() const { return TTypeEncoding; }
234 unsigned getCompactUnwindDwarfEHFrameOnly() const {
235 return CompactUnwindDwarfEHFrameOnly;
238 MCSection *getTextSection() const { return TextSection; }
239 MCSection *getDataSection() const { return DataSection; }
240 MCSection *getBSSSection() const { return BSSSection; }
241 MCSection *getReadOnlySection() const { return ReadOnlySection; }
242 MCSection *getLSDASection() const { return LSDASection; }
243 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
244 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
245 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
246 MCSection *getDwarfLineSection() const { return DwarfLineSection; }
247 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
248 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
249 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
250 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
251 MCSection *getDwarfGnuPubNamesSection() const {
252 return DwarfGnuPubNamesSection;
254 MCSection *getDwarfGnuPubTypesSection() const {
255 return DwarfGnuPubTypesSection;
257 const MCSection *getDwarfDebugInlineSection() const {
258 return DwarfDebugInlineSection;
260 MCSection *getDwarfStrSection() const { return DwarfStrSection; }
261 MCSection *getDwarfLocSection() const { return DwarfLocSection; }
262 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
263 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
264 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
265 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
267 MCSection *getDwarfDebugNamesSection() const {
268 return DwarfDebugNamesSection;
270 MCSection *getDwarfAccelNamesSection() const {
271 return DwarfAccelNamesSection;
273 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
274 MCSection *getDwarfAccelNamespaceSection() const {
275 return DwarfAccelNamespaceSection;
277 MCSection *getDwarfAccelTypesSection() const {
278 return DwarfAccelTypesSection;
280 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
281 MCSection *getDwarfTypesSection(uint64_t Hash) const;
282 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
283 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
284 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
285 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
286 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
287 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
288 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
289 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
290 MCSection *getDwarfRnglistsDWOSection() const {
291 return DwarfRnglistsDWOSection;
293 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
294 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
295 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
297 MCSection *getCOFFDebugSymbolsSection() const {
298 return COFFDebugSymbolsSection;
300 MCSection *getCOFFDebugTypesSection() const {
301 return COFFDebugTypesSection;
303 MCSection *getCOFFGlobalTypeHashesSection() const {
304 return COFFGlobalTypeHashesSection;
307 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
308 const MCSection *getTLSDataSection() const { return TLSDataSection; }
309 MCSection *getTLSBSSSection() const { return TLSBSSSection; }
311 MCSection *getStackMapSection() const { return StackMapSection; }
312 MCSection *getFaultMapSection() const { return FaultMapSection; }
314 MCSection *getStackSizesSection(const MCSection &TextSec) const;
316 // ELF specific sections.
317 MCSection *getDataRelROSection() const { return DataRelROSection; }
318 const MCSection *getMergeableConst4Section() const {
319 return MergeableConst4Section;
321 const MCSection *getMergeableConst8Section() const {
322 return MergeableConst8Section;
324 const MCSection *getMergeableConst16Section() const {
325 return MergeableConst16Section;
327 const MCSection *getMergeableConst32Section() const {
328 return MergeableConst32Section;
331 // MachO specific sections.
332 const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
333 const MCSection *getTLSThreadInitSection() const {
334 return TLSThreadInitSection;
336 const MCSection *getCStringSection() const { return CStringSection; }
337 const MCSection *getUStringSection() const { return UStringSection; }
338 MCSection *getTextCoalSection() const { return TextCoalSection; }
339 const MCSection *getConstTextCoalSection() const {
340 return ConstTextCoalSection;
342 const MCSection *getConstDataSection() const { return ConstDataSection; }
343 const MCSection *getDataCoalSection() const { return DataCoalSection; }
344 const MCSection *getConstDataCoalSection() const {
345 return ConstDataCoalSection;
347 const MCSection *getDataCommonSection() const { return DataCommonSection; }
348 MCSection *getDataBSSSection() const { return DataBSSSection; }
349 const MCSection *getFourByteConstantSection() const {
350 return FourByteConstantSection;
352 const MCSection *getEightByteConstantSection() const {
353 return EightByteConstantSection;
355 const MCSection *getSixteenByteConstantSection() const {
356 return SixteenByteConstantSection;
358 MCSection *getLazySymbolPointerSection() const {
359 return LazySymbolPointerSection;
361 MCSection *getNonLazySymbolPointerSection() const {
362 return NonLazySymbolPointerSection;
364 MCSection *getThreadLocalPointerSection() const {
365 return ThreadLocalPointerSection;
368 // COFF specific sections.
369 MCSection *getDrectveSection() const { return DrectveSection; }
370 MCSection *getPDataSection() const { return PDataSection; }
371 MCSection *getXDataSection() const { return XDataSection; }
372 MCSection *getSXDataSection() const { return SXDataSection; }
373 MCSection *getGFIDsSection() const { return GFIDsSection; }
375 MCSection *getEHFrameSection() {
376 return EHFrameSection;
379 enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
380 Environment getObjectFileType() const { return Env; }
382 bool isPositionIndependent() const { return PositionIndependent; }
386 bool PositionIndependent;
390 void initMachOMCObjectFileInfo(const Triple &T);
391 void initELFMCObjectFileInfo(const Triple &T, bool Large);
392 void initCOFFMCObjectFileInfo(const Triple &T);
393 void initWasmMCObjectFileInfo(const Triple &T);
396 const Triple &getTargetTriple() const { return TT; }
399 } // end namespace llvm