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