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_MCOBJECTFILEINFO_H
15 #define LLVM_MC_MCOBJECTFILEINFO_H
16 
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"
22 
23 namespace llvm {
24 class MCContext;
25 class MCSection;
26 
27 class MCObjectFileInfo {
28 protected:
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;
32 
33   /// True if target object file supports a weak_definition of constant 0 for an
34   /// omitted EH frame.
35   bool SupportsWeakOmittedEHFrame;
36 
37   /// True if the target object file supports emitting a compact unwind section
38   /// without an associated EH frame section.
39   bool SupportsCompactUnwindWithoutEHFrame;
40 
41   /// OmitDwarfIfHaveCompactUnwind - True if the target object file
42   /// supports having some functions with compact unwind and other with
43   /// dwarf unwind.
44   bool OmitDwarfIfHaveCompactUnwind;
45 
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
49   /// its target
50   unsigned FDECFIEncoding = 0;
51 
52   /// Compact unwind encoding indicating that we should emit only an EH frame.
53   unsigned CompactUnwindDwarfEHFrameOnly;
54 
55   /// Section directive for standard text.
56   MCSection *TextSection;
57 
58   /// Section directive for standard data.
59   MCSection *DataSection;
60 
61   /// Section that is default initialized to zero.
62   MCSection *BSSSection;
63 
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
67   /// constants.
68   MCSection *ReadOnlySection;
69 
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;
73 
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;
78 
79   // Dwarf sections for debug info.  If a target supports debug info, these must
80   // be set.
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;
96 
97   /// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5
98   /// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection,
99   /// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5
100   /// extensions.
101   MCSection *DwarfDebugNamesSection;
102   MCSection *DwarfAccelNamesSection;
103   MCSection *DwarfAccelObjCSection;
104   MCSection *DwarfAccelNamespaceSection;
105   MCSection *DwarfAccelTypesSection;
106 
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;
115 
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;
123 
124   /// The DWARF v5 range list section for fission.
125   MCSection *DwarfRnglistsDWOSection;
126 
127   // These are for Fission DWP files.
128   MCSection *DwarfCUIndexSection;
129   MCSection *DwarfTUIndexSection;
130 
131   /// Section for newer gnu pubnames.
132   MCSection *DwarfGnuPubNamesSection;
133   /// Section for newer gnu pubtypes.
134   MCSection *DwarfGnuPubTypesSection;
135 
136   // Section for Swift AST
137   MCSection *DwarfSwiftASTSection;
138 
139   MCSection *COFFDebugSymbolsSection;
140   MCSection *COFFDebugTypesSection;
141   MCSection *COFFGlobalTypeHashesSection;
142 
143   /// Extra TLS Variable Data section.
144   ///
145   /// If the target needs to put additional information for a TLS variable,
146   /// it'll go here.
147   MCSection *TLSExtraDataSection;
148 
149   /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
150   MCSection *TLSDataSection; // Defaults to ".tdata".
151 
152   /// Section directive for Thread Local uninitialized data.
153   ///
154   /// Null if this target doesn't support a BSS section. ELF and MachO only.
155   MCSection *TLSBSSSection; // Defaults to ".tbss".
156 
157   /// StackMap section.
158   MCSection *StackMapSection;
159 
160   /// FaultMap section.
161   MCSection *FaultMapSection;
162 
163   /// EH frame section.
164   ///
165   /// It is initialized on demand so it can be overwritten (with uniquing).
166   MCSection *EHFrameSection;
167 
168   /// Section containing metadata on function stack sizes.
169   MCSection *StackSizesSection;
170   mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing;
171 
172   // ELF specific sections.
173   MCSection *DataRelROSection;
174   MCSection *MergeableConst4Section;
175   MCSection *MergeableConst8Section;
176   MCSection *MergeableConst16Section;
177   MCSection *MergeableConst32Section;
178 
179   // MachO specific sections.
180 
181   /// Section for thread local structure information.
182   ///
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".
186 
187   /// Section for thread local data initialization functions.
188   const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
189 
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;
205 
206   /// COFF specific sections.
207   MCSection *DrectveSection;
208   MCSection *PDataSection;
209   MCSection *XDataSection;
210   MCSection *SXDataSection;
211   MCSection *GFIDsSection;
212 
213 public:
214   void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
215                             bool LargeCodeModel = false);
216 
getSupportsWeakOmittedEHFrame()217   bool getSupportsWeakOmittedEHFrame() const {
218     return SupportsWeakOmittedEHFrame;
219   }
getSupportsCompactUnwindWithoutEHFrame()220   bool getSupportsCompactUnwindWithoutEHFrame() const {
221     return SupportsCompactUnwindWithoutEHFrame;
222   }
getOmitDwarfIfHaveCompactUnwind()223   bool getOmitDwarfIfHaveCompactUnwind() const {
224     return OmitDwarfIfHaveCompactUnwind;
225   }
226 
getCommDirectiveSupportsAlignment()227   bool getCommDirectiveSupportsAlignment() const {
228     return CommDirectiveSupportsAlignment;
229   }
230 
getFDEEncoding()231   unsigned getFDEEncoding() const { return FDECFIEncoding; }
232 
getCompactUnwindDwarfEHFrameOnly()233   unsigned getCompactUnwindDwarfEHFrameOnly() const {
234     return CompactUnwindDwarfEHFrameOnly;
235   }
236 
getTextSection()237   MCSection *getTextSection() const { return TextSection; }
getDataSection()238   MCSection *getDataSection() const { return DataSection; }
getBSSSection()239   MCSection *getBSSSection() const { return BSSSection; }
getReadOnlySection()240   MCSection *getReadOnlySection() const { return ReadOnlySection; }
getLSDASection()241   MCSection *getLSDASection() const { return LSDASection; }
getCompactUnwindSection()242   MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
getDwarfAbbrevSection()243   MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
getDwarfInfoSection()244   MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
getDwarfInfoSection(uint64_t Hash)245   MCSection *getDwarfInfoSection(uint64_t Hash) const {
246     return getDwarfComdatSection(".debug_info", Hash);
247   }
getDwarfLineSection()248   MCSection *getDwarfLineSection() const { return DwarfLineSection; }
getDwarfLineStrSection()249   MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
getDwarfFrameSection()250   MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
getDwarfPubNamesSection()251   MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
getDwarfPubTypesSection()252   MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
getDwarfGnuPubNamesSection()253   MCSection *getDwarfGnuPubNamesSection() const {
254     return DwarfGnuPubNamesSection;
255   }
getDwarfGnuPubTypesSection()256   MCSection *getDwarfGnuPubTypesSection() const {
257     return DwarfGnuPubTypesSection;
258   }
getDwarfDebugInlineSection()259   const MCSection *getDwarfDebugInlineSection() const {
260     return DwarfDebugInlineSection;
261   }
getDwarfStrSection()262   MCSection *getDwarfStrSection() const { return DwarfStrSection; }
getDwarfLocSection()263   MCSection *getDwarfLocSection() const { return DwarfLocSection; }
getDwarfARangesSection()264   MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
getDwarfRangesSection()265   MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
getDwarfRnglistsSection()266   MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
getDwarfLoclistsSection()267   MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; }
getDwarfMacinfoSection()268   MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
269 
getDwarfDebugNamesSection()270   MCSection *getDwarfDebugNamesSection() const {
271     return DwarfDebugNamesSection;
272   }
getDwarfAccelNamesSection()273   MCSection *getDwarfAccelNamesSection() const {
274     return DwarfAccelNamesSection;
275   }
getDwarfAccelObjCSection()276   MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
getDwarfAccelNamespaceSection()277   MCSection *getDwarfAccelNamespaceSection() const {
278     return DwarfAccelNamespaceSection;
279   }
getDwarfAccelTypesSection()280   MCSection *getDwarfAccelTypesSection() const {
281     return DwarfAccelTypesSection;
282   }
getDwarfInfoDWOSection()283   MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
getDwarfTypesSection(uint64_t Hash)284   MCSection *getDwarfTypesSection(uint64_t Hash) const {
285     return getDwarfComdatSection(".debug_types", Hash);
286   }
getDwarfTypesDWOSection()287   MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
getDwarfAbbrevDWOSection()288   MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
getDwarfStrDWOSection()289   MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
getDwarfLineDWOSection()290   MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
getDwarfLocDWOSection()291   MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
getDwarfStrOffDWOSection()292   MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
getDwarfStrOffSection()293   MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
getDwarfAddrSection()294   MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
getDwarfRnglistsDWOSection()295   MCSection *getDwarfRnglistsDWOSection() const {
296     return DwarfRnglistsDWOSection;
297   }
getDwarfCUIndexSection()298   MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
getDwarfTUIndexSection()299   MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
getDwarfSwiftASTSection()300   MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
301 
getCOFFDebugSymbolsSection()302   MCSection *getCOFFDebugSymbolsSection() const {
303     return COFFDebugSymbolsSection;
304   }
getCOFFDebugTypesSection()305   MCSection *getCOFFDebugTypesSection() const {
306     return COFFDebugTypesSection;
307   }
getCOFFGlobalTypeHashesSection()308   MCSection *getCOFFGlobalTypeHashesSection() const {
309     return COFFGlobalTypeHashesSection;
310   }
311 
getTLSExtraDataSection()312   MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
getTLSDataSection()313   const MCSection *getTLSDataSection() const { return TLSDataSection; }
getTLSBSSSection()314   MCSection *getTLSBSSSection() const { return TLSBSSSection; }
315 
getStackMapSection()316   MCSection *getStackMapSection() const { return StackMapSection; }
getFaultMapSection()317   MCSection *getFaultMapSection() const { return FaultMapSection; }
318 
319   MCSection *getStackSizesSection(const MCSection &TextSec) const;
320 
321   // ELF specific sections.
getDataRelROSection()322   MCSection *getDataRelROSection() const { return DataRelROSection; }
getMergeableConst4Section()323   const MCSection *getMergeableConst4Section() const {
324     return MergeableConst4Section;
325   }
getMergeableConst8Section()326   const MCSection *getMergeableConst8Section() const {
327     return MergeableConst8Section;
328   }
getMergeableConst16Section()329   const MCSection *getMergeableConst16Section() const {
330     return MergeableConst16Section;
331   }
getMergeableConst32Section()332   const MCSection *getMergeableConst32Section() const {
333     return MergeableConst32Section;
334   }
335 
336   // MachO specific sections.
getTLSTLVSection()337   const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
getTLSThreadInitSection()338   const MCSection *getTLSThreadInitSection() const {
339     return TLSThreadInitSection;
340   }
getCStringSection()341   const MCSection *getCStringSection() const { return CStringSection; }
getUStringSection()342   const MCSection *getUStringSection() const { return UStringSection; }
getTextCoalSection()343   MCSection *getTextCoalSection() const { return TextCoalSection; }
getConstTextCoalSection()344   const MCSection *getConstTextCoalSection() const {
345     return ConstTextCoalSection;
346   }
getConstDataSection()347   const MCSection *getConstDataSection() const { return ConstDataSection; }
getDataCoalSection()348   const MCSection *getDataCoalSection() const { return DataCoalSection; }
getConstDataCoalSection()349   const MCSection *getConstDataCoalSection() const {
350     return ConstDataCoalSection;
351   }
getDataCommonSection()352   const MCSection *getDataCommonSection() const { return DataCommonSection; }
getDataBSSSection()353   MCSection *getDataBSSSection() const { return DataBSSSection; }
getFourByteConstantSection()354   const MCSection *getFourByteConstantSection() const {
355     return FourByteConstantSection;
356   }
getEightByteConstantSection()357   const MCSection *getEightByteConstantSection() const {
358     return EightByteConstantSection;
359   }
getSixteenByteConstantSection()360   const MCSection *getSixteenByteConstantSection() const {
361     return SixteenByteConstantSection;
362   }
getLazySymbolPointerSection()363   MCSection *getLazySymbolPointerSection() const {
364     return LazySymbolPointerSection;
365   }
getNonLazySymbolPointerSection()366   MCSection *getNonLazySymbolPointerSection() const {
367     return NonLazySymbolPointerSection;
368   }
getThreadLocalPointerSection()369   MCSection *getThreadLocalPointerSection() const {
370     return ThreadLocalPointerSection;
371   }
372 
373   // COFF specific sections.
getDrectveSection()374   MCSection *getDrectveSection() const { return DrectveSection; }
getPDataSection()375   MCSection *getPDataSection() const { return PDataSection; }
getXDataSection()376   MCSection *getXDataSection() const { return XDataSection; }
getSXDataSection()377   MCSection *getSXDataSection() const { return SXDataSection; }
getGFIDsSection()378   MCSection *getGFIDsSection() const { return GFIDsSection; }
379 
getEHFrameSection()380   MCSection *getEHFrameSection() {
381     return EHFrameSection;
382   }
383 
384   enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
getObjectFileType()385   Environment getObjectFileType() const { return Env; }
386 
isPositionIndependent()387   bool isPositionIndependent() const { return PositionIndependent; }
388 
389 private:
390   Environment Env;
391   bool PositionIndependent;
392   MCContext *Ctx;
393   Triple TT;
394   VersionTuple SDKVersion;
395 
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;
401 
402 public:
getTargetTriple()403   const Triple &getTargetTriple() const { return TT; }
404 
setSDKVersion(const VersionTuple & TheSDKVersion)405   void setSDKVersion(const VersionTuple &TheSDKVersion) {
406     SDKVersion = TheSDKVersion;
407   }
408 
getSDKVersion()409   const VersionTuple &getSDKVersion() const { return SDKVersion; }
410 };
411 
412 } // end namespace llvm
413 
414 #endif
415