1 //===-- llvm/MC/MCObjectFileInfo.h - Object File Info -----------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file describes common object file formats. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_MC_MCOBJECTFILEINFO_H 14 #define LLVM_MC_MCOBJECTFILEINFO_H 15 16 #include "llvm/BinaryFormat/Swift.h" 17 #include "llvm/MC/MCSection.h" 18 #include "llvm/Support/Compiler.h" 19 #include "llvm/Support/VersionTuple.h" 20 #include "llvm/TargetParser/Triple.h" 21 22 #include <array> 23 #include <optional> 24 25 namespace llvm { 26 class MCContext; 27 class MCSection; 28 29 class LLVM_ABI MCObjectFileInfo { 30 protected: 31 /// True if target object file supports a weak_definition of constant 0 for an 32 /// omitted EH frame. 33 bool SupportsWeakOmittedEHFrame = false; 34 35 /// True if the target object file supports emitting a compact unwind section 36 /// without an associated EH frame section. 37 bool SupportsCompactUnwindWithoutEHFrame = false; 38 39 /// OmitDwarfIfHaveCompactUnwind - True if the target object file 40 /// supports having some functions with compact unwind and other with 41 /// dwarf unwind. 42 bool OmitDwarfIfHaveCompactUnwind = false; 43 44 /// FDE CFI encoding. Controls the encoding of the begin label in the 45 /// .eh_frame section. Unlike the LSDA encoding, personality encoding, and 46 /// type encodings, this is something that the assembler just "knows" about 47 /// its target 48 unsigned FDECFIEncoding = 0; 49 50 /// Compact unwind encoding indicating that we should emit only an EH frame. 51 unsigned CompactUnwindDwarfEHFrameOnly = 0; 52 53 /// Section directive for standard text. 54 MCSection *TextSection = nullptr; 55 56 /// Section directive for standard data. 57 MCSection *DataSection = nullptr; 58 59 /// Section that is default initialized to zero. 60 MCSection *BSSSection = nullptr; 61 62 /// Section that is readonly and can contain arbitrary initialized data. 63 /// Targets are not required to have a readonly section. If they don't, 64 /// various bits of code will fall back to using the data section for 65 /// constants. 66 MCSection *ReadOnlySection = nullptr; 67 68 /// If exception handling is supported by the target, this is the section the 69 /// Language Specific Data Area information is emitted to. 70 MCSection *LSDASection = nullptr; 71 72 /// If exception handling is supported by the target and the target can 73 /// support a compact representation of the CIE and FDE, this is the section 74 /// to emit them into. 75 MCSection *CompactUnwindSection = nullptr; 76 77 /// If import call optimization is supported by the target, this is the 78 /// section to emit import call data to. 79 MCSection *ImportCallSection = nullptr; 80 81 // Dwarf sections for debug info. If a target supports debug info, these must 82 // be set. 83 MCSection *DwarfAbbrevSection = nullptr; 84 MCSection *DwarfInfoSection = nullptr; 85 MCSection *DwarfLineSection = nullptr; 86 MCSection *DwarfLineStrSection = nullptr; 87 MCSection *DwarfFrameSection = nullptr; 88 MCSection *DwarfPubTypesSection = nullptr; 89 const MCSection *DwarfDebugInlineSection = nullptr; 90 MCSection *DwarfStrSection = nullptr; 91 MCSection *DwarfLocSection = nullptr; 92 MCSection *DwarfARangesSection = nullptr; 93 MCSection *DwarfRangesSection = nullptr; 94 MCSection *DwarfMacinfoSection = nullptr; 95 MCSection *DwarfMacroSection = nullptr; 96 // The pubnames section is no longer generated by default. The generation 97 // can be enabled by a compiler flag. 98 MCSection *DwarfPubNamesSection = nullptr; 99 100 /// Accelerator table sections. DwarfDebugNamesSection is the DWARF v5 101 /// accelerator table, while DwarfAccelNamesSection, DwarfAccelObjCSection, 102 /// DwarfAccelNamespaceSection, DwarfAccelTypesSection are pre-DWARF v5 103 /// extensions. 104 MCSection *DwarfDebugNamesSection = nullptr; 105 MCSection *DwarfAccelNamesSection = nullptr; 106 MCSection *DwarfAccelObjCSection = nullptr; 107 MCSection *DwarfAccelNamespaceSection = nullptr; 108 MCSection *DwarfAccelTypesSection = nullptr; 109 110 // These are used for the Fission separate debug information files. 111 MCSection *DwarfInfoDWOSection = nullptr; 112 MCSection *DwarfTypesDWOSection = nullptr; 113 MCSection *DwarfAbbrevDWOSection = nullptr; 114 MCSection *DwarfStrDWOSection = nullptr; 115 MCSection *DwarfLineDWOSection = nullptr; 116 MCSection *DwarfLocDWOSection = nullptr; 117 MCSection *DwarfStrOffDWOSection = nullptr; 118 MCSection *DwarfMacinfoDWOSection = nullptr; 119 MCSection *DwarfMacroDWOSection = nullptr; 120 121 /// The DWARF v5 string offset and address table sections. 122 MCSection *DwarfStrOffSection = nullptr; 123 MCSection *DwarfAddrSection = nullptr; 124 /// The DWARF v5 range list section. 125 MCSection *DwarfRnglistsSection = nullptr; 126 /// The DWARF v5 locations list section. 127 MCSection *DwarfLoclistsSection = nullptr; 128 129 /// The DWARF v5 range and location list sections for fission. 130 MCSection *DwarfRnglistsDWOSection = nullptr; 131 MCSection *DwarfLoclistsDWOSection = nullptr; 132 133 // These are for Fission DWP files. 134 MCSection *DwarfCUIndexSection = nullptr; 135 MCSection *DwarfTUIndexSection = nullptr; 136 137 /// Section for newer gnu pubnames. 138 MCSection *DwarfGnuPubNamesSection = nullptr; 139 /// Section for newer gnu pubtypes. 140 MCSection *DwarfGnuPubTypesSection = nullptr; 141 142 // Section for Swift AST 143 MCSection *DwarfSwiftASTSection = nullptr; 144 145 MCSection *COFFDebugSymbolsSection = nullptr; 146 MCSection *COFFDebugTypesSection = nullptr; 147 MCSection *COFFGlobalTypeHashesSection = nullptr; 148 149 /// Extra TLS Variable Data section. 150 /// 151 /// If the target needs to put additional information for a TLS variable, 152 /// it'll go here. 153 MCSection *TLSExtraDataSection = nullptr; 154 155 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm. 156 MCSection *TLSDataSection = nullptr; // Defaults to ".tdata". 157 158 /// Section directive for Thread Local uninitialized data. 159 /// 160 /// Null if this target doesn't support a BSS section. ELF and MachO only. 161 MCSection *TLSBSSSection = nullptr; // Defaults to ".tbss". 162 163 /// StackMap section. 164 MCSection *StackMapSection = nullptr; 165 166 /// FaultMap section. 167 MCSection *FaultMapSection = nullptr; 168 169 /// Remarks section. 170 MCSection *RemarksSection = nullptr; 171 172 /// EH frame section. 173 /// 174 /// It is initialized on demand so it can be overwritten (with uniquing). 175 MCSection *EHFrameSection = nullptr; 176 177 /// Section containing metadata on function stack sizes. 178 MCSection *StackSizesSection = nullptr; 179 180 /// Section for pseudo probe information used by AutoFDO 181 MCSection *PseudoProbeSection = nullptr; 182 MCSection *PseudoProbeDescSection = nullptr; 183 184 // Section for metadata of llvm statistics. 185 MCSection *LLVMStatsSection = nullptr; 186 187 // ELF specific sections. 188 MCSection *DataRelROSection = nullptr; 189 MCSection *MergeableConst4Section = nullptr; 190 MCSection *MergeableConst8Section = nullptr; 191 MCSection *MergeableConst16Section = nullptr; 192 MCSection *MergeableConst32Section = nullptr; 193 194 // MachO specific sections. 195 196 /// Section for thread local structure information. 197 /// 198 /// Contains the source code name of the variable, visibility and a pointer to 199 /// the initial value (.tdata or .tbss). 200 MCSection *TLSTLVSection = nullptr; // Defaults to ".tlv". 201 202 /// Section for thread local data initialization functions. 203 // Defaults to ".thread_init_func". 204 const MCSection *TLSThreadInitSection = nullptr; 205 206 MCSection *CStringSection = nullptr; 207 MCSection *UStringSection = nullptr; 208 MCSection *TextCoalSection = nullptr; 209 MCSection *ConstTextCoalSection = nullptr; 210 MCSection *ConstDataSection = nullptr; 211 MCSection *DataCoalSection = nullptr; 212 MCSection *ConstDataCoalSection = nullptr; 213 MCSection *DataCommonSection = nullptr; 214 MCSection *DataBSSSection = nullptr; 215 MCSection *FourByteConstantSection = nullptr; 216 MCSection *EightByteConstantSection = nullptr; 217 MCSection *SixteenByteConstantSection = nullptr; 218 MCSection *LazySymbolPointerSection = nullptr; 219 MCSection *NonLazySymbolPointerSection = nullptr; 220 MCSection *ThreadLocalPointerSection = nullptr; 221 MCSection *AddrSigSection = nullptr; 222 223 /// COFF specific sections. 224 MCSection *DrectveSection = nullptr; 225 MCSection *PDataSection = nullptr; 226 MCSection *XDataSection = nullptr; 227 MCSection *SXDataSection = nullptr; 228 MCSection *GEHContSection = nullptr; 229 MCSection *GFIDsSection = nullptr; 230 MCSection *GIATsSection = nullptr; 231 MCSection *GLJMPSection = nullptr; 232 233 // GOFF specific sections. 234 MCSection *PPA2ListSection = nullptr; 235 MCSection *ADASection = nullptr; 236 MCSection *IDRLSection = nullptr; 237 238 // XCOFF specific sections 239 MCSection *TOCBaseSection = nullptr; 240 MCSection *ReadOnly8Section = nullptr; 241 MCSection *ReadOnly16Section = nullptr; 242 243 // Swift5 Reflection Data Sections 244 std::array<MCSection *, binaryformat::Swift5ReflectionSectionKind::last> 245 Swift5ReflectionSections = {}; 246 247 public: 248 void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, 249 bool LargeCodeModel = false); 250 virtual ~MCObjectFileInfo(); getContext()251 MCContext &getContext() const { return *Ctx; } 252 getSupportsWeakOmittedEHFrame()253 bool getSupportsWeakOmittedEHFrame() const { 254 return SupportsWeakOmittedEHFrame; 255 } getSupportsCompactUnwindWithoutEHFrame()256 bool getSupportsCompactUnwindWithoutEHFrame() const { 257 return SupportsCompactUnwindWithoutEHFrame; 258 } getOmitDwarfIfHaveCompactUnwind()259 bool getOmitDwarfIfHaveCompactUnwind() const { 260 return OmitDwarfIfHaveCompactUnwind; 261 } 262 getFDEEncoding()263 unsigned getFDEEncoding() const { return FDECFIEncoding; } 264 getCompactUnwindDwarfEHFrameOnly()265 unsigned getCompactUnwindDwarfEHFrameOnly() const { 266 return CompactUnwindDwarfEHFrameOnly; 267 } 268 getTextSectionAlignment()269 virtual unsigned getTextSectionAlignment() const { return 4; } getTextSection()270 MCSection *getTextSection() const { return TextSection; } getDataSection()271 MCSection *getDataSection() const { return DataSection; } getBSSSection()272 MCSection *getBSSSection() const { return BSSSection; } getReadOnlySection()273 MCSection *getReadOnlySection() const { return ReadOnlySection; } getLSDASection()274 MCSection *getLSDASection() const { return LSDASection; } getImportCallSection()275 MCSection *getImportCallSection() const { return ImportCallSection; } getCompactUnwindSection()276 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; } getDwarfAbbrevSection()277 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } getDwarfInfoSection()278 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } getDwarfInfoSection(uint64_t Hash)279 MCSection *getDwarfInfoSection(uint64_t Hash) const { 280 return getDwarfComdatSection(".debug_info", Hash); 281 } getDwarfLineSection()282 MCSection *getDwarfLineSection() const { return DwarfLineSection; } getDwarfLineStrSection()283 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; } getDwarfFrameSection()284 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } getDwarfPubNamesSection()285 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; } getDwarfPubTypesSection()286 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; } getDwarfGnuPubNamesSection()287 MCSection *getDwarfGnuPubNamesSection() const { 288 return DwarfGnuPubNamesSection; 289 } getDwarfGnuPubTypesSection()290 MCSection *getDwarfGnuPubTypesSection() const { 291 return DwarfGnuPubTypesSection; 292 } getDwarfDebugInlineSection()293 const MCSection *getDwarfDebugInlineSection() const { 294 return DwarfDebugInlineSection; 295 } getDwarfStrSection()296 MCSection *getDwarfStrSection() const { return DwarfStrSection; } getDwarfLocSection()297 MCSection *getDwarfLocSection() const { return DwarfLocSection; } getDwarfARangesSection()298 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; } getDwarfRangesSection()299 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } getDwarfRnglistsSection()300 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; } getDwarfLoclistsSection()301 MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; } getDwarfMacinfoSection()302 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; } getDwarfMacroSection()303 MCSection *getDwarfMacroSection() const { return DwarfMacroSection; } 304 getDwarfDebugNamesSection()305 MCSection *getDwarfDebugNamesSection() const { 306 return DwarfDebugNamesSection; 307 } getDwarfAccelNamesSection()308 MCSection *getDwarfAccelNamesSection() const { 309 return DwarfAccelNamesSection; 310 } getDwarfAccelObjCSection()311 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; } getDwarfAccelNamespaceSection()312 MCSection *getDwarfAccelNamespaceSection() const { 313 return DwarfAccelNamespaceSection; 314 } getDwarfAccelTypesSection()315 MCSection *getDwarfAccelTypesSection() const { 316 return DwarfAccelTypesSection; 317 } getDwarfInfoDWOSection()318 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; } getDwarfTypesSection(uint64_t Hash)319 MCSection *getDwarfTypesSection(uint64_t Hash) const { 320 return getDwarfComdatSection(".debug_types", Hash); 321 } getDwarfTypesDWOSection()322 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; } getDwarfAbbrevDWOSection()323 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; } getDwarfStrDWOSection()324 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; } getDwarfLineDWOSection()325 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; } getDwarfLocDWOSection()326 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; } getDwarfStrOffDWOSection()327 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; } getDwarfStrOffSection()328 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; } getDwarfAddrSection()329 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; } getDwarfRnglistsDWOSection()330 MCSection *getDwarfRnglistsDWOSection() const { 331 return DwarfRnglistsDWOSection; 332 } getDwarfLoclistsDWOSection()333 MCSection *getDwarfLoclistsDWOSection() const { 334 return DwarfLoclistsDWOSection; 335 } getDwarfMacroDWOSection()336 MCSection *getDwarfMacroDWOSection() const { return DwarfMacroDWOSection; } getDwarfMacinfoDWOSection()337 MCSection *getDwarfMacinfoDWOSection() const { 338 return DwarfMacinfoDWOSection; 339 } getDwarfCUIndexSection()340 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; } getDwarfTUIndexSection()341 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; } getDwarfSwiftASTSection()342 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; } 343 getCOFFDebugSymbolsSection()344 MCSection *getCOFFDebugSymbolsSection() const { 345 return COFFDebugSymbolsSection; 346 } getCOFFDebugTypesSection()347 MCSection *getCOFFDebugTypesSection() const { 348 return COFFDebugTypesSection; 349 } getCOFFGlobalTypeHashesSection()350 MCSection *getCOFFGlobalTypeHashesSection() const { 351 return COFFGlobalTypeHashesSection; 352 } 353 getTLSExtraDataSection()354 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; } getTLSDataSection()355 const MCSection *getTLSDataSection() const { return TLSDataSection; } getTLSBSSSection()356 MCSection *getTLSBSSSection() const { return TLSBSSSection; } 357 getStackMapSection()358 MCSection *getStackMapSection() const { return StackMapSection; } getFaultMapSection()359 MCSection *getFaultMapSection() const { return FaultMapSection; } getRemarksSection()360 MCSection *getRemarksSection() const { return RemarksSection; } 361 362 MCSection *getStackSizesSection(const MCSection &TextSec) const; 363 364 MCSection *getBBAddrMapSection(const MCSection &TextSec) const; 365 366 MCSection *getKCFITrapSection(const MCSection &TextSec) const; 367 368 MCSection *getPseudoProbeSection(const MCSection &TextSec) const; 369 370 MCSection *getPseudoProbeDescSection(StringRef FuncName) const; 371 372 MCSection *getLLVMStatsSection() const; 373 374 MCSection *getPCSection(StringRef Name, const MCSection *TextSec) const; 375 376 // ELF specific sections. getDataRelROSection()377 MCSection *getDataRelROSection() const { return DataRelROSection; } getMergeableConst4Section()378 const MCSection *getMergeableConst4Section() const { 379 return MergeableConst4Section; 380 } getMergeableConst8Section()381 const MCSection *getMergeableConst8Section() const { 382 return MergeableConst8Section; 383 } getMergeableConst16Section()384 const MCSection *getMergeableConst16Section() const { 385 return MergeableConst16Section; 386 } getMergeableConst32Section()387 const MCSection *getMergeableConst32Section() const { 388 return MergeableConst32Section; 389 } 390 391 // MachO specific sections. getTLSTLVSection()392 const MCSection *getTLSTLVSection() const { return TLSTLVSection; } getTLSThreadInitSection()393 const MCSection *getTLSThreadInitSection() const { 394 return TLSThreadInitSection; 395 } getCStringSection()396 const MCSection *getCStringSection() const { return CStringSection; } getUStringSection()397 const MCSection *getUStringSection() const { return UStringSection; } getTextCoalSection()398 MCSection *getTextCoalSection() const { return TextCoalSection; } getConstTextCoalSection()399 const MCSection *getConstTextCoalSection() const { 400 return ConstTextCoalSection; 401 } getConstDataSection()402 const MCSection *getConstDataSection() const { return ConstDataSection; } getDataCoalSection()403 const MCSection *getDataCoalSection() const { return DataCoalSection; } getConstDataCoalSection()404 const MCSection *getConstDataCoalSection() const { 405 return ConstDataCoalSection; 406 } getDataCommonSection()407 const MCSection *getDataCommonSection() const { return DataCommonSection; } getDataBSSSection()408 MCSection *getDataBSSSection() const { return DataBSSSection; } getFourByteConstantSection()409 const MCSection *getFourByteConstantSection() const { 410 return FourByteConstantSection; 411 } getEightByteConstantSection()412 const MCSection *getEightByteConstantSection() const { 413 return EightByteConstantSection; 414 } getSixteenByteConstantSection()415 const MCSection *getSixteenByteConstantSection() const { 416 return SixteenByteConstantSection; 417 } getLazySymbolPointerSection()418 MCSection *getLazySymbolPointerSection() const { 419 return LazySymbolPointerSection; 420 } getNonLazySymbolPointerSection()421 MCSection *getNonLazySymbolPointerSection() const { 422 return NonLazySymbolPointerSection; 423 } getThreadLocalPointerSection()424 MCSection *getThreadLocalPointerSection() const { 425 return ThreadLocalPointerSection; 426 } getAddrSigSection()427 MCSection *getAddrSigSection() const { return AddrSigSection; } 428 429 // COFF specific sections. getDrectveSection()430 MCSection *getDrectveSection() const { return DrectveSection; } getPDataSection()431 MCSection *getPDataSection() const { return PDataSection; } getXDataSection()432 MCSection *getXDataSection() const { return XDataSection; } getSXDataSection()433 MCSection *getSXDataSection() const { return SXDataSection; } getGEHContSection()434 MCSection *getGEHContSection() const { return GEHContSection; } getGFIDsSection()435 MCSection *getGFIDsSection() const { return GFIDsSection; } getGIATsSection()436 MCSection *getGIATsSection() const { return GIATsSection; } getGLJMPSection()437 MCSection *getGLJMPSection() const { return GLJMPSection; } 438 439 // GOFF specific sections. getPPA2ListSection()440 MCSection *getPPA2ListSection() const { return PPA2ListSection; } getADASection()441 MCSection *getADASection() const { return ADASection; } getIDRLSection()442 MCSection *getIDRLSection() const { return IDRLSection; } 443 444 // XCOFF specific sections getTOCBaseSection()445 MCSection *getTOCBaseSection() const { return TOCBaseSection; } 446 getEHFrameSection()447 MCSection *getEHFrameSection() const { return EHFrameSection; } 448 isPositionIndependent()449 bool isPositionIndependent() const { return PositionIndependent; } 450 451 // Swift5 Reflection Data Sections getSwift5ReflectionSection(llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind)452 MCSection *getSwift5ReflectionSection( 453 llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind) { 454 return ReflSectionKind != 455 llvm::binaryformat::Swift5ReflectionSectionKind::unknown 456 ? Swift5ReflectionSections[ReflSectionKind] 457 : nullptr; 458 } 459 460 private: 461 bool PositionIndependent = false; 462 MCContext *Ctx = nullptr; 463 464 void initMachOMCObjectFileInfo(const Triple &T); 465 void initELFMCObjectFileInfo(const Triple &T, bool Large); 466 void initGOFFMCObjectFileInfo(const Triple &T); 467 void initCOFFMCObjectFileInfo(const Triple &T); 468 void initSPIRVMCObjectFileInfo(const Triple &T); 469 void initWasmMCObjectFileInfo(const Triple &T); 470 void initXCOFFMCObjectFileInfo(const Triple &T); 471 void initDXContainerObjectFileInfo(const Triple &T); 472 MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const; 473 }; 474 475 } // end namespace llvm 476 477 #endif 478