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