Line data Source code
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 :
22 : namespace llvm {
23 : class MCContext;
24 : class MCSection;
25 :
26 51544 : class MCObjectFileInfo {
27 : protected:
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;
31 :
32 : /// True if target object file supports a weak_definition of constant 0 for an
33 : /// omitted EH frame.
34 : bool SupportsWeakOmittedEHFrame;
35 :
36 : /// True if the target object file supports emitting a compact unwind section
37 : /// without an associated EH frame section.
38 : bool SupportsCompactUnwindWithoutEHFrame;
39 :
40 : /// OmitDwarfIfHaveCompactUnwind - True if the target object file
41 : /// supports having some functions with compact unwind and other with
42 : /// dwarf unwind.
43 : bool OmitDwarfIfHaveCompactUnwind;
44 :
45 : /// FDE CFI encoding. Controls the encoding of the begin label in the
46 : /// .eh_frame section. Unlike the LSDA encoding, personality encoding, and
47 : /// type encodings, this is something that the assembler just "knows" about
48 : /// its target
49 : unsigned FDECFIEncoding = 0;
50 :
51 : /// Compact unwind encoding indicating that we should emit only an EH frame.
52 : unsigned CompactUnwindDwarfEHFrameOnly;
53 :
54 : /// Section directive for standard text.
55 : MCSection *TextSection;
56 :
57 : /// Section directive for standard data.
58 : MCSection *DataSection;
59 :
60 : /// Section that is default initialized to zero.
61 : MCSection *BSSSection;
62 :
63 : /// Section that is readonly and can contain arbitrary initialized data.
64 : /// Targets are not required to have a readonly section. If they don't,
65 : /// various bits of code will fall back to using the data section for
66 : /// constants.
67 : MCSection *ReadOnlySection;
68 :
69 : /// If exception handling is supported by the target, this is the section the
70 : /// Language Specific Data Area information is emitted to.
71 : MCSection *LSDASection;
72 :
73 : /// If exception handling is supported by the target and the target can
74 : /// support a compact representation of the CIE and FDE, this is the section
75 : /// to emit them into.
76 : MCSection *CompactUnwindSection;
77 :
78 : // Dwarf sections for debug info. If a target supports debug info, these must
79 : // be set.
80 : MCSection *DwarfAbbrevSection;
81 : MCSection *DwarfInfoSection;
82 : MCSection *DwarfLineSection;
83 : MCSection *DwarfLineStrSection;
84 : MCSection *DwarfFrameSection;
85 : MCSection *DwarfPubTypesSection;
86 : const MCSection *DwarfDebugInlineSection;
87 : MCSection *DwarfStrSection;
88 : MCSection *DwarfLocSection;
89 : MCSection *DwarfARangesSection;
90 : MCSection *DwarfRangesSection;
91 : MCSection *DwarfMacinfoSection;
92 : // The pubnames section is no longer generated by default. The generation
93 : // can be enabled by a compiler flag.
94 : MCSection *DwarfPubNamesSection;
95 :
96 : /// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5
97 : /// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection,
98 : /// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5
99 : /// extensions.
100 : MCSection *DwarfDebugNamesSection;
101 : MCSection *DwarfAccelNamesSection;
102 : MCSection *DwarfAccelObjCSection;
103 : MCSection *DwarfAccelNamespaceSection;
104 : MCSection *DwarfAccelTypesSection;
105 :
106 : // These are used for the Fission separate debug information files.
107 : MCSection *DwarfInfoDWOSection;
108 : MCSection *DwarfTypesDWOSection;
109 : MCSection *DwarfAbbrevDWOSection;
110 : MCSection *DwarfStrDWOSection;
111 : MCSection *DwarfLineDWOSection;
112 : MCSection *DwarfLocDWOSection;
113 : MCSection *DwarfStrOffDWOSection;
114 :
115 : /// The DWARF v5 string offset and address table sections.
116 : MCSection *DwarfStrOffSection;
117 : MCSection *DwarfAddrSection;
118 : /// The DWARF v5 range list section.
119 : MCSection *DwarfRnglistsSection;
120 :
121 : /// The DWARF v5 range list section for fission.
122 : MCSection *DwarfRnglistsDWOSection;
123 :
124 : // These are for Fission DWP files.
125 : MCSection *DwarfCUIndexSection;
126 : MCSection *DwarfTUIndexSection;
127 :
128 : /// Section for newer gnu pubnames.
129 : MCSection *DwarfGnuPubNamesSection;
130 : /// Section for newer gnu pubtypes.
131 : MCSection *DwarfGnuPubTypesSection;
132 :
133 : // Section for Swift AST
134 : MCSection *DwarfSwiftASTSection;
135 :
136 : MCSection *COFFDebugSymbolsSection;
137 : MCSection *COFFDebugTypesSection;
138 : MCSection *COFFGlobalTypeHashesSection;
139 :
140 : /// Extra TLS Variable Data section.
141 : ///
142 : /// If the target needs to put additional information for a TLS variable,
143 : /// it'll go here.
144 : MCSection *TLSExtraDataSection;
145 :
146 : /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
147 : MCSection *TLSDataSection; // Defaults to ".tdata".
148 :
149 : /// Section directive for Thread Local uninitialized data.
150 : ///
151 : /// Null if this target doesn't support a BSS section. ELF and MachO only.
152 : MCSection *TLSBSSSection; // Defaults to ".tbss".
153 :
154 : /// StackMap section.
155 : MCSection *StackMapSection;
156 :
157 : /// FaultMap section.
158 : MCSection *FaultMapSection;
159 :
160 : /// EH frame section.
161 : ///
162 : /// It is initialized on demand so it can be overwritten (with uniquing).
163 : MCSection *EHFrameSection;
164 :
165 : /// Section containing metadata on function stack sizes.
166 : MCSection *StackSizesSection;
167 : mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing;
168 :
169 : // ELF specific sections.
170 : MCSection *DataRelROSection;
171 : MCSection *MergeableConst4Section;
172 : MCSection *MergeableConst8Section;
173 : MCSection *MergeableConst16Section;
174 : MCSection *MergeableConst32Section;
175 :
176 : // MachO specific sections.
177 :
178 : /// Section for thread local structure information.
179 : ///
180 : /// Contains the source code name of the variable, visibility and a pointer to
181 : /// the initial value (.tdata or .tbss).
182 : MCSection *TLSTLVSection; // Defaults to ".tlv".
183 :
184 : /// Section for thread local data initialization functions.
185 : const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func".
186 :
187 : MCSection *CStringSection;
188 : MCSection *UStringSection;
189 : MCSection *TextCoalSection;
190 : MCSection *ConstTextCoalSection;
191 : MCSection *ConstDataSection;
192 : MCSection *DataCoalSection;
193 : MCSection *ConstDataCoalSection;
194 : MCSection *DataCommonSection;
195 : MCSection *DataBSSSection;
196 : MCSection *FourByteConstantSection;
197 : MCSection *EightByteConstantSection;
198 : MCSection *SixteenByteConstantSection;
199 : MCSection *LazySymbolPointerSection;
200 : MCSection *NonLazySymbolPointerSection;
201 : MCSection *ThreadLocalPointerSection;
202 :
203 : /// COFF specific sections.
204 : MCSection *DrectveSection;
205 : MCSection *PDataSection;
206 : MCSection *XDataSection;
207 : MCSection *SXDataSection;
208 : MCSection *GFIDsSection;
209 :
210 : public:
211 : void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx,
212 : bool LargeCodeModel = false);
213 :
214 : bool getSupportsWeakOmittedEHFrame() const {
215 : return SupportsWeakOmittedEHFrame;
216 : }
217 0 : bool getSupportsCompactUnwindWithoutEHFrame() const {
218 0 : return SupportsCompactUnwindWithoutEHFrame;
219 : }
220 0 : bool getOmitDwarfIfHaveCompactUnwind() const {
221 0 : return OmitDwarfIfHaveCompactUnwind;
222 : }
223 :
224 0 : bool getCommDirectiveSupportsAlignment() const {
225 0 : return CommDirectiveSupportsAlignment;
226 : }
227 :
228 0 : unsigned getFDEEncoding() const { return FDECFIEncoding; }
229 :
230 0 : unsigned getCompactUnwindDwarfEHFrameOnly() const {
231 0 : return CompactUnwindDwarfEHFrameOnly;
232 : }
233 :
234 0 : MCSection *getTextSection() const { return TextSection; }
235 0 : MCSection *getDataSection() const { return DataSection; }
236 0 : MCSection *getBSSSection() const { return BSSSection; }
237 0 : MCSection *getReadOnlySection() const { return ReadOnlySection; }
238 0 : MCSection *getLSDASection() const { return LSDASection; }
239 0 : MCSection *getCompactUnwindSection() const { return CompactUnwindSection; }
240 0 : MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; }
241 0 : MCSection *getDwarfInfoSection() const { return DwarfInfoSection; }
242 0 : MCSection *getDwarfLineSection() const { return DwarfLineSection; }
243 0 : MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; }
244 0 : MCSection *getDwarfFrameSection() const { return DwarfFrameSection; }
245 0 : MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; }
246 0 : MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; }
247 0 : MCSection *getDwarfGnuPubNamesSection() const {
248 0 : return DwarfGnuPubNamesSection;
249 : }
250 0 : MCSection *getDwarfGnuPubTypesSection() const {
251 0 : return DwarfGnuPubTypesSection;
252 : }
253 0 : const MCSection *getDwarfDebugInlineSection() const {
254 0 : return DwarfDebugInlineSection;
255 : }
256 0 : MCSection *getDwarfStrSection() const { return DwarfStrSection; }
257 0 : MCSection *getDwarfLocSection() const { return DwarfLocSection; }
258 0 : MCSection *getDwarfARangesSection() const { return DwarfARangesSection; }
259 0 : MCSection *getDwarfRangesSection() const { return DwarfRangesSection; }
260 0 : MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; }
261 0 : MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; }
262 :
263 0 : MCSection *getDwarfDebugNamesSection() const {
264 0 : return DwarfDebugNamesSection;
265 : }
266 0 : MCSection *getDwarfAccelNamesSection() const {
267 0 : return DwarfAccelNamesSection;
268 : }
269 0 : MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; }
270 0 : MCSection *getDwarfAccelNamespaceSection() const {
271 0 : return DwarfAccelNamespaceSection;
272 : }
273 0 : MCSection *getDwarfAccelTypesSection() const {
274 0 : return DwarfAccelTypesSection;
275 : }
276 0 : MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; }
277 : MCSection *getDwarfTypesSection(uint64_t Hash) const;
278 0 : MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; }
279 0 : MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; }
280 0 : MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; }
281 0 : MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; }
282 0 : MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; }
283 0 : MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; }
284 0 : MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; }
285 0 : MCSection *getDwarfAddrSection() const { return DwarfAddrSection; }
286 : MCSection *getDwarfRnglistsDWOSection() const {
287 : return DwarfRnglistsDWOSection;
288 : }
289 0 : MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; }
290 0 : MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; }
291 0 : MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; }
292 :
293 0 : MCSection *getCOFFDebugSymbolsSection() const {
294 0 : return COFFDebugSymbolsSection;
295 : }
296 0 : MCSection *getCOFFDebugTypesSection() const {
297 0 : return COFFDebugTypesSection;
298 : }
299 0 : MCSection *getCOFFGlobalTypeHashesSection() const {
300 0 : return COFFGlobalTypeHashesSection;
301 : }
302 :
303 0 : MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; }
304 : const MCSection *getTLSDataSection() const { return TLSDataSection; }
305 0 : MCSection *getTLSBSSSection() const { return TLSBSSSection; }
306 :
307 0 : MCSection *getStackMapSection() const { return StackMapSection; }
308 0 : MCSection *getFaultMapSection() const { return FaultMapSection; }
309 :
310 : MCSection *getStackSizesSection(const MCSection &TextSec) const;
311 :
312 : // ELF specific sections.
313 : MCSection *getDataRelROSection() const { return DataRelROSection; }
314 : const MCSection *getMergeableConst4Section() const {
315 : return MergeableConst4Section;
316 : }
317 : const MCSection *getMergeableConst8Section() const {
318 : return MergeableConst8Section;
319 : }
320 : const MCSection *getMergeableConst16Section() const {
321 : return MergeableConst16Section;
322 : }
323 : const MCSection *getMergeableConst32Section() const {
324 : return MergeableConst32Section;
325 : }
326 :
327 : // MachO specific sections.
328 : const MCSection *getTLSTLVSection() const { return TLSTLVSection; }
329 : const MCSection *getTLSThreadInitSection() const {
330 : return TLSThreadInitSection;
331 : }
332 : const MCSection *getCStringSection() const { return CStringSection; }
333 : const MCSection *getUStringSection() const { return UStringSection; }
334 0 : MCSection *getTextCoalSection() const { return TextCoalSection; }
335 : const MCSection *getConstTextCoalSection() const {
336 : return ConstTextCoalSection;
337 : }
338 : const MCSection *getConstDataSection() const { return ConstDataSection; }
339 : const MCSection *getDataCoalSection() const { return DataCoalSection; }
340 : const MCSection *getConstDataCoalSection() const {
341 : return ConstDataCoalSection;
342 : }
343 : const MCSection *getDataCommonSection() const { return DataCommonSection; }
344 0 : MCSection *getDataBSSSection() const { return DataBSSSection; }
345 : const MCSection *getFourByteConstantSection() const {
346 : return FourByteConstantSection;
347 : }
348 : const MCSection *getEightByteConstantSection() const {
349 : return EightByteConstantSection;
350 : }
351 : const MCSection *getSixteenByteConstantSection() const {
352 : return SixteenByteConstantSection;
353 : }
354 : MCSection *getLazySymbolPointerSection() const {
355 : return LazySymbolPointerSection;
356 : }
357 0 : MCSection *getNonLazySymbolPointerSection() const {
358 0 : return NonLazySymbolPointerSection;
359 : }
360 0 : MCSection *getThreadLocalPointerSection() const {
361 0 : return ThreadLocalPointerSection;
362 : }
363 :
364 : // COFF specific sections.
365 0 : MCSection *getDrectveSection() const { return DrectveSection; }
366 0 : MCSection *getPDataSection() const { return PDataSection; }
367 0 : MCSection *getXDataSection() const { return XDataSection; }
368 0 : MCSection *getSXDataSection() const { return SXDataSection; }
369 0 : MCSection *getGFIDsSection() const { return GFIDsSection; }
370 :
371 0 : MCSection *getEHFrameSection() {
372 0 : return EHFrameSection;
373 : }
374 :
375 : enum Environment { IsMachO, IsELF, IsCOFF, IsWasm };
376 0 : Environment getObjectFileType() const { return Env; }
377 :
378 0 : bool isPositionIndependent() const { return PositionIndependent; }
379 :
380 : private:
381 : Environment Env;
382 : bool PositionIndependent;
383 : MCContext *Ctx;
384 : Triple TT;
385 :
386 : void initMachOMCObjectFileInfo(const Triple &T);
387 : void initELFMCObjectFileInfo(const Triple &T, bool Large);
388 : void initCOFFMCObjectFileInfo(const Triple &T);
389 : void initWasmMCObjectFileInfo(const Triple &T);
390 :
391 : public:
392 166730 : const Triple &getTargetTriple() const { return TT; }
393 : };
394 :
395 : } // end namespace llvm
396 :
397 : #endif
|