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 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 /// PersonalityEncoding, LSDAEncoding, TTypeEncoding - Some encoding values 46 /// for EH. 47 unsigned PersonalityEncoding; 48 unsigned LSDAEncoding; 49 unsigned FDECFIEncoding; 50 unsigned TTypeEncoding; 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 122 /// The DWARF v5 range list section for fission. 123 MCSection *DwarfRnglistsDWOSection; 124 125 // These are for Fission DWP files. 126 MCSection *DwarfCUIndexSection; 127 MCSection *DwarfTUIndexSection; 128 129 /// Section for newer gnu pubnames. 130 MCSection *DwarfGnuPubNamesSection; 131 /// Section for newer gnu pubtypes. 132 MCSection *DwarfGnuPubTypesSection; 133 134 // Section for Swift AST 135 MCSection *DwarfSwiftASTSection; 136 137 MCSection *COFFDebugSymbolsSection; 138 MCSection *COFFDebugTypesSection; 139 MCSection *COFFGlobalTypeHashesSection; 140 141 /// Extra TLS Variable Data section. 142 /// 143 /// If the target needs to put additional information for a TLS variable, 144 /// it'll go here. 145 MCSection *TLSExtraDataSection; 146 147 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm. 148 MCSection *TLSDataSection; // Defaults to ".tdata". 149 150 /// Section directive for Thread Local uninitialized data. 151 /// 152 /// Null if this target doesn't support a BSS section. ELF and MachO only. 153 MCSection *TLSBSSSection; // Defaults to ".tbss". 154 155 /// StackMap section. 156 MCSection *StackMapSection; 157 158 /// FaultMap section. 159 MCSection *FaultMapSection; 160 161 /// EH frame section. 162 /// 163 /// It is initialized on demand so it can be overwritten (with uniquing). 164 MCSection *EHFrameSection; 165 166 /// Section containing metadata on function stack sizes. 167 MCSection *StackSizesSection; 168 mutable DenseMap<const MCSymbol *, unsigned> StackSizesUniquing; 169 170 // ELF specific sections. 171 MCSection *DataRelROSection; 172 MCSection *MergeableConst4Section; 173 MCSection *MergeableConst8Section; 174 MCSection *MergeableConst16Section; 175 MCSection *MergeableConst32Section; 176 177 // MachO specific sections. 178 179 /// Section for thread local structure information. 180 /// 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". 184 185 /// Section for thread local data initialization functions. 186 const MCSection *TLSThreadInitSection; // Defaults to ".thread_init_func". 187 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; 203 204 /// COFF specific sections. 205 MCSection *DrectveSection; 206 MCSection *PDataSection; 207 MCSection *XDataSection; 208 MCSection *SXDataSection; 209 MCSection *GFIDsSection; 210 211 public: 212 void InitMCObjectFileInfo(const Triple &TT, bool PIC, MCContext &ctx, 213 bool LargeCodeModel = false); 214 getSupportsWeakOmittedEHFrame()215 bool getSupportsWeakOmittedEHFrame() const { 216 return SupportsWeakOmittedEHFrame; 217 } getSupportsCompactUnwindWithoutEHFrame()218 bool getSupportsCompactUnwindWithoutEHFrame() const { 219 return SupportsCompactUnwindWithoutEHFrame; 220 } getOmitDwarfIfHaveCompactUnwind()221 bool getOmitDwarfIfHaveCompactUnwind() const { 222 return OmitDwarfIfHaveCompactUnwind; 223 } 224 getCommDirectiveSupportsAlignment()225 bool getCommDirectiveSupportsAlignment() const { 226 return CommDirectiveSupportsAlignment; 227 } 228 getPersonalityEncoding()229 unsigned getPersonalityEncoding() const { return PersonalityEncoding; } getLSDAEncoding()230 unsigned getLSDAEncoding() const { return LSDAEncoding; } getFDEEncoding()231 unsigned getFDEEncoding() const { return FDECFIEncoding; } getTTypeEncoding()232 unsigned getTTypeEncoding() const { return TTypeEncoding; } 233 getCompactUnwindDwarfEHFrameOnly()234 unsigned getCompactUnwindDwarfEHFrameOnly() const { 235 return CompactUnwindDwarfEHFrameOnly; 236 } 237 getTextSection()238 MCSection *getTextSection() const { return TextSection; } getDataSection()239 MCSection *getDataSection() const { return DataSection; } getBSSSection()240 MCSection *getBSSSection() const { return BSSSection; } getReadOnlySection()241 MCSection *getReadOnlySection() const { return ReadOnlySection; } getLSDASection()242 MCSection *getLSDASection() const { return LSDASection; } getCompactUnwindSection()243 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; } getDwarfAbbrevSection()244 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } getDwarfInfoSection()245 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } getDwarfLineSection()246 MCSection *getDwarfLineSection() const { return DwarfLineSection; } getDwarfLineStrSection()247 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; } getDwarfFrameSection()248 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } getDwarfPubNamesSection()249 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; } getDwarfPubTypesSection()250 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; } getDwarfGnuPubNamesSection()251 MCSection *getDwarfGnuPubNamesSection() const { 252 return DwarfGnuPubNamesSection; 253 } getDwarfGnuPubTypesSection()254 MCSection *getDwarfGnuPubTypesSection() const { 255 return DwarfGnuPubTypesSection; 256 } getDwarfDebugInlineSection()257 const MCSection *getDwarfDebugInlineSection() const { 258 return DwarfDebugInlineSection; 259 } getDwarfStrSection()260 MCSection *getDwarfStrSection() const { return DwarfStrSection; } getDwarfLocSection()261 MCSection *getDwarfLocSection() const { return DwarfLocSection; } getDwarfARangesSection()262 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; } getDwarfRangesSection()263 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } getDwarfRnglistsSection()264 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; } getDwarfMacinfoSection()265 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; } 266 getDwarfDebugNamesSection()267 MCSection *getDwarfDebugNamesSection() const { 268 return DwarfDebugNamesSection; 269 } getDwarfAccelNamesSection()270 MCSection *getDwarfAccelNamesSection() const { 271 return DwarfAccelNamesSection; 272 } getDwarfAccelObjCSection()273 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; } getDwarfAccelNamespaceSection()274 MCSection *getDwarfAccelNamespaceSection() const { 275 return DwarfAccelNamespaceSection; 276 } getDwarfAccelTypesSection()277 MCSection *getDwarfAccelTypesSection() const { 278 return DwarfAccelTypesSection; 279 } getDwarfInfoDWOSection()280 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; } 281 MCSection *getDwarfTypesSection(uint64_t Hash) const; getDwarfTypesDWOSection()282 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; } getDwarfAbbrevDWOSection()283 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; } getDwarfStrDWOSection()284 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; } getDwarfLineDWOSection()285 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; } getDwarfLocDWOSection()286 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; } getDwarfStrOffDWOSection()287 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; } getDwarfStrOffSection()288 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; } getDwarfAddrSection()289 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; } getDwarfRnglistsDWOSection()290 MCSection *getDwarfRnglistsDWOSection() const { 291 return DwarfRnglistsDWOSection; 292 } getDwarfCUIndexSection()293 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; } getDwarfTUIndexSection()294 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; } getDwarfSwiftASTSection()295 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; } 296 getCOFFDebugSymbolsSection()297 MCSection *getCOFFDebugSymbolsSection() const { 298 return COFFDebugSymbolsSection; 299 } getCOFFDebugTypesSection()300 MCSection *getCOFFDebugTypesSection() const { 301 return COFFDebugTypesSection; 302 } getCOFFGlobalTypeHashesSection()303 MCSection *getCOFFGlobalTypeHashesSection() const { 304 return COFFGlobalTypeHashesSection; 305 } 306 getTLSExtraDataSection()307 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; } getTLSDataSection()308 const MCSection *getTLSDataSection() const { return TLSDataSection; } getTLSBSSSection()309 MCSection *getTLSBSSSection() const { return TLSBSSSection; } 310 getStackMapSection()311 MCSection *getStackMapSection() const { return StackMapSection; } getFaultMapSection()312 MCSection *getFaultMapSection() const { return FaultMapSection; } 313 314 MCSection *getStackSizesSection(const MCSection &TextSec) const; 315 316 // ELF specific sections. getDataRelROSection()317 MCSection *getDataRelROSection() const { return DataRelROSection; } getMergeableConst4Section()318 const MCSection *getMergeableConst4Section() const { 319 return MergeableConst4Section; 320 } getMergeableConst8Section()321 const MCSection *getMergeableConst8Section() const { 322 return MergeableConst8Section; 323 } getMergeableConst16Section()324 const MCSection *getMergeableConst16Section() const { 325 return MergeableConst16Section; 326 } getMergeableConst32Section()327 const MCSection *getMergeableConst32Section() const { 328 return MergeableConst32Section; 329 } 330 331 // MachO specific sections. getTLSTLVSection()332 const MCSection *getTLSTLVSection() const { return TLSTLVSection; } getTLSThreadInitSection()333 const MCSection *getTLSThreadInitSection() const { 334 return TLSThreadInitSection; 335 } getCStringSection()336 const MCSection *getCStringSection() const { return CStringSection; } getUStringSection()337 const MCSection *getUStringSection() const { return UStringSection; } getTextCoalSection()338 MCSection *getTextCoalSection() const { return TextCoalSection; } getConstTextCoalSection()339 const MCSection *getConstTextCoalSection() const { 340 return ConstTextCoalSection; 341 } getConstDataSection()342 const MCSection *getConstDataSection() const { return ConstDataSection; } getDataCoalSection()343 const MCSection *getDataCoalSection() const { return DataCoalSection; } getConstDataCoalSection()344 const MCSection *getConstDataCoalSection() const { 345 return ConstDataCoalSection; 346 } getDataCommonSection()347 const MCSection *getDataCommonSection() const { return DataCommonSection; } getDataBSSSection()348 MCSection *getDataBSSSection() const { return DataBSSSection; } getFourByteConstantSection()349 const MCSection *getFourByteConstantSection() const { 350 return FourByteConstantSection; 351 } getEightByteConstantSection()352 const MCSection *getEightByteConstantSection() const { 353 return EightByteConstantSection; 354 } getSixteenByteConstantSection()355 const MCSection *getSixteenByteConstantSection() const { 356 return SixteenByteConstantSection; 357 } getLazySymbolPointerSection()358 MCSection *getLazySymbolPointerSection() const { 359 return LazySymbolPointerSection; 360 } getNonLazySymbolPointerSection()361 MCSection *getNonLazySymbolPointerSection() const { 362 return NonLazySymbolPointerSection; 363 } getThreadLocalPointerSection()364 MCSection *getThreadLocalPointerSection() const { 365 return ThreadLocalPointerSection; 366 } 367 368 // COFF specific sections. getDrectveSection()369 MCSection *getDrectveSection() const { return DrectveSection; } getPDataSection()370 MCSection *getPDataSection() const { return PDataSection; } getXDataSection()371 MCSection *getXDataSection() const { return XDataSection; } getSXDataSection()372 MCSection *getSXDataSection() const { return SXDataSection; } getGFIDsSection()373 MCSection *getGFIDsSection() const { return GFIDsSection; } 374 getEHFrameSection()375 MCSection *getEHFrameSection() { 376 return EHFrameSection; 377 } 378 379 enum Environment { IsMachO, IsELF, IsCOFF, IsWasm }; getObjectFileType()380 Environment getObjectFileType() const { return Env; } 381 isPositionIndependent()382 bool isPositionIndependent() const { return PositionIndependent; } 383 384 private: 385 Environment Env; 386 bool PositionIndependent; 387 MCContext *Ctx; 388 Triple TT; 389 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); 394 395 public: getTargetTriple()396 const Triple &getTargetTriple() const { return TT; } 397 }; 398 399 } // end namespace llvm 400 401 #endif 402