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"
21 #include "llvm/Support/VersionTuple.h"
27 class MCObjectFileInfo {
29 /// True if .comm supports alignment. This is a hack for as long as we
30 /// support 10.4 Tiger, whose assembler doesn't support alignment on comm.
31 bool CommDirectiveSupportsAlignment;
33 /// True if target object file supports a weak_definition of constant 0 for an
35 bool SupportsWeakOmittedEHFrame;
37 /// True if the target object file supports emitting a compact unwind section
38 /// without an associated EH frame section.
39 bool SupportsCompactUnwindWithoutEHFrame;
41 /// OmitDwarfIfHaveCompactUnwind - True if the target object file
42 /// supports having some functions with compact unwind and other with
44 bool OmitDwarfIfHaveCompactUnwind;
46 /// FDE CFI encoding. Controls the encoding of the begin label in the
47 /// .eh_frame section. Unlike the LSDA encoding, personality encoding, and
48 /// type encodings, this is something that the assembler just "knows" about
50 unsigned FDECFIEncoding = 0;
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;
121 /// The DWARF v5 locations list section.
122 MCSection *DwarfLoclistsSection;
124 /// The DWARF v5 range list section for fission.
125 MCSection *DwarfRnglistsDWOSection;
127 // These are for Fission DWP files.
128 MCSection *DwarfCUIndexSection;
129 MCSection *DwarfTUIndexSection;
131 /// Section for newer gnu pubnames.
132 MCSection *DwarfGnuPubNamesSection;
133 /// Section for newer gnu pubtypes.
134 MCSection *DwarfGnuPubTypesSection;
136 // Section for Swift AST
137 MCSection *DwarfSwiftASTSection;
139 MCSection *COFFDebugSymbolsSection;
140 MCSection *COFFDebugTypesSection;
141 MCSection *COFFGlobalTypeHashesSection;
143 /// Extra TLS Variable Data section.
145 /// If the target needs to put additional information for a TLS variable,
147 MCSection *TLSExtraDataSection;
149 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
150 MCSection *TLSDataSection; // Defaults to ".tdata".
152 /// Section directive for Thread Local uninitialized data.
154 /// Null if this target doesn't support a BSS section. ELF and MachO only.
155 MCSection *TLSBSSSection; // Defaults to ".tbss".
157 /// StackMap section.
158 MCSection *StackMapSection;
160 /// FaultMap section.
161 MCSection *FaultMapSection;
163 /// EH frame section.
165 /// It is initialized on demand so it can be overwritten (with uniquing).
166 MCSection *EHFrameSection;
168 /// Section containing metadata on function stack sizes.
169 MCSection *StackSizesSection;
170 mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing;
172 // ELF specific sections.
173 MCSection *DataRelROSection;
174 MCSection *MergeableConst4Section;
175 MCSection *MergeableConst8Section;
176 MCSection *MergeableConst16Section;
177 MCSection *MergeableConst32Section;
179 // MachO specific sections.
181 /// Section for thread local structure information.
183 /// Contains the source code name of the variable, visibility and a pointer to
184 /// the initial value (.tdata or .tbss).
185 MCSection *TLSTLVSection; // Defaults to ".tlv".
187 /// Section for thread local data initialization functions.
188 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
190 MCSection *CStringSection;
191 MCSection *UStringSection;
192 MCSection *TextCoalSection;
193 MCSection *ConstTextCoalSection;
194 MCSection *ConstDataSection;
195 MCSection *DataCoalSection;
196 MCSection *ConstDataCoalSection;
197 MCSection *DataCommonSection;
198 MCSection *DataBSSSection;
199 MCSection *FourByteConstantSection;
200 MCSection *EightByteConstantSection;
201 MCSection *SixteenByteConstantSection;
202 MCSection *LazySymbolPointerSection;
203 MCSection *NonLazySymbolPointerSection;
204 MCSection *ThreadLocalPointerSection;
206 /// COFF specific sections.
207 MCSection *DrectveSection;
208 MCSection *PDataSection;
209 MCSection *XDataSection;
210 MCSection *SXDataSection;
211 MCSection *GFIDsSection;
214 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
215 bool LargeCodeModel = false);
217 bool getSupportsWeakOmittedEHFrame() const {
218 return SupportsWeakOmittedEHFrame;
220 bool getSupportsCompactUnwindWithoutEHFrame() const {
221 return SupportsCompactUnwindWithoutEHFrame;
223 bool getOmitDwarfIfHaveCompactUnwind() const {
224 return OmitDwarfIfHaveCompactUnwind;
227 bool getCommDirectiveSupportsAlignment() const {
228 return CommDirectiveSupportsAlignment;
231 unsigned getFDEEncoding() const { return FDECFIEncoding; }
233 unsigned getCompactUnwindDwarfEHFrameOnly() const {
234 return CompactUnwindDwarfEHFrameOnly;
237 MCSection *getTextSection() const { return TextSection; }
238 MCSection *getDataSection() const { return DataSection; }
239 MCSection *getBSSSection() const { return BSSSection; }
240 MCSection *getReadOnlySection() const { return ReadOnlySection; }
241 MCSection *getLSDASection() const { return LSDASection; }
242 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
243 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
244 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
245 MCSection *getDwarfInfoSection(uint64_t Hash) const {
246 return getDwarfComdatSection(".debug_info", Hash);
248 MCSection *getDwarfLineSection() const { return DwarfLineSection; }
249 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
250 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
251 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
252 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
253 MCSection *getDwarfGnuPubNamesSection() const {
254 return DwarfGnuPubNamesSection;
256 MCSection *getDwarfGnuPubTypesSection() const {
257 return DwarfGnuPubTypesSection;
259 const MCSection *getDwarfDebugInlineSection() const {
260 return DwarfDebugInlineSection;
262 MCSection *getDwarfStrSection() const { return DwarfStrSection; }
263 MCSection *getDwarfLocSection() const { return DwarfLocSection; }
264 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
265 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
266 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
267 MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; }
268 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
270 MCSection *getDwarfDebugNamesSection() const {
271 return DwarfDebugNamesSection;
273 MCSection *getDwarfAccelNamesSection() const {
274 return DwarfAccelNamesSection;
276 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
277 MCSection *getDwarfAccelNamespaceSection() const {
278 return DwarfAccelNamespaceSection;
280 MCSection *getDwarfAccelTypesSection() const {
281 return DwarfAccelTypesSection;
283 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
284 MCSection *getDwarfTypesSection(uint64_t Hash) const {
285 return getDwarfComdatSection(".debug_types", Hash);
287 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
288 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
289 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
290 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
291 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
292 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
293 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
294 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
295 MCSection *getDwarfRnglistsDWOSection() const {
296 return DwarfRnglistsDWOSection;
298 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
299 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
300 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
302 MCSection *getCOFFDebugSymbolsSection() const {
303 return COFFDebugSymbolsSection;
305 MCSection *getCOFFDebugTypesSection() const {
306 return COFFDebugTypesSection;
308 MCSection *getCOFFGlobalTypeHashesSection() const {
309 return COFFGlobalTypeHashesSection;
312 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
313 const MCSection *getTLSDataSection() const { return TLSDataSection; }
314 MCSection *getTLSBSSSection() const { return TLSBSSSection; }
316 MCSection *getStackMapSection() const { return StackMapSection; }
317 MCSection *getFaultMapSection() const { return FaultMapSection; }
319 MCSection *getStackSizesSection(const MCSection &TextSec) const;
321 // ELF specific sections.
322 MCSection *getDataRelROSection() const { return DataRelROSection; }
323 const MCSection *getMergeableConst4Section() const {
324 return MergeableConst4Section;
326 const MCSection *getMergeableConst8Section() const {
327 return MergeableConst8Section;
329 const MCSection *getMergeableConst16Section() const {
330 return MergeableConst16Section;
332 const MCSection *getMergeableConst32Section() const {
333 return MergeableConst32Section;
336 // MachO specific sections.
337 const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
338 const MCSection *getTLSThreadInitSection() const {
339 return TLSThreadInitSection;
341 const MCSection *getCStringSection() const { return CStringSection; }
342 const MCSection *getUStringSection() const { return UStringSection; }
343 MCSection *getTextCoalSection() const { return TextCoalSection; }
344 const MCSection *getConstTextCoalSection() const {
345 return ConstTextCoalSection;
347 const MCSection *getConstDataSection() const { return ConstDataSection; }
348 const MCSection *getDataCoalSection() const { return DataCoalSection; }
349 const MCSection *getConstDataCoalSection() const {
350 return ConstDataCoalSection;
352 const MCSection *getDataCommonSection() const { return DataCommonSection; }
353 MCSection *getDataBSSSection() const { return DataBSSSection; }
354 const MCSection *getFourByteConstantSection() const {
355 return FourByteConstantSection;
357 const MCSection *getEightByteConstantSection() const {
358 return EightByteConstantSection;
360 const MCSection *getSixteenByteConstantSection() const {
361 return SixteenByteConstantSection;
363 MCSection *getLazySymbolPointerSection() const {
364 return LazySymbolPointerSection;
366 MCSection *getNonLazySymbolPointerSection() const {
367 return NonLazySymbolPointerSection;
369 MCSection *getThreadLocalPointerSection() const {
370 return ThreadLocalPointerSection;
373 // COFF specific sections.
374 MCSection *getDrectveSection() const { return DrectveSection; }
375 MCSection *getPDataSection() const { return PDataSection; }
376 MCSection *getXDataSection() const { return XDataSection; }
377 MCSection *getSXDataSection() const { return SXDataSection; }
378 MCSection *getGFIDsSection() const { return GFIDsSection; }
380 MCSection *getEHFrameSection() {
381 return EHFrameSection;
384 enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
385 Environment getObjectFileType() const { return Env; }
387 bool isPositionIndependent() const { return PositionIndependent; }
391 bool PositionIndependent;
394 VersionTuple SDKVersion;
396 void initMachOMCObjectFileInfo(const Triple &T);
397 void initELFMCObjectFileInfo(const Triple &T, bool Large);
398 void initCOFFMCObjectFileInfo(const Triple &T);
399 void initWasmMCObjectFileInfo(const Triple &T);
400 MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const;
403 const Triple &getTargetTriple() const { return TT; }
405 void setSDKVersion(const VersionTuple &TheSDKVersion) {
406 SDKVersion = TheSDKVersion;
409 const VersionTuple &getSDKVersion() const { return SDKVersion; }
412 } // end namespace llvm