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/ADT/DenseMap.h" 17 #include "llvm/ADT/Triple.h" 18 #include "llvm/MC/MCSymbol.h" 19 #include "llvm/Support/CodeGen.h" 20 #include "llvm/Support/VersionTuple.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 = false; 31 32 /// True if target object file supports a weak_definition of constant 0 for an 33 /// omitted EH frame. 34 bool SupportsWeakOmittedEHFrame = false; 35 36 /// True if the target object file supports emitting a compact unwind section 37 /// without an associated EH frame section. 38 bool SupportsCompactUnwindWithoutEHFrame = false; 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 = false; 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 = 0; 53 54 /// Section directive for standard text. 55 MCSection *TextSection = nullptr; 56 57 /// Section directive for standard data. 58 MCSection *DataSection = nullptr; 59 60 /// Section that is default initialized to zero. 61 MCSection *BSSSection = nullptr; 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 = nullptr; 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 = nullptr; 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 = nullptr; 77 78 // Dwarf sections for debug info. If a target supports debug info, these must 79 // be set. 80 MCSection *DwarfAbbrevSection = nullptr; 81 MCSection *DwarfInfoSection = nullptr; 82 MCSection *DwarfLineSection = nullptr; 83 MCSection *DwarfLineStrSection = nullptr; 84 MCSection *DwarfFrameSection = nullptr; 85 MCSection *DwarfPubTypesSection = nullptr; 86 const MCSection *DwarfDebugInlineSection = nullptr; 87 MCSection *DwarfStrSection = nullptr; 88 MCSection *DwarfLocSection = nullptr; 89 MCSection *DwarfARangesSection = nullptr; 90 MCSection *DwarfRangesSection = nullptr; 91 MCSection *DwarfMacinfoSection = nullptr; 92 MCSection *DwarfMacroSection = nullptr; 93 // The pubnames section is no longer generated by default. The generation 94 // can be enabled by a compiler flag. 95 MCSection *DwarfPubNamesSection = nullptr; 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 = nullptr; 102 MCSection *DwarfAccelNamesSection = nullptr; 103 MCSection *DwarfAccelObjCSection = nullptr; 104 MCSection *DwarfAccelNamespaceSection = nullptr; 105 MCSection *DwarfAccelTypesSection = nullptr; 106 107 // These are used for the Fission separate debug information files. 108 MCSection *DwarfInfoDWOSection = nullptr; 109 MCSection *DwarfTypesDWOSection = nullptr; 110 MCSection *DwarfAbbrevDWOSection = nullptr; 111 MCSection *DwarfStrDWOSection = nullptr; 112 MCSection *DwarfLineDWOSection = nullptr; 113 MCSection *DwarfLocDWOSection = nullptr; 114 MCSection *DwarfStrOffDWOSection = nullptr; 115 MCSection *DwarfMacinfoDWOSection = nullptr; 116 MCSection *DwarfMacroDWOSection = nullptr; 117 118 /// The DWARF v5 string offset and address table sections. 119 MCSection *DwarfStrOffSection = nullptr; 120 MCSection *DwarfAddrSection = nullptr; 121 /// The DWARF v5 range list section. 122 MCSection *DwarfRnglistsSection = nullptr; 123 /// The DWARF v5 locations list section. 124 MCSection *DwarfLoclistsSection = nullptr; 125 126 /// The DWARF v5 range and location list sections for fission. 127 MCSection *DwarfRnglistsDWOSection = nullptr; 128 MCSection *DwarfLoclistsDWOSection = nullptr; 129 130 // These are for Fission DWP files. 131 MCSection *DwarfCUIndexSection = nullptr; 132 MCSection *DwarfTUIndexSection = nullptr; 133 134 /// Section for newer gnu pubnames. 135 MCSection *DwarfGnuPubNamesSection = nullptr; 136 /// Section for newer gnu pubtypes. 137 MCSection *DwarfGnuPubTypesSection = nullptr; 138 139 // Section for Swift AST 140 MCSection *DwarfSwiftASTSection = nullptr; 141 142 MCSection *COFFDebugSymbolsSection = nullptr; 143 MCSection *COFFDebugTypesSection = nullptr; 144 MCSection *COFFGlobalTypeHashesSection = nullptr; 145 146 /// Extra TLS Variable Data section. 147 /// 148 /// If the target needs to put additional information for a TLS variable, 149 /// it'll go here. 150 MCSection *TLSExtraDataSection = nullptr; 151 152 /// Section directive for Thread Local data. ELF, MachO, COFF, and Wasm. 153 MCSection *TLSDataSection = nullptr; // Defaults to ".tdata". 154 155 /// Section directive for Thread Local uninitialized data. 156 /// 157 /// Null if this target doesn't support a BSS section. ELF and MachO only. 158 MCSection *TLSBSSSection = nullptr; // Defaults to ".tbss". 159 160 /// StackMap section. 161 MCSection *StackMapSection = nullptr; 162 163 /// FaultMap section. 164 MCSection *FaultMapSection = nullptr; 165 166 /// Remarks section. 167 MCSection *RemarksSection = nullptr; 168 169 /// EH frame section. 170 /// 171 /// It is initialized on demand so it can be overwritten (with uniquing). 172 MCSection *EHFrameSection = nullptr; 173 174 /// Section containing metadata on function stack sizes. 175 MCSection *StackSizesSection = nullptr; 176 177 /// Section for pseudo probe information used by AutoFDO 178 MCSection *PseudoProbeSection = nullptr; 179 MCSection *PseudoProbeDescSection = nullptr; 180 181 // ELF specific sections. 182 MCSection *DataRelROSection = nullptr; 183 MCSection *MergeableConst4Section = nullptr; 184 MCSection *MergeableConst8Section = nullptr; 185 MCSection *MergeableConst16Section = nullptr; 186 MCSection *MergeableConst32Section = nullptr; 187 188 // MachO specific sections. 189 190 /// Section for thread local structure information. 191 /// 192 /// Contains the source code name of the variable, visibility and a pointer to 193 /// the initial value (.tdata or .tbss). 194 MCSection *TLSTLVSection = nullptr; // Defaults to ".tlv". 195 196 /// Section for thread local data initialization functions. 197 // Defaults to ".thread_init_func". 198 const MCSection *TLSThreadInitSection = nullptr; 199 200 MCSection *CStringSection = nullptr; 201 MCSection *UStringSection = nullptr; 202 MCSection *TextCoalSection = nullptr; 203 MCSection *ConstTextCoalSection = nullptr; 204 MCSection *ConstDataSection = nullptr; 205 MCSection *DataCoalSection = nullptr; 206 MCSection *ConstDataCoalSection = nullptr; 207 MCSection *DataCommonSection = nullptr; 208 MCSection *DataBSSSection = nullptr; 209 MCSection *FourByteConstantSection = nullptr; 210 MCSection *EightByteConstantSection = nullptr; 211 MCSection *SixteenByteConstantSection = nullptr; 212 MCSection *LazySymbolPointerSection = nullptr; 213 MCSection *NonLazySymbolPointerSection = nullptr; 214 MCSection *ThreadLocalPointerSection = nullptr; 215 216 /// COFF specific sections. 217 MCSection *DrectveSection = nullptr; 218 MCSection *PDataSection = nullptr; 219 MCSection *XDataSection = nullptr; 220 MCSection *SXDataSection = nullptr; 221 MCSection *GEHContSection = nullptr; 222 MCSection *GFIDsSection = nullptr; 223 MCSection *GIATsSection = nullptr; 224 MCSection *GLJMPSection = nullptr; 225 226 // XCOFF specific sections 227 MCSection *TOCBaseSection = nullptr; 228 229 public: 230 void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, 231 bool LargeCodeModel = false); getContext()232 MCContext &getContext() const { return *Ctx; } 233 getSupportsWeakOmittedEHFrame()234 bool getSupportsWeakOmittedEHFrame() const { 235 return SupportsWeakOmittedEHFrame; 236 } getSupportsCompactUnwindWithoutEHFrame()237 bool getSupportsCompactUnwindWithoutEHFrame() const { 238 return SupportsCompactUnwindWithoutEHFrame; 239 } getOmitDwarfIfHaveCompactUnwind()240 bool getOmitDwarfIfHaveCompactUnwind() const { 241 return OmitDwarfIfHaveCompactUnwind; 242 } 243 getCommDirectiveSupportsAlignment()244 bool getCommDirectiveSupportsAlignment() const { 245 return CommDirectiveSupportsAlignment; 246 } 247 getFDEEncoding()248 unsigned getFDEEncoding() const { return FDECFIEncoding; } 249 getCompactUnwindDwarfEHFrameOnly()250 unsigned getCompactUnwindDwarfEHFrameOnly() const { 251 return CompactUnwindDwarfEHFrameOnly; 252 } 253 getTextSection()254 MCSection *getTextSection() const { return TextSection; } getDataSection()255 MCSection *getDataSection() const { return DataSection; } getBSSSection()256 MCSection *getBSSSection() const { return BSSSection; } getReadOnlySection()257 MCSection *getReadOnlySection() const { return ReadOnlySection; } getLSDASection()258 MCSection *getLSDASection() const { return LSDASection; } getCompactUnwindSection()259 MCSection *getCompactUnwindSection() const { return CompactUnwindSection; } getDwarfAbbrevSection()260 MCSection *getDwarfAbbrevSection() const { return DwarfAbbrevSection; } getDwarfInfoSection()261 MCSection *getDwarfInfoSection() const { return DwarfInfoSection; } getDwarfInfoSection(uint64_t Hash)262 MCSection *getDwarfInfoSection(uint64_t Hash) const { 263 return getDwarfComdatSection(".debug_info", Hash); 264 } getDwarfLineSection()265 MCSection *getDwarfLineSection() const { return DwarfLineSection; } getDwarfLineStrSection()266 MCSection *getDwarfLineStrSection() const { return DwarfLineStrSection; } getDwarfFrameSection()267 MCSection *getDwarfFrameSection() const { return DwarfFrameSection; } getDwarfPubNamesSection()268 MCSection *getDwarfPubNamesSection() const { return DwarfPubNamesSection; } getDwarfPubTypesSection()269 MCSection *getDwarfPubTypesSection() const { return DwarfPubTypesSection; } getDwarfGnuPubNamesSection()270 MCSection *getDwarfGnuPubNamesSection() const { 271 return DwarfGnuPubNamesSection; 272 } getDwarfGnuPubTypesSection()273 MCSection *getDwarfGnuPubTypesSection() const { 274 return DwarfGnuPubTypesSection; 275 } getDwarfDebugInlineSection()276 const MCSection *getDwarfDebugInlineSection() const { 277 return DwarfDebugInlineSection; 278 } getDwarfStrSection()279 MCSection *getDwarfStrSection() const { return DwarfStrSection; } getDwarfLocSection()280 MCSection *getDwarfLocSection() const { return DwarfLocSection; } getDwarfARangesSection()281 MCSection *getDwarfARangesSection() const { return DwarfARangesSection; } getDwarfRangesSection()282 MCSection *getDwarfRangesSection() const { return DwarfRangesSection; } getDwarfRnglistsSection()283 MCSection *getDwarfRnglistsSection() const { return DwarfRnglistsSection; } getDwarfLoclistsSection()284 MCSection *getDwarfLoclistsSection() const { return DwarfLoclistsSection; } getDwarfMacinfoSection()285 MCSection *getDwarfMacinfoSection() const { return DwarfMacinfoSection; } getDwarfMacroSection()286 MCSection *getDwarfMacroSection() const { return DwarfMacroSection; } 287 getDwarfDebugNamesSection()288 MCSection *getDwarfDebugNamesSection() const { 289 return DwarfDebugNamesSection; 290 } getDwarfAccelNamesSection()291 MCSection *getDwarfAccelNamesSection() const { 292 return DwarfAccelNamesSection; 293 } getDwarfAccelObjCSection()294 MCSection *getDwarfAccelObjCSection() const { return DwarfAccelObjCSection; } getDwarfAccelNamespaceSection()295 MCSection *getDwarfAccelNamespaceSection() const { 296 return DwarfAccelNamespaceSection; 297 } getDwarfAccelTypesSection()298 MCSection *getDwarfAccelTypesSection() const { 299 return DwarfAccelTypesSection; 300 } getDwarfInfoDWOSection()301 MCSection *getDwarfInfoDWOSection() const { return DwarfInfoDWOSection; } getDwarfTypesSection(uint64_t Hash)302 MCSection *getDwarfTypesSection(uint64_t Hash) const { 303 return getDwarfComdatSection(".debug_types", Hash); 304 } getDwarfTypesDWOSection()305 MCSection *getDwarfTypesDWOSection() const { return DwarfTypesDWOSection; } getDwarfAbbrevDWOSection()306 MCSection *getDwarfAbbrevDWOSection() const { return DwarfAbbrevDWOSection; } getDwarfStrDWOSection()307 MCSection *getDwarfStrDWOSection() const { return DwarfStrDWOSection; } getDwarfLineDWOSection()308 MCSection *getDwarfLineDWOSection() const { return DwarfLineDWOSection; } getDwarfLocDWOSection()309 MCSection *getDwarfLocDWOSection() const { return DwarfLocDWOSection; } getDwarfStrOffDWOSection()310 MCSection *getDwarfStrOffDWOSection() const { return DwarfStrOffDWOSection; } getDwarfStrOffSection()311 MCSection *getDwarfStrOffSection() const { return DwarfStrOffSection; } getDwarfAddrSection()312 MCSection *getDwarfAddrSection() const { return DwarfAddrSection; } getDwarfRnglistsDWOSection()313 MCSection *getDwarfRnglistsDWOSection() const { 314 return DwarfRnglistsDWOSection; 315 } getDwarfLoclistsDWOSection()316 MCSection *getDwarfLoclistsDWOSection() const { 317 return DwarfLoclistsDWOSection; 318 } getDwarfMacroDWOSection()319 MCSection *getDwarfMacroDWOSection() const { return DwarfMacroDWOSection; } getDwarfMacinfoDWOSection()320 MCSection *getDwarfMacinfoDWOSection() const { 321 return DwarfMacinfoDWOSection; 322 } getDwarfCUIndexSection()323 MCSection *getDwarfCUIndexSection() const { return DwarfCUIndexSection; } getDwarfTUIndexSection()324 MCSection *getDwarfTUIndexSection() const { return DwarfTUIndexSection; } getDwarfSwiftASTSection()325 MCSection *getDwarfSwiftASTSection() const { return DwarfSwiftASTSection; } 326 getCOFFDebugSymbolsSection()327 MCSection *getCOFFDebugSymbolsSection() const { 328 return COFFDebugSymbolsSection; 329 } getCOFFDebugTypesSection()330 MCSection *getCOFFDebugTypesSection() const { 331 return COFFDebugTypesSection; 332 } getCOFFGlobalTypeHashesSection()333 MCSection *getCOFFGlobalTypeHashesSection() const { 334 return COFFGlobalTypeHashesSection; 335 } 336 getTLSExtraDataSection()337 MCSection *getTLSExtraDataSection() const { return TLSExtraDataSection; } getTLSDataSection()338 const MCSection *getTLSDataSection() const { return TLSDataSection; } getTLSBSSSection()339 MCSection *getTLSBSSSection() const { return TLSBSSSection; } 340 getStackMapSection()341 MCSection *getStackMapSection() const { return StackMapSection; } getFaultMapSection()342 MCSection *getFaultMapSection() const { return FaultMapSection; } getRemarksSection()343 MCSection *getRemarksSection() const { return RemarksSection; } 344 345 MCSection *getStackSizesSection(const MCSection &TextSec) const; 346 347 MCSection *getBBAddrMapSection(const MCSection &TextSec) const; 348 349 MCSection *getPseudoProbeSection(const MCSection *TextSec) const; 350 351 MCSection *getPseudoProbeDescSection(StringRef FuncName) const; 352 353 // ELF specific sections. getDataRelROSection()354 MCSection *getDataRelROSection() const { return DataRelROSection; } getMergeableConst4Section()355 const MCSection *getMergeableConst4Section() const { 356 return MergeableConst4Section; 357 } getMergeableConst8Section()358 const MCSection *getMergeableConst8Section() const { 359 return MergeableConst8Section; 360 } getMergeableConst16Section()361 const MCSection *getMergeableConst16Section() const { 362 return MergeableConst16Section; 363 } getMergeableConst32Section()364 const MCSection *getMergeableConst32Section() const { 365 return MergeableConst32Section; 366 } 367 368 // MachO specific sections. getTLSTLVSection()369 const MCSection *getTLSTLVSection() const { return TLSTLVSection; } getTLSThreadInitSection()370 const MCSection *getTLSThreadInitSection() const { 371 return TLSThreadInitSection; 372 } getCStringSection()373 const MCSection *getCStringSection() const { return CStringSection; } getUStringSection()374 const MCSection *getUStringSection() const { return UStringSection; } getTextCoalSection()375 MCSection *getTextCoalSection() const { return TextCoalSection; } getConstTextCoalSection()376 const MCSection *getConstTextCoalSection() const { 377 return ConstTextCoalSection; 378 } getConstDataSection()379 const MCSection *getConstDataSection() const { return ConstDataSection; } getDataCoalSection()380 const MCSection *getDataCoalSection() const { return DataCoalSection; } getConstDataCoalSection()381 const MCSection *getConstDataCoalSection() const { 382 return ConstDataCoalSection; 383 } getDataCommonSection()384 const MCSection *getDataCommonSection() const { return DataCommonSection; } getDataBSSSection()385 MCSection *getDataBSSSection() const { return DataBSSSection; } getFourByteConstantSection()386 const MCSection *getFourByteConstantSection() const { 387 return FourByteConstantSection; 388 } getEightByteConstantSection()389 const MCSection *getEightByteConstantSection() const { 390 return EightByteConstantSection; 391 } getSixteenByteConstantSection()392 const MCSection *getSixteenByteConstantSection() const { 393 return SixteenByteConstantSection; 394 } getLazySymbolPointerSection()395 MCSection *getLazySymbolPointerSection() const { 396 return LazySymbolPointerSection; 397 } getNonLazySymbolPointerSection()398 MCSection *getNonLazySymbolPointerSection() const { 399 return NonLazySymbolPointerSection; 400 } getThreadLocalPointerSection()401 MCSection *getThreadLocalPointerSection() const { 402 return ThreadLocalPointerSection; 403 } 404 405 // COFF specific sections. getDrectveSection()406 MCSection *getDrectveSection() const { return DrectveSection; } getPDataSection()407 MCSection *getPDataSection() const { return PDataSection; } getXDataSection()408 MCSection *getXDataSection() const { return XDataSection; } getSXDataSection()409 MCSection *getSXDataSection() const { return SXDataSection; } getGEHContSection()410 MCSection *getGEHContSection() const { return GEHContSection; } getGFIDsSection()411 MCSection *getGFIDsSection() const { return GFIDsSection; } getGIATsSection()412 MCSection *getGIATsSection() const { return GIATsSection; } getGLJMPSection()413 MCSection *getGLJMPSection() const { return GLJMPSection; } 414 415 // XCOFF specific sections getTOCBaseSection()416 MCSection *getTOCBaseSection() const { return TOCBaseSection; } 417 getEHFrameSection()418 MCSection *getEHFrameSection() const { return EHFrameSection; } 419 isPositionIndependent()420 bool isPositionIndependent() const { return PositionIndependent; } 421 422 private: 423 bool PositionIndependent = false; 424 MCContext *Ctx = nullptr; 425 VersionTuple SDKVersion; 426 427 void initMachOMCObjectFileInfo(const Triple &T); 428 void initELFMCObjectFileInfo(const Triple &T, bool Large); 429 void initGOFFMCObjectFileInfo(const Triple &T); 430 void initCOFFMCObjectFileInfo(const Triple &T); 431 void initWasmMCObjectFileInfo(const Triple &T); 432 void initXCOFFMCObjectFileInfo(const Triple &T); 433 MCSection *getDwarfComdatSection(const char *Name, uint64_t Hash) const; 434 435 public: setSDKVersion(const VersionTuple & TheSDKVersion)436 void setSDKVersion(const VersionTuple &TheSDKVersion) { 437 SDKVersion = TheSDKVersion; 438 } 439 getSDKVersion()440 const VersionTuple &getSDKVersion() const { return SDKVersion; } 441 }; 442 443 } // end namespace llvm 444 445 #endif 446