1 //===-- MCObjectFileInfo.cpp - Object File Information --------------------===// 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 #include "llvm/MC/MCObjectFileInfo.h" 10 #include "llvm/ADT/StringExtras.h" 11 #include "llvm/BinaryFormat/COFF.h" 12 #include "llvm/BinaryFormat/ELF.h" 13 #include "llvm/BinaryFormat/Wasm.h" 14 #include "llvm/MC/MCAsmInfo.h" 15 #include "llvm/MC/MCContext.h" 16 #include "llvm/MC/MCSection.h" 17 #include "llvm/MC/MCSectionCOFF.h" 18 #include "llvm/MC/MCSectionDXContainer.h" 19 #include "llvm/MC/MCSectionELF.h" 20 #include "llvm/MC/MCSectionGOFF.h" 21 #include "llvm/MC/MCSectionMachO.h" 22 #include "llvm/MC/MCSectionSPIRV.h" 23 #include "llvm/MC/MCSectionWasm.h" 24 #include "llvm/MC/MCSectionXCOFF.h" 25 #include "llvm/Support/Casting.h" 26 #include "llvm/TargetParser/Triple.h" 27 28 using namespace llvm; 29 30 static bool useCompactUnwind(const Triple &T) { 31 // Only on darwin. 32 if (!T.isOSDarwin()) 33 return false; 34 35 // aarch64 always has it. 36 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) 37 return true; 38 39 // armv7k always has it. 40 if (T.isWatchABI()) 41 return true; 42 43 // Use it on newer version of OS X. 44 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) 45 return true; 46 47 // And the iOS simulator. 48 if (T.isiOS() && T.isX86()) 49 return true; 50 51 return false; 52 } 53 54 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { 55 // MachO 56 SupportsWeakOmittedEHFrame = false; 57 58 EHFrameSection = Ctx->getMachOSection( 59 "__TEXT", "__eh_frame", 60 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC | 61 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT, 62 SectionKind::getReadOnly()); 63 64 if (T.isOSDarwin() && 65 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)) 66 SupportsCompactUnwindWithoutEHFrame = true; 67 68 switch (Ctx->emitDwarfUnwindInfo()) { 69 case EmitDwarfUnwindType::Always: 70 OmitDwarfIfHaveCompactUnwind = false; 71 break; 72 case EmitDwarfUnwindType::NoCompactUnwind: 73 OmitDwarfIfHaveCompactUnwind = true; 74 break; 75 case EmitDwarfUnwindType::Default: 76 OmitDwarfIfHaveCompactUnwind = 77 T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame; 78 break; 79 } 80 81 FDECFIEncoding = dwarf::DW_EH_PE_pcrel; 82 83 TextSection // .text 84 = Ctx->getMachOSection("__TEXT", "__text", 85 MachO::S_ATTR_PURE_INSTRUCTIONS, 86 SectionKind::getText()); 87 DataSection // .data 88 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData()); 89 90 // BSSSection might not be expected initialized on msvc. 91 BSSSection = nullptr; 92 93 TLSDataSection // .tdata 94 = Ctx->getMachOSection("__DATA", "__thread_data", 95 MachO::S_THREAD_LOCAL_REGULAR, 96 SectionKind::getData()); 97 TLSBSSSection // .tbss 98 = Ctx->getMachOSection("__DATA", "__thread_bss", 99 MachO::S_THREAD_LOCAL_ZEROFILL, 100 SectionKind::getThreadBSS()); 101 102 // TODO: Verify datarel below. 103 TLSTLVSection // .tlv 104 = Ctx->getMachOSection("__DATA", "__thread_vars", 105 MachO::S_THREAD_LOCAL_VARIABLES, 106 SectionKind::getData()); 107 108 TLSThreadInitSection = Ctx->getMachOSection( 109 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 110 SectionKind::getData()); 111 112 CStringSection // .cstring 113 = Ctx->getMachOSection("__TEXT", "__cstring", 114 MachO::S_CSTRING_LITERALS, 115 SectionKind::getMergeable1ByteCString()); 116 UStringSection 117 = Ctx->getMachOSection("__TEXT","__ustring", 0, 118 SectionKind::getMergeable2ByteCString()); 119 FourByteConstantSection // .literal4 120 = Ctx->getMachOSection("__TEXT", "__literal4", 121 MachO::S_4BYTE_LITERALS, 122 SectionKind::getMergeableConst4()); 123 EightByteConstantSection // .literal8 124 = Ctx->getMachOSection("__TEXT", "__literal8", 125 MachO::S_8BYTE_LITERALS, 126 SectionKind::getMergeableConst8()); 127 128 SixteenByteConstantSection // .literal16 129 = Ctx->getMachOSection("__TEXT", "__literal16", 130 MachO::S_16BYTE_LITERALS, 131 SectionKind::getMergeableConst16()); 132 133 ReadOnlySection // .const 134 = Ctx->getMachOSection("__TEXT", "__const", 0, 135 SectionKind::getReadOnly()); 136 137 // If the target is not powerpc, map the coal sections to the non-coal 138 // sections. 139 // 140 // "__TEXT/__textcoal_nt" => section "__TEXT/__text" 141 // "__TEXT/__const_coal" => section "__TEXT/__const" 142 // "__DATA/__datacoal_nt" => section "__DATA/__data" 143 Triple::ArchType ArchTy = T.getArch(); 144 145 ConstDataSection // .const_data 146 = Ctx->getMachOSection("__DATA", "__const", 0, 147 SectionKind::getReadOnlyWithRel()); 148 149 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) { 150 TextCoalSection 151 = Ctx->getMachOSection("__TEXT", "__textcoal_nt", 152 MachO::S_COALESCED | 153 MachO::S_ATTR_PURE_INSTRUCTIONS, 154 SectionKind::getText()); 155 ConstTextCoalSection 156 = Ctx->getMachOSection("__TEXT", "__const_coal", 157 MachO::S_COALESCED, 158 SectionKind::getReadOnly()); 159 DataCoalSection = Ctx->getMachOSection( 160 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData()); 161 ConstDataCoalSection = DataCoalSection; 162 } else { 163 TextCoalSection = TextSection; 164 ConstTextCoalSection = ReadOnlySection; 165 DataCoalSection = DataSection; 166 ConstDataCoalSection = ConstDataSection; 167 } 168 169 DataCommonSection 170 = Ctx->getMachOSection("__DATA","__common", 171 MachO::S_ZEROFILL, 172 SectionKind::getBSS()); 173 DataBSSSection 174 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL, 175 SectionKind::getBSS()); 176 177 178 LazySymbolPointerSection 179 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr", 180 MachO::S_LAZY_SYMBOL_POINTERS, 181 SectionKind::getMetadata()); 182 NonLazySymbolPointerSection 183 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr", 184 MachO::S_NON_LAZY_SYMBOL_POINTERS, 185 SectionKind::getMetadata()); 186 187 ThreadLocalPointerSection 188 = Ctx->getMachOSection("__DATA", "__thread_ptr", 189 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS, 190 SectionKind::getMetadata()); 191 192 AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0, 193 SectionKind::getData()); 194 195 // Exception Handling. 196 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0, 197 SectionKind::getReadOnlyWithRel()); 198 199 COFFDebugSymbolsSection = nullptr; 200 COFFDebugTypesSection = nullptr; 201 COFFGlobalTypeHashesSection = nullptr; 202 203 if (useCompactUnwind(T)) { 204 CompactUnwindSection = 205 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG, 206 SectionKind::getReadOnly()); 207 208 if (T.isX86()) 209 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF 210 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) 211 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF 212 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb) 213 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF 214 } 215 216 // Debug Information. 217 DwarfDebugNamesSection = 218 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG, 219 SectionKind::getMetadata(), "debug_names_begin"); 220 DwarfAccelNamesSection = 221 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG, 222 SectionKind::getMetadata(), "names_begin"); 223 DwarfAccelObjCSection = 224 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG, 225 SectionKind::getMetadata(), "objc_begin"); 226 // 16 character section limit... 227 DwarfAccelNamespaceSection = 228 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG, 229 SectionKind::getMetadata(), "namespac_begin"); 230 DwarfAccelTypesSection = 231 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG, 232 SectionKind::getMetadata(), "types_begin"); 233 234 DwarfSwiftASTSection = 235 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG, 236 SectionKind::getMetadata()); 237 238 DwarfAbbrevSection = 239 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG, 240 SectionKind::getMetadata(), "section_abbrev"); 241 DwarfInfoSection = 242 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG, 243 SectionKind::getMetadata(), "section_info"); 244 DwarfLineSection = 245 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG, 246 SectionKind::getMetadata(), "section_line"); 247 DwarfLineStrSection = 248 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG, 249 SectionKind::getMetadata(), "section_line_str"); 250 DwarfFrameSection = 251 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG, 252 SectionKind::getMetadata(), "section_frame"); 253 DwarfPubNamesSection = 254 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG, 255 SectionKind::getMetadata()); 256 DwarfPubTypesSection = 257 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG, 258 SectionKind::getMetadata()); 259 DwarfGnuPubNamesSection = 260 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG, 261 SectionKind::getMetadata()); 262 DwarfGnuPubTypesSection = 263 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG, 264 SectionKind::getMetadata()); 265 DwarfStrSection = 266 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG, 267 SectionKind::getMetadata(), "info_string"); 268 DwarfStrOffSection = 269 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG, 270 SectionKind::getMetadata(), "section_str_off"); 271 DwarfAddrSection = 272 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG, 273 SectionKind::getMetadata(), "section_info"); 274 DwarfLocSection = 275 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG, 276 SectionKind::getMetadata(), "section_debug_loc"); 277 DwarfLoclistsSection = 278 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG, 279 SectionKind::getMetadata(), "section_debug_loc"); 280 281 DwarfARangesSection = 282 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG, 283 SectionKind::getMetadata()); 284 DwarfRangesSection = 285 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG, 286 SectionKind::getMetadata(), "debug_range"); 287 DwarfRnglistsSection = 288 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG, 289 SectionKind::getMetadata(), "debug_range"); 290 DwarfMacinfoSection = 291 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG, 292 SectionKind::getMetadata(), "debug_macinfo"); 293 DwarfMacroSection = 294 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG, 295 SectionKind::getMetadata(), "debug_macro"); 296 DwarfDebugInlineSection = 297 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG, 298 SectionKind::getMetadata()); 299 DwarfCUIndexSection = 300 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG, 301 SectionKind::getMetadata()); 302 DwarfTUIndexSection = 303 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG, 304 SectionKind::getMetadata()); 305 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 306 0, SectionKind::getMetadata()); 307 308 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps", 309 0, SectionKind::getMetadata()); 310 311 RemarksSection = Ctx->getMachOSection( 312 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata()); 313 314 // The architecture of dsymutil makes it very difficult to copy the Swift 315 // reflection metadata sections into the __TEXT segment, so dsymutil creates 316 // these sections in the __DWARF segment instead. 317 if (!Ctx->getSwift5ReflectionSegmentName().empty()) { 318 #define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \ 319 Swift5ReflectionSections \ 320 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \ 321 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \ 322 MACHO, 0, SectionKind::getMetadata()); 323 #include "llvm/BinaryFormat/Swift.def" 324 } 325 326 TLSExtraDataSection = TLSTLVSection; 327 } 328 329 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) { 330 switch (T.getArch()) { 331 case Triple::mips: 332 case Triple::mipsel: 333 case Triple::mips64: 334 case Triple::mips64el: 335 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case 336 // since there is no R_MIPS_PC64 relocation (only a 32-bit version). 337 if (PositionIndependent && !Large) 338 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 339 else 340 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4 341 ? dwarf::DW_EH_PE_sdata4 342 : dwarf::DW_EH_PE_sdata8; 343 break; 344 case Triple::ppc64: 345 case Triple::ppc64le: 346 case Triple::aarch64: 347 case Triple::aarch64_be: 348 case Triple::x86_64: 349 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | 350 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4); 351 break; 352 case Triple::bpfel: 353 case Triple::bpfeb: 354 FDECFIEncoding = dwarf::DW_EH_PE_sdata8; 355 break; 356 case Triple::hexagon: 357 FDECFIEncoding = 358 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr; 359 break; 360 case Triple::xtensa: 361 FDECFIEncoding = dwarf::DW_EH_PE_sdata4; 362 break; 363 default: 364 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 365 break; 366 } 367 368 unsigned EHSectionType = T.getArch() == Triple::x86_64 369 ? ELF::SHT_X86_64_UNWIND 370 : ELF::SHT_PROGBITS; 371 372 // Solaris requires different flags for .eh_frame to seemingly every other 373 // platform. 374 unsigned EHSectionFlags = ELF::SHF_ALLOC; 375 if (T.isOSSolaris() && T.getArch() != Triple::x86_64) 376 EHSectionFlags |= ELF::SHF_WRITE; 377 378 // ELF 379 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS, 380 ELF::SHF_WRITE | ELF::SHF_ALLOC); 381 382 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS, 383 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC); 384 385 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS, 386 ELF::SHF_WRITE | ELF::SHF_ALLOC); 387 388 ReadOnlySection = 389 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 390 391 TLSDataSection = 392 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, 393 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); 394 395 TLSBSSSection = Ctx->getELFSection( 396 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); 397 398 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, 399 ELF::SHF_ALLOC | ELF::SHF_WRITE); 400 401 MergeableConst4Section = 402 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, 403 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4); 404 405 MergeableConst8Section = 406 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, 407 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8); 408 409 MergeableConst16Section = 410 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, 411 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16); 412 413 MergeableConst32Section = 414 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS, 415 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32); 416 417 // Exception Handling Sections. 418 419 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though 420 // it contains relocatable pointers. In PIC mode, this is probably a big 421 // runtime hit for C++ apps. Either the contents of the LSDA need to be 422 // adjusted or this should be a data section. 423 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, 424 ELF::SHF_ALLOC); 425 426 COFFDebugSymbolsSection = nullptr; 427 COFFDebugTypesSection = nullptr; 428 429 unsigned DebugSecType = ELF::SHT_PROGBITS; 430 431 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type 432 // to distinguish among sections contain DWARF and ECOFF debug formats. 433 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS. 434 if (T.isMIPS()) 435 DebugSecType = ELF::SHT_MIPS_DWARF; 436 437 // Debug Info Sections. 438 DwarfAbbrevSection = 439 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0); 440 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0); 441 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0); 442 DwarfLineStrSection = 443 Ctx->getELFSection(".debug_line_str", DebugSecType, 444 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1); 445 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0); 446 DwarfPubNamesSection = 447 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0); 448 DwarfPubTypesSection = 449 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0); 450 DwarfGnuPubNamesSection = 451 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0); 452 DwarfGnuPubTypesSection = 453 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0); 454 DwarfStrSection = 455 Ctx->getELFSection(".debug_str", DebugSecType, 456 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1); 457 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0); 458 DwarfARangesSection = 459 Ctx->getELFSection(".debug_aranges", DebugSecType, 0); 460 DwarfRangesSection = 461 Ctx->getELFSection(".debug_ranges", DebugSecType, 0); 462 DwarfMacinfoSection = 463 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0); 464 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0); 465 466 // DWARF5 Experimental Debug Info 467 468 // Accelerator Tables 469 DwarfDebugNamesSection = 470 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0); 471 DwarfAccelNamesSection = 472 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0); 473 DwarfAccelObjCSection = 474 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0); 475 DwarfAccelNamespaceSection = 476 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0); 477 DwarfAccelTypesSection = 478 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0); 479 480 // String Offset and Address Sections 481 DwarfStrOffSection = 482 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0); 483 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0); 484 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0); 485 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0); 486 487 // Fission Sections 488 DwarfInfoDWOSection = 489 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE); 490 DwarfTypesDWOSection = 491 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE); 492 DwarfAbbrevDWOSection = 493 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE); 494 DwarfStrDWOSection = Ctx->getELFSection( 495 ".debug_str.dwo", DebugSecType, 496 ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1); 497 DwarfLineDWOSection = 498 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE); 499 DwarfLocDWOSection = 500 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE); 501 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo", 502 DebugSecType, ELF::SHF_EXCLUDE); 503 DwarfRnglistsDWOSection = 504 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE); 505 DwarfMacinfoDWOSection = 506 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE); 507 DwarfMacroDWOSection = 508 Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE); 509 510 DwarfLoclistsDWOSection = 511 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE); 512 513 // DWP Sections 514 DwarfCUIndexSection = 515 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0); 516 DwarfTUIndexSection = 517 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0); 518 519 StackMapSection = 520 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 521 522 FaultMapSection = 523 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 524 525 EHFrameSection = 526 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags); 527 528 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0); 529 530 PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0); 531 PseudoProbeDescSection = 532 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0); 533 534 LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0); 535 } 536 537 void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) { 538 TextSection = 539 Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr, nullptr); 540 BSSSection = 541 Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr, nullptr); 542 PPA1Section = 543 Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(), TextSection, 544 MCConstantExpr::create(GOFF::SK_PPA1, *Ctx)); 545 ADASection = 546 Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr, nullptr); 547 } 548 549 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) { 550 EHFrameSection = 551 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 552 COFF::IMAGE_SCN_MEM_READ, 553 SectionKind::getData()); 554 555 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is 556 // used to indicate to the linker that the text segment contains thumb instructions 557 // and to set the ISA selection bit for calls accordingly. 558 const bool IsThumb = T.getArch() == Triple::thumb; 559 560 // COFF 561 BSSSection = Ctx->getCOFFSection( 562 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | 563 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE, 564 SectionKind::getBSS()); 565 TextSection = Ctx->getCOFFSection( 566 ".text", 567 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) | 568 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | 569 COFF::IMAGE_SCN_MEM_READ, 570 SectionKind::getText()); 571 DataSection = Ctx->getCOFFSection( 572 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 573 COFF::IMAGE_SCN_MEM_WRITE, 574 SectionKind::getData()); 575 ReadOnlySection = Ctx->getCOFFSection( 576 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 577 SectionKind::getReadOnly()); 578 579 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 || 580 T.getArch() == Triple::arm || T.getArch() == Triple::thumb) { 581 // On Windows with SEH, the LSDA is emitted into the .xdata section 582 LSDASection = nullptr; 583 } else { 584 LSDASection = Ctx->getCOFFSection(".gcc_except_table", 585 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 586 COFF::IMAGE_SCN_MEM_READ, 587 SectionKind::getReadOnly()); 588 } 589 590 // Debug info. 591 COFFDebugSymbolsSection = 592 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 593 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 594 COFF::IMAGE_SCN_MEM_READ), 595 SectionKind::getMetadata()); 596 COFFDebugTypesSection = 597 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 598 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 599 COFF::IMAGE_SCN_MEM_READ), 600 SectionKind::getMetadata()); 601 COFFGlobalTypeHashesSection = Ctx->getCOFFSection( 602 ".debug$H", 603 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 604 COFF::IMAGE_SCN_MEM_READ), 605 SectionKind::getMetadata()); 606 607 DwarfAbbrevSection = Ctx->getCOFFSection( 608 ".debug_abbrev", 609 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 610 COFF::IMAGE_SCN_MEM_READ, 611 SectionKind::getMetadata(), "section_abbrev"); 612 DwarfInfoSection = Ctx->getCOFFSection( 613 ".debug_info", 614 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 615 COFF::IMAGE_SCN_MEM_READ, 616 SectionKind::getMetadata(), "section_info"); 617 DwarfLineSection = Ctx->getCOFFSection( 618 ".debug_line", 619 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 620 COFF::IMAGE_SCN_MEM_READ, 621 SectionKind::getMetadata(), "section_line"); 622 DwarfLineStrSection = Ctx->getCOFFSection( 623 ".debug_line_str", 624 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 625 COFF::IMAGE_SCN_MEM_READ, 626 SectionKind::getMetadata(), "section_line_str"); 627 DwarfFrameSection = Ctx->getCOFFSection( 628 ".debug_frame", 629 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 630 COFF::IMAGE_SCN_MEM_READ, 631 SectionKind::getMetadata()); 632 DwarfPubNamesSection = Ctx->getCOFFSection( 633 ".debug_pubnames", 634 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 635 COFF::IMAGE_SCN_MEM_READ, 636 SectionKind::getMetadata()); 637 DwarfPubTypesSection = Ctx->getCOFFSection( 638 ".debug_pubtypes", 639 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 640 COFF::IMAGE_SCN_MEM_READ, 641 SectionKind::getMetadata()); 642 DwarfGnuPubNamesSection = Ctx->getCOFFSection( 643 ".debug_gnu_pubnames", 644 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 645 COFF::IMAGE_SCN_MEM_READ, 646 SectionKind::getMetadata()); 647 DwarfGnuPubTypesSection = Ctx->getCOFFSection( 648 ".debug_gnu_pubtypes", 649 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 650 COFF::IMAGE_SCN_MEM_READ, 651 SectionKind::getMetadata()); 652 DwarfStrSection = Ctx->getCOFFSection( 653 ".debug_str", 654 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 655 COFF::IMAGE_SCN_MEM_READ, 656 SectionKind::getMetadata(), "info_string"); 657 DwarfStrOffSection = Ctx->getCOFFSection( 658 ".debug_str_offsets", 659 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 660 COFF::IMAGE_SCN_MEM_READ, 661 SectionKind::getMetadata(), "section_str_off"); 662 DwarfLocSection = Ctx->getCOFFSection( 663 ".debug_loc", 664 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 665 COFF::IMAGE_SCN_MEM_READ, 666 SectionKind::getMetadata(), "section_debug_loc"); 667 DwarfLoclistsSection = Ctx->getCOFFSection( 668 ".debug_loclists", 669 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 670 COFF::IMAGE_SCN_MEM_READ, 671 SectionKind::getMetadata(), "section_debug_loclists"); 672 DwarfARangesSection = Ctx->getCOFFSection( 673 ".debug_aranges", 674 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 675 COFF::IMAGE_SCN_MEM_READ, 676 SectionKind::getMetadata()); 677 DwarfRangesSection = Ctx->getCOFFSection( 678 ".debug_ranges", 679 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 680 COFF::IMAGE_SCN_MEM_READ, 681 SectionKind::getMetadata(), "debug_range"); 682 DwarfRnglistsSection = Ctx->getCOFFSection( 683 ".debug_rnglists", 684 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 685 COFF::IMAGE_SCN_MEM_READ, 686 SectionKind::getMetadata(), "debug_rnglists"); 687 DwarfMacinfoSection = Ctx->getCOFFSection( 688 ".debug_macinfo", 689 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 690 COFF::IMAGE_SCN_MEM_READ, 691 SectionKind::getMetadata(), "debug_macinfo"); 692 DwarfMacroSection = Ctx->getCOFFSection( 693 ".debug_macro", 694 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 695 COFF::IMAGE_SCN_MEM_READ, 696 SectionKind::getMetadata(), "debug_macro"); 697 DwarfMacinfoDWOSection = Ctx->getCOFFSection( 698 ".debug_macinfo.dwo", 699 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 700 COFF::IMAGE_SCN_MEM_READ, 701 SectionKind::getMetadata(), "debug_macinfo.dwo"); 702 DwarfMacroDWOSection = Ctx->getCOFFSection( 703 ".debug_macro.dwo", 704 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 705 COFF::IMAGE_SCN_MEM_READ, 706 SectionKind::getMetadata(), "debug_macro.dwo"); 707 DwarfInfoDWOSection = Ctx->getCOFFSection( 708 ".debug_info.dwo", 709 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 710 COFF::IMAGE_SCN_MEM_READ, 711 SectionKind::getMetadata(), "section_info_dwo"); 712 DwarfTypesDWOSection = Ctx->getCOFFSection( 713 ".debug_types.dwo", 714 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 715 COFF::IMAGE_SCN_MEM_READ, 716 SectionKind::getMetadata(), "section_types_dwo"); 717 DwarfAbbrevDWOSection = Ctx->getCOFFSection( 718 ".debug_abbrev.dwo", 719 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 720 COFF::IMAGE_SCN_MEM_READ, 721 SectionKind::getMetadata(), "section_abbrev_dwo"); 722 DwarfStrDWOSection = Ctx->getCOFFSection( 723 ".debug_str.dwo", 724 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 725 COFF::IMAGE_SCN_MEM_READ, 726 SectionKind::getMetadata(), "skel_string"); 727 DwarfLineDWOSection = Ctx->getCOFFSection( 728 ".debug_line.dwo", 729 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 730 COFF::IMAGE_SCN_MEM_READ, 731 SectionKind::getMetadata()); 732 DwarfLocDWOSection = Ctx->getCOFFSection( 733 ".debug_loc.dwo", 734 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 735 COFF::IMAGE_SCN_MEM_READ, 736 SectionKind::getMetadata(), "skel_loc"); 737 DwarfStrOffDWOSection = Ctx->getCOFFSection( 738 ".debug_str_offsets.dwo", 739 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 740 COFF::IMAGE_SCN_MEM_READ, 741 SectionKind::getMetadata(), "section_str_off_dwo"); 742 DwarfAddrSection = Ctx->getCOFFSection( 743 ".debug_addr", 744 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 745 COFF::IMAGE_SCN_MEM_READ, 746 SectionKind::getMetadata(), "addr_sec"); 747 DwarfCUIndexSection = Ctx->getCOFFSection( 748 ".debug_cu_index", 749 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 750 COFF::IMAGE_SCN_MEM_READ, 751 SectionKind::getMetadata()); 752 DwarfTUIndexSection = Ctx->getCOFFSection( 753 ".debug_tu_index", 754 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 755 COFF::IMAGE_SCN_MEM_READ, 756 SectionKind::getMetadata()); 757 DwarfDebugNamesSection = Ctx->getCOFFSection( 758 ".debug_names", 759 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 760 COFF::IMAGE_SCN_MEM_READ, 761 SectionKind::getMetadata(), "debug_names_begin"); 762 DwarfAccelNamesSection = Ctx->getCOFFSection( 763 ".apple_names", 764 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 765 COFF::IMAGE_SCN_MEM_READ, 766 SectionKind::getMetadata(), "names_begin"); 767 DwarfAccelNamespaceSection = Ctx->getCOFFSection( 768 ".apple_namespaces", 769 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 770 COFF::IMAGE_SCN_MEM_READ, 771 SectionKind::getMetadata(), "namespac_begin"); 772 DwarfAccelTypesSection = Ctx->getCOFFSection( 773 ".apple_types", 774 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 775 COFF::IMAGE_SCN_MEM_READ, 776 SectionKind::getMetadata(), "types_begin"); 777 DwarfAccelObjCSection = Ctx->getCOFFSection( 778 ".apple_objc", 779 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 780 COFF::IMAGE_SCN_MEM_READ, 781 SectionKind::getMetadata(), "objc_begin"); 782 783 DrectveSection = Ctx->getCOFFSection( 784 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE, 785 SectionKind::getMetadata()); 786 787 PDataSection = Ctx->getCOFFSection( 788 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 789 SectionKind::getData()); 790 791 XDataSection = Ctx->getCOFFSection( 792 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 793 SectionKind::getData()); 794 795 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO, 796 SectionKind::getMetadata()); 797 798 GEHContSection = Ctx->getCOFFSection(".gehcont$y", 799 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 800 COFF::IMAGE_SCN_MEM_READ, 801 SectionKind::getMetadata()); 802 803 GFIDsSection = Ctx->getCOFFSection(".gfids$y", 804 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 805 COFF::IMAGE_SCN_MEM_READ, 806 SectionKind::getMetadata()); 807 808 GIATsSection = Ctx->getCOFFSection(".giats$y", 809 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 810 COFF::IMAGE_SCN_MEM_READ, 811 SectionKind::getMetadata()); 812 813 GLJMPSection = Ctx->getCOFFSection(".gljmp$y", 814 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 815 COFF::IMAGE_SCN_MEM_READ, 816 SectionKind::getMetadata()); 817 818 TLSDataSection = Ctx->getCOFFSection( 819 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 820 COFF::IMAGE_SCN_MEM_WRITE, 821 SectionKind::getData()); 822 823 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps", 824 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 825 COFF::IMAGE_SCN_MEM_READ, 826 SectionKind::getReadOnly()); 827 } 828 829 void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) { 830 // Put everything in a single binary section. 831 TextSection = Ctx->getSPIRVSection(); 832 } 833 834 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) { 835 TextSection = Ctx->getWasmSection(".text", SectionKind::getText()); 836 DataSection = Ctx->getWasmSection(".data", SectionKind::getData()); 837 838 DwarfLineSection = 839 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata()); 840 DwarfLineStrSection = 841 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(), 842 wasm::WASM_SEG_FLAG_STRINGS); 843 DwarfStrSection = Ctx->getWasmSection( 844 ".debug_str", SectionKind::getMetadata(), wasm::WASM_SEG_FLAG_STRINGS); 845 DwarfLocSection = 846 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata()); 847 DwarfAbbrevSection = 848 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata()); 849 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata()); 850 DwarfRangesSection = 851 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata()); 852 DwarfMacinfoSection = 853 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata()); 854 DwarfMacroSection = 855 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata()); 856 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 857 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 858 DwarfInfoSection = 859 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata()); 860 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata()); 861 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata()); 862 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata()); 863 DwarfGnuPubNamesSection = 864 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata()); 865 DwarfGnuPubTypesSection = 866 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata()); 867 868 DwarfDebugNamesSection = 869 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata()); 870 DwarfStrOffSection = 871 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata()); 872 DwarfAddrSection = 873 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata()); 874 DwarfRnglistsSection = 875 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata()); 876 DwarfLoclistsSection = 877 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata()); 878 879 // Fission Sections 880 DwarfInfoDWOSection = 881 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata()); 882 DwarfTypesDWOSection = 883 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata()); 884 DwarfAbbrevDWOSection = 885 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata()); 886 DwarfStrDWOSection = 887 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(), 888 wasm::WASM_SEG_FLAG_STRINGS); 889 DwarfLineDWOSection = 890 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata()); 891 DwarfLocDWOSection = 892 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata()); 893 DwarfStrOffDWOSection = 894 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata()); 895 DwarfRnglistsDWOSection = 896 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata()); 897 DwarfMacinfoDWOSection = 898 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata()); 899 DwarfMacroDWOSection = 900 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata()); 901 902 DwarfLoclistsDWOSection = 903 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata()); 904 905 // DWP Sections 906 DwarfCUIndexSection = 907 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 908 DwarfTUIndexSection = 909 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 910 911 // Wasm use data section for LSDA. 912 // TODO Consider putting each function's exception table in a separate 913 // section, as in -function-sections, to facilitate lld's --gc-section. 914 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table", 915 SectionKind::getReadOnlyWithRel()); 916 917 // TODO: Define more sections. 918 } 919 920 void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) { 921 // The default csect for program code. Functions without a specified section 922 // get placed into this csect. The choice of csect name is not a property of 923 // the ABI or object file format. For example, the XL compiler uses an unnamed 924 // csect for program code. 925 TextSection = Ctx->getXCOFFSection( 926 ".text", SectionKind::getText(), 927 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD), 928 /* MultiSymbolsAllowed*/ true); 929 930 DataSection = Ctx->getXCOFFSection( 931 ".data", SectionKind::getData(), 932 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD), 933 /* MultiSymbolsAllowed*/ true); 934 935 ReadOnlySection = Ctx->getXCOFFSection( 936 ".rodata", SectionKind::getReadOnly(), 937 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 938 /* MultiSymbolsAllowed*/ true); 939 ReadOnlySection->setAlignment(Align(4)); 940 941 ReadOnly8Section = Ctx->getXCOFFSection( 942 ".rodata.8", SectionKind::getReadOnly(), 943 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 944 /* MultiSymbolsAllowed*/ true); 945 ReadOnly8Section->setAlignment(Align(8)); 946 947 ReadOnly16Section = Ctx->getXCOFFSection( 948 ".rodata.16", SectionKind::getReadOnly(), 949 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 950 /* MultiSymbolsAllowed*/ true); 951 ReadOnly16Section->setAlignment(Align(16)); 952 953 TLSDataSection = Ctx->getXCOFFSection( 954 ".tdata", SectionKind::getThreadData(), 955 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD), 956 /* MultiSymbolsAllowed*/ true); 957 958 TOCBaseSection = Ctx->getXCOFFSection( 959 "TOC", SectionKind::getData(), 960 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0, 961 XCOFF::XTY_SD)); 962 963 // The TOC-base always has 0 size, but 4 byte alignment. 964 TOCBaseSection->setAlignment(Align(4)); 965 966 LSDASection = Ctx->getXCOFFSection( 967 ".gcc_except_table", SectionKind::getReadOnly(), 968 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, 969 XCOFF::XTY_SD)); 970 971 CompactUnwindSection = Ctx->getXCOFFSection( 972 ".eh_info_table", SectionKind::getData(), 973 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, 974 XCOFF::XTY_SD)); 975 976 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF 977 // sections, and the individual DWARF sections are distinguished by their 978 // section subtype. 979 DwarfAbbrevSection = Ctx->getXCOFFSection( 980 ".dwabrev", SectionKind::getMetadata(), 981 /* CsectProperties */ std::nullopt, 982 /* MultiSymbolsAllowed */ true, ".dwabrev", XCOFF::SSUBTYP_DWABREV); 983 984 DwarfInfoSection = Ctx->getXCOFFSection( 985 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 986 /* MultiSymbolsAllowed */ true, ".dwinfo", XCOFF::SSUBTYP_DWINFO); 987 988 DwarfLineSection = Ctx->getXCOFFSection( 989 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 990 /* MultiSymbolsAllowed */ true, ".dwline", XCOFF::SSUBTYP_DWLINE); 991 992 DwarfFrameSection = Ctx->getXCOFFSection( 993 ".dwframe", SectionKind::getMetadata(), 994 /* CsectProperties */ std::nullopt, 995 /* MultiSymbolsAllowed */ true, ".dwframe", XCOFF::SSUBTYP_DWFRAME); 996 997 DwarfPubNamesSection = Ctx->getXCOFFSection( 998 ".dwpbnms", SectionKind::getMetadata(), 999 /* CsectProperties */ std::nullopt, 1000 /* MultiSymbolsAllowed */ true, ".dwpbnms", XCOFF::SSUBTYP_DWPBNMS); 1001 1002 DwarfPubTypesSection = Ctx->getXCOFFSection( 1003 ".dwpbtyp", SectionKind::getMetadata(), 1004 /* CsectProperties */ std::nullopt, 1005 /* MultiSymbolsAllowed */ true, ".dwpbtyp", XCOFF::SSUBTYP_DWPBTYP); 1006 1007 DwarfStrSection = Ctx->getXCOFFSection( 1008 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 1009 /* MultiSymbolsAllowed */ true, ".dwstr", XCOFF::SSUBTYP_DWSTR); 1010 1011 DwarfLocSection = Ctx->getXCOFFSection( 1012 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 1013 /* MultiSymbolsAllowed */ true, ".dwloc", XCOFF::SSUBTYP_DWLOC); 1014 1015 DwarfARangesSection = Ctx->getXCOFFSection( 1016 ".dwarnge", SectionKind::getMetadata(), 1017 /* CsectProperties */ std::nullopt, 1018 /* MultiSymbolsAllowed */ true, ".dwarnge", XCOFF::SSUBTYP_DWARNGE); 1019 1020 DwarfRangesSection = Ctx->getXCOFFSection( 1021 ".dwrnges", SectionKind::getMetadata(), 1022 /* CsectProperties */ std::nullopt, 1023 /* MultiSymbolsAllowed */ true, ".dwrnges", XCOFF::SSUBTYP_DWRNGES); 1024 1025 DwarfMacinfoSection = Ctx->getXCOFFSection( 1026 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 1027 /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC); 1028 } 1029 1030 void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) { 1031 // At the moment the DXBC section should end up empty. 1032 TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText()); 1033 } 1034 1035 MCObjectFileInfo::~MCObjectFileInfo() = default; 1036 1037 void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, 1038 bool LargeCodeModel) { 1039 PositionIndependent = PIC; 1040 Ctx = &MCCtx; 1041 1042 // Common. 1043 SupportsWeakOmittedEHFrame = true; 1044 SupportsCompactUnwindWithoutEHFrame = false; 1045 OmitDwarfIfHaveCompactUnwind = false; 1046 1047 FDECFIEncoding = dwarf::DW_EH_PE_absptr; 1048 1049 CompactUnwindDwarfEHFrameOnly = 0; 1050 1051 EHFrameSection = nullptr; // Created on demand. 1052 CompactUnwindSection = nullptr; // Used only by selected targets. 1053 DwarfAccelNamesSection = nullptr; // Used only by selected targets. 1054 DwarfAccelObjCSection = nullptr; // Used only by selected targets. 1055 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. 1056 DwarfAccelTypesSection = nullptr; // Used only by selected targets. 1057 1058 Triple TheTriple = Ctx->getTargetTriple(); 1059 switch (Ctx->getObjectFileType()) { 1060 case MCContext::IsMachO: 1061 initMachOMCObjectFileInfo(TheTriple); 1062 break; 1063 case MCContext::IsCOFF: 1064 initCOFFMCObjectFileInfo(TheTriple); 1065 break; 1066 case MCContext::IsELF: 1067 initELFMCObjectFileInfo(TheTriple, LargeCodeModel); 1068 break; 1069 case MCContext::IsGOFF: 1070 initGOFFMCObjectFileInfo(TheTriple); 1071 break; 1072 case MCContext::IsSPIRV: 1073 initSPIRVMCObjectFileInfo(TheTriple); 1074 break; 1075 case MCContext::IsWasm: 1076 initWasmMCObjectFileInfo(TheTriple); 1077 break; 1078 case MCContext::IsXCOFF: 1079 initXCOFFMCObjectFileInfo(TheTriple); 1080 break; 1081 case MCContext::IsDXContainer: 1082 initDXContainerObjectFileInfo(TheTriple); 1083 break; 1084 } 1085 } 1086 1087 MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, 1088 uint64_t Hash) const { 1089 switch (Ctx->getTargetTriple().getObjectFormat()) { 1090 case Triple::ELF: 1091 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, 1092 utostr(Hash), /*IsComdat=*/true); 1093 case Triple::Wasm: 1094 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0, 1095 utostr(Hash), MCContext::GenericSectionID); 1096 case Triple::MachO: 1097 case Triple::COFF: 1098 case Triple::GOFF: 1099 case Triple::SPIRV: 1100 case Triple::XCOFF: 1101 case Triple::DXContainer: 1102 case Triple::UnknownObjectFormat: 1103 report_fatal_error("Cannot get DWARF comdat section for this object file " 1104 "format: not implemented."); 1105 break; 1106 } 1107 llvm_unreachable("Unknown ObjectFormatType"); 1108 } 1109 1110 MCSection * 1111 MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { 1112 if ((Ctx->getObjectFileType() != MCContext::IsELF) || 1113 Ctx->getTargetTriple().isPS4()) 1114 return StackSizesSection; 1115 1116 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1117 unsigned Flags = ELF::SHF_LINK_ORDER; 1118 StringRef GroupName; 1119 if (const MCSymbol *Group = ElfSec.getGroup()) { 1120 GroupName = Group->getName(); 1121 Flags |= ELF::SHF_GROUP; 1122 } 1123 1124 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, 1125 GroupName, true, ElfSec.getUniqueID(), 1126 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1127 } 1128 1129 MCSection * 1130 MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { 1131 if (Ctx->getObjectFileType() != MCContext::IsELF) 1132 return nullptr; 1133 1134 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1135 unsigned Flags = ELF::SHF_LINK_ORDER; 1136 StringRef GroupName; 1137 if (const MCSymbol *Group = ElfSec.getGroup()) { 1138 GroupName = Group->getName(); 1139 Flags |= ELF::SHF_GROUP; 1140 } 1141 1142 // Use the text section's begin symbol and unique ID to create a separate 1143 // .llvm_bb_addr_map section associated with every unique text section. 1144 return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, 1145 Flags, 0, GroupName, true, ElfSec.getUniqueID(), 1146 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1147 } 1148 1149 MCSection * 1150 MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const { 1151 if (Ctx->getObjectFileType() != MCContext::IsELF) 1152 return nullptr; 1153 1154 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1155 unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC; 1156 StringRef GroupName; 1157 if (const MCSymbol *Group = ElfSec.getGroup()) { 1158 GroupName = Group->getName(); 1159 Flags |= ELF::SHF_GROUP; 1160 } 1161 1162 return Ctx->getELFSection(".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, 1163 GroupName, 1164 /*IsComdat=*/true, ElfSec.getUniqueID(), 1165 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1166 } 1167 1168 MCSection * 1169 MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const { 1170 if (Ctx->getObjectFileType() != MCContext::IsELF) 1171 return PseudoProbeSection; 1172 1173 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1174 unsigned Flags = ELF::SHF_LINK_ORDER; 1175 StringRef GroupName; 1176 if (const MCSymbol *Group = ElfSec.getGroup()) { 1177 GroupName = Group->getName(); 1178 Flags |= ELF::SHF_GROUP; 1179 } 1180 1181 return Ctx->getELFSection(PseudoProbeSection->getName(), ELF::SHT_PROGBITS, 1182 Flags, 0, GroupName, true, ElfSec.getUniqueID(), 1183 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1184 } 1185 1186 MCSection * 1187 MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { 1188 if (Ctx->getObjectFileType() == MCContext::IsELF) { 1189 // Create a separate comdat group for each function's descriptor in order 1190 // for the linker to deduplicate. The duplication, must be from different 1191 // tranlation unit, can come from: 1192 // 1. Inline functions defined in header files; 1193 // 2. ThinLTO imported funcions; 1194 // 3. Weak-linkage definitions. 1195 // Use a concatenation of the section name and the function name as the 1196 // group name so that descriptor-only groups won't be folded with groups of 1197 // code. 1198 if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) { 1199 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); 1200 auto Flags = S->getFlags() | ELF::SHF_GROUP; 1201 return Ctx->getELFSection(S->getName(), S->getType(), Flags, 1202 S->getEntrySize(), 1203 S->getName() + "_" + FuncName, 1204 /*IsComdat=*/true); 1205 } 1206 } 1207 return PseudoProbeDescSection; 1208 } 1209 1210 MCSection *MCObjectFileInfo::getLLVMStatsSection() const { 1211 return LLVMStatsSection; 1212 } 1213 1214 MCSection *MCObjectFileInfo::getPCSection(StringRef Name, 1215 const MCSection *TextSec) const { 1216 if (Ctx->getObjectFileType() != MCContext::IsELF) 1217 return nullptr; 1218 1219 // SHF_WRITE for relocations, and let user post-process data in-place. 1220 unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER; 1221 1222 if (!TextSec) 1223 TextSec = getTextSection(); 1224 1225 StringRef GroupName; 1226 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec); 1227 if (const MCSymbol *Group = ElfSec.getGroup()) { 1228 GroupName = Group->getName(); 1229 Flags |= ELF::SHF_GROUP; 1230 } 1231 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, 1232 ElfSec.getUniqueID(), 1233 cast<MCSymbolELF>(TextSec->getBeginSymbol())); 1234 } 1235