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 = 527 Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr, nullptr); 528 BSSSection = 529 Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr, nullptr); 530 PPA1Section = 531 Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(), TextSection, 532 MCConstantExpr::create(GOFF::SK_PPA1, *Ctx)); 533 } 534 535 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) { 536 EHFrameSection = 537 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 538 COFF::IMAGE_SCN_MEM_READ, 539 SectionKind::getData()); 540 541 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is 542 // used to indicate to the linker that the text segment contains thumb instructions 543 // and to set the ISA selection bit for calls accordingly. 544 const bool IsThumb = T.getArch() == Triple::thumb; 545 546 CommDirectiveSupportsAlignment = true; 547 548 // COFF 549 BSSSection = Ctx->getCOFFSection( 550 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | 551 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE, 552 SectionKind::getBSS()); 553 TextSection = Ctx->getCOFFSection( 554 ".text", 555 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) | 556 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | 557 COFF::IMAGE_SCN_MEM_READ, 558 SectionKind::getText()); 559 DataSection = Ctx->getCOFFSection( 560 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 561 COFF::IMAGE_SCN_MEM_WRITE, 562 SectionKind::getData()); 563 ReadOnlySection = Ctx->getCOFFSection( 564 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 565 SectionKind::getReadOnly()); 566 567 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) { 568 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section 569 LSDASection = nullptr; 570 } else { 571 LSDASection = Ctx->getCOFFSection(".gcc_except_table", 572 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 573 COFF::IMAGE_SCN_MEM_READ, 574 SectionKind::getReadOnly()); 575 } 576 577 // Debug info. 578 COFFDebugSymbolsSection = 579 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 580 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 581 COFF::IMAGE_SCN_MEM_READ), 582 SectionKind::getMetadata()); 583 COFFDebugTypesSection = 584 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 585 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 586 COFF::IMAGE_SCN_MEM_READ), 587 SectionKind::getMetadata()); 588 COFFGlobalTypeHashesSection = Ctx->getCOFFSection( 589 ".debug$H", 590 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 591 COFF::IMAGE_SCN_MEM_READ), 592 SectionKind::getMetadata()); 593 594 DwarfAbbrevSection = Ctx->getCOFFSection( 595 ".debug_abbrev", 596 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 597 COFF::IMAGE_SCN_MEM_READ, 598 SectionKind::getMetadata(), "section_abbrev"); 599 DwarfInfoSection = Ctx->getCOFFSection( 600 ".debug_info", 601 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 602 COFF::IMAGE_SCN_MEM_READ, 603 SectionKind::getMetadata(), "section_info"); 604 DwarfLineSection = Ctx->getCOFFSection( 605 ".debug_line", 606 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 607 COFF::IMAGE_SCN_MEM_READ, 608 SectionKind::getMetadata(), "section_line"); 609 DwarfLineStrSection = Ctx->getCOFFSection( 610 ".debug_line_str", 611 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 612 COFF::IMAGE_SCN_MEM_READ, 613 SectionKind::getMetadata(), "section_line_str"); 614 DwarfFrameSection = Ctx->getCOFFSection( 615 ".debug_frame", 616 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 617 COFF::IMAGE_SCN_MEM_READ, 618 SectionKind::getMetadata()); 619 DwarfPubNamesSection = Ctx->getCOFFSection( 620 ".debug_pubnames", 621 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 622 COFF::IMAGE_SCN_MEM_READ, 623 SectionKind::getMetadata()); 624 DwarfPubTypesSection = Ctx->getCOFFSection( 625 ".debug_pubtypes", 626 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 627 COFF::IMAGE_SCN_MEM_READ, 628 SectionKind::getMetadata()); 629 DwarfGnuPubNamesSection = Ctx->getCOFFSection( 630 ".debug_gnu_pubnames", 631 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 632 COFF::IMAGE_SCN_MEM_READ, 633 SectionKind::getMetadata()); 634 DwarfGnuPubTypesSection = Ctx->getCOFFSection( 635 ".debug_gnu_pubtypes", 636 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 637 COFF::IMAGE_SCN_MEM_READ, 638 SectionKind::getMetadata()); 639 DwarfStrSection = Ctx->getCOFFSection( 640 ".debug_str", 641 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 642 COFF::IMAGE_SCN_MEM_READ, 643 SectionKind::getMetadata(), "info_string"); 644 DwarfStrOffSection = Ctx->getCOFFSection( 645 ".debug_str_offsets", 646 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 647 COFF::IMAGE_SCN_MEM_READ, 648 SectionKind::getMetadata(), "section_str_off"); 649 DwarfLocSection = Ctx->getCOFFSection( 650 ".debug_loc", 651 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 652 COFF::IMAGE_SCN_MEM_READ, 653 SectionKind::getMetadata(), "section_debug_loc"); 654 DwarfLoclistsSection = Ctx->getCOFFSection( 655 ".debug_loclists", 656 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 657 COFF::IMAGE_SCN_MEM_READ, 658 SectionKind::getMetadata(), "section_debug_loclists"); 659 DwarfARangesSection = Ctx->getCOFFSection( 660 ".debug_aranges", 661 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 662 COFF::IMAGE_SCN_MEM_READ, 663 SectionKind::getMetadata()); 664 DwarfRangesSection = Ctx->getCOFFSection( 665 ".debug_ranges", 666 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 667 COFF::IMAGE_SCN_MEM_READ, 668 SectionKind::getMetadata(), "debug_range"); 669 DwarfRnglistsSection = Ctx->getCOFFSection( 670 ".debug_rnglists", 671 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 672 COFF::IMAGE_SCN_MEM_READ, 673 SectionKind::getMetadata(), "debug_rnglists"); 674 DwarfMacinfoSection = Ctx->getCOFFSection( 675 ".debug_macinfo", 676 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 677 COFF::IMAGE_SCN_MEM_READ, 678 SectionKind::getMetadata(), "debug_macinfo"); 679 DwarfMacroSection = Ctx->getCOFFSection( 680 ".debug_macro", 681 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 682 COFF::IMAGE_SCN_MEM_READ, 683 SectionKind::getMetadata(), "debug_macro"); 684 DwarfMacinfoDWOSection = Ctx->getCOFFSection( 685 ".debug_macinfo.dwo", 686 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 687 COFF::IMAGE_SCN_MEM_READ, 688 SectionKind::getMetadata(), "debug_macinfo.dwo"); 689 DwarfMacroDWOSection = Ctx->getCOFFSection( 690 ".debug_macro.dwo", 691 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 692 COFF::IMAGE_SCN_MEM_READ, 693 SectionKind::getMetadata(), "debug_macro.dwo"); 694 DwarfInfoDWOSection = Ctx->getCOFFSection( 695 ".debug_info.dwo", 696 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 697 COFF::IMAGE_SCN_MEM_READ, 698 SectionKind::getMetadata(), "section_info_dwo"); 699 DwarfTypesDWOSection = Ctx->getCOFFSection( 700 ".debug_types.dwo", 701 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 702 COFF::IMAGE_SCN_MEM_READ, 703 SectionKind::getMetadata(), "section_types_dwo"); 704 DwarfAbbrevDWOSection = Ctx->getCOFFSection( 705 ".debug_abbrev.dwo", 706 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 707 COFF::IMAGE_SCN_MEM_READ, 708 SectionKind::getMetadata(), "section_abbrev_dwo"); 709 DwarfStrDWOSection = Ctx->getCOFFSection( 710 ".debug_str.dwo", 711 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 712 COFF::IMAGE_SCN_MEM_READ, 713 SectionKind::getMetadata(), "skel_string"); 714 DwarfLineDWOSection = Ctx->getCOFFSection( 715 ".debug_line.dwo", 716 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 717 COFF::IMAGE_SCN_MEM_READ, 718 SectionKind::getMetadata()); 719 DwarfLocDWOSection = Ctx->getCOFFSection( 720 ".debug_loc.dwo", 721 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 722 COFF::IMAGE_SCN_MEM_READ, 723 SectionKind::getMetadata(), "skel_loc"); 724 DwarfStrOffDWOSection = Ctx->getCOFFSection( 725 ".debug_str_offsets.dwo", 726 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 727 COFF::IMAGE_SCN_MEM_READ, 728 SectionKind::getMetadata(), "section_str_off_dwo"); 729 DwarfAddrSection = Ctx->getCOFFSection( 730 ".debug_addr", 731 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 732 COFF::IMAGE_SCN_MEM_READ, 733 SectionKind::getMetadata(), "addr_sec"); 734 DwarfCUIndexSection = Ctx->getCOFFSection( 735 ".debug_cu_index", 736 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 737 COFF::IMAGE_SCN_MEM_READ, 738 SectionKind::getMetadata()); 739 DwarfTUIndexSection = Ctx->getCOFFSection( 740 ".debug_tu_index", 741 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 742 COFF::IMAGE_SCN_MEM_READ, 743 SectionKind::getMetadata()); 744 DwarfDebugNamesSection = Ctx->getCOFFSection( 745 ".debug_names", 746 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 747 COFF::IMAGE_SCN_MEM_READ, 748 SectionKind::getMetadata(), "debug_names_begin"); 749 DwarfAccelNamesSection = Ctx->getCOFFSection( 750 ".apple_names", 751 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 752 COFF::IMAGE_SCN_MEM_READ, 753 SectionKind::getMetadata(), "names_begin"); 754 DwarfAccelNamespaceSection = Ctx->getCOFFSection( 755 ".apple_namespaces", 756 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 757 COFF::IMAGE_SCN_MEM_READ, 758 SectionKind::getMetadata(), "namespac_begin"); 759 DwarfAccelTypesSection = Ctx->getCOFFSection( 760 ".apple_types", 761 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 762 COFF::IMAGE_SCN_MEM_READ, 763 SectionKind::getMetadata(), "types_begin"); 764 DwarfAccelObjCSection = Ctx->getCOFFSection( 765 ".apple_objc", 766 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 767 COFF::IMAGE_SCN_MEM_READ, 768 SectionKind::getMetadata(), "objc_begin"); 769 770 DrectveSection = Ctx->getCOFFSection( 771 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE, 772 SectionKind::getMetadata()); 773 774 PDataSection = Ctx->getCOFFSection( 775 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 776 SectionKind::getData()); 777 778 XDataSection = Ctx->getCOFFSection( 779 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 780 SectionKind::getData()); 781 782 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO, 783 SectionKind::getMetadata()); 784 785 GEHContSection = Ctx->getCOFFSection(".gehcont$y", 786 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 787 COFF::IMAGE_SCN_MEM_READ, 788 SectionKind::getMetadata()); 789 790 GFIDsSection = Ctx->getCOFFSection(".gfids$y", 791 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 792 COFF::IMAGE_SCN_MEM_READ, 793 SectionKind::getMetadata()); 794 795 GIATsSection = Ctx->getCOFFSection(".giats$y", 796 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 797 COFF::IMAGE_SCN_MEM_READ, 798 SectionKind::getMetadata()); 799 800 GLJMPSection = Ctx->getCOFFSection(".gljmp$y", 801 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 802 COFF::IMAGE_SCN_MEM_READ, 803 SectionKind::getMetadata()); 804 805 TLSDataSection = Ctx->getCOFFSection( 806 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 807 COFF::IMAGE_SCN_MEM_WRITE, 808 SectionKind::getData()); 809 810 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps", 811 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 812 COFF::IMAGE_SCN_MEM_READ, 813 SectionKind::getReadOnly()); 814 } 815 816 void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) { 817 // Put everything in a single binary section. 818 TextSection = Ctx->getSPIRVSection(); 819 } 820 821 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) { 822 TextSection = Ctx->getWasmSection(".text", SectionKind::getText()); 823 DataSection = Ctx->getWasmSection(".data", SectionKind::getData()); 824 825 DwarfLineSection = 826 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata()); 827 DwarfLineStrSection = 828 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(), 829 wasm::WASM_SEG_FLAG_STRINGS); 830 DwarfStrSection = Ctx->getWasmSection( 831 ".debug_str", SectionKind::getMetadata(), wasm::WASM_SEG_FLAG_STRINGS); 832 DwarfLocSection = 833 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata()); 834 DwarfAbbrevSection = 835 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata()); 836 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata()); 837 DwarfRangesSection = 838 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata()); 839 DwarfMacinfoSection = 840 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata()); 841 DwarfMacroSection = 842 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata()); 843 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 844 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 845 DwarfInfoSection = 846 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata()); 847 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata()); 848 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata()); 849 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata()); 850 DwarfGnuPubNamesSection = 851 Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata()); 852 DwarfGnuPubTypesSection = 853 Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata()); 854 855 DwarfDebugNamesSection = 856 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata()); 857 DwarfStrOffSection = 858 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata()); 859 DwarfAddrSection = 860 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata()); 861 DwarfRnglistsSection = 862 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata()); 863 DwarfLoclistsSection = 864 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata()); 865 866 // Fission Sections 867 DwarfInfoDWOSection = 868 Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata()); 869 DwarfTypesDWOSection = 870 Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata()); 871 DwarfAbbrevDWOSection = 872 Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata()); 873 DwarfStrDWOSection = 874 Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(), 875 wasm::WASM_SEG_FLAG_STRINGS); 876 DwarfLineDWOSection = 877 Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata()); 878 DwarfLocDWOSection = 879 Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata()); 880 DwarfStrOffDWOSection = 881 Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata()); 882 DwarfRnglistsDWOSection = 883 Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata()); 884 DwarfMacinfoDWOSection = 885 Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata()); 886 DwarfMacroDWOSection = 887 Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata()); 888 889 DwarfLoclistsDWOSection = 890 Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata()); 891 892 // DWP Sections 893 DwarfCUIndexSection = 894 Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 895 DwarfTUIndexSection = 896 Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 897 898 // Wasm use data section for LSDA. 899 // TODO Consider putting each function's exception table in a separate 900 // section, as in -function-sections, to facilitate lld's --gc-section. 901 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table", 902 SectionKind::getReadOnlyWithRel()); 903 904 // TODO: Define more sections. 905 } 906 907 void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) { 908 // The default csect for program code. Functions without a specified section 909 // get placed into this csect. The choice of csect name is not a property of 910 // the ABI or object file format. For example, the XL compiler uses an unnamed 911 // csect for program code. 912 TextSection = Ctx->getXCOFFSection( 913 ".text", SectionKind::getText(), 914 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD), 915 /* MultiSymbolsAllowed*/ true); 916 917 DataSection = Ctx->getXCOFFSection( 918 ".data", SectionKind::getData(), 919 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD), 920 /* MultiSymbolsAllowed*/ true); 921 922 ReadOnlySection = Ctx->getXCOFFSection( 923 ".rodata", SectionKind::getReadOnly(), 924 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 925 /* MultiSymbolsAllowed*/ true); 926 ReadOnlySection->setAlignment(Align(4)); 927 928 ReadOnly8Section = Ctx->getXCOFFSection( 929 ".rodata.8", SectionKind::getReadOnly(), 930 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 931 /* MultiSymbolsAllowed*/ true); 932 ReadOnly8Section->setAlignment(Align(8)); 933 934 ReadOnly16Section = Ctx->getXCOFFSection( 935 ".rodata.16", SectionKind::getReadOnly(), 936 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 937 /* MultiSymbolsAllowed*/ true); 938 ReadOnly16Section->setAlignment(Align(16)); 939 940 TLSDataSection = Ctx->getXCOFFSection( 941 ".tdata", SectionKind::getThreadData(), 942 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD), 943 /* MultiSymbolsAllowed*/ true); 944 945 TOCBaseSection = Ctx->getXCOFFSection( 946 "TOC", SectionKind::getData(), 947 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0, 948 XCOFF::XTY_SD)); 949 950 // The TOC-base always has 0 size, but 4 byte alignment. 951 TOCBaseSection->setAlignment(Align(4)); 952 953 LSDASection = Ctx->getXCOFFSection( 954 ".gcc_except_table", SectionKind::getReadOnly(), 955 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, 956 XCOFF::XTY_SD)); 957 958 CompactUnwindSection = Ctx->getXCOFFSection( 959 ".eh_info_table", SectionKind::getData(), 960 XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, 961 XCOFF::XTY_SD)); 962 963 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF 964 // sections, and the individual DWARF sections are distinguished by their 965 // section subtype. 966 DwarfAbbrevSection = Ctx->getXCOFFSection( 967 ".dwabrev", SectionKind::getMetadata(), /* CsectProperties */ None, 968 /* MultiSymbolsAllowed */ true, ".dwabrev", XCOFF::SSUBTYP_DWABREV); 969 970 DwarfInfoSection = Ctx->getXCOFFSection( 971 ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ None, 972 /* MultiSymbolsAllowed */ true, ".dwinfo", XCOFF::SSUBTYP_DWINFO); 973 974 DwarfLineSection = Ctx->getXCOFFSection( 975 ".dwline", SectionKind::getMetadata(), /* CsectProperties */ None, 976 /* MultiSymbolsAllowed */ true, ".dwline", XCOFF::SSUBTYP_DWLINE); 977 978 DwarfFrameSection = Ctx->getXCOFFSection( 979 ".dwframe", SectionKind::getMetadata(), /* CsectProperties */ None, 980 /* MultiSymbolsAllowed */ true, ".dwframe", XCOFF::SSUBTYP_DWFRAME); 981 982 DwarfPubNamesSection = Ctx->getXCOFFSection( 983 ".dwpbnms", SectionKind::getMetadata(), /* CsectProperties */ None, 984 /* MultiSymbolsAllowed */ true, ".dwpbnms", XCOFF::SSUBTYP_DWPBNMS); 985 986 DwarfPubTypesSection = Ctx->getXCOFFSection( 987 ".dwpbtyp", SectionKind::getMetadata(), /* CsectProperties */ None, 988 /* MultiSymbolsAllowed */ true, ".dwpbtyp", XCOFF::SSUBTYP_DWPBTYP); 989 990 DwarfStrSection = Ctx->getXCOFFSection( 991 ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ None, 992 /* MultiSymbolsAllowed */ true, ".dwstr", XCOFF::SSUBTYP_DWSTR); 993 994 DwarfLocSection = Ctx->getXCOFFSection( 995 ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ None, 996 /* MultiSymbolsAllowed */ true, ".dwloc", XCOFF::SSUBTYP_DWLOC); 997 998 DwarfARangesSection = Ctx->getXCOFFSection( 999 ".dwarnge", SectionKind::getMetadata(), /* CsectProperties */ None, 1000 /* MultiSymbolsAllowed */ true, ".dwarnge", XCOFF::SSUBTYP_DWARNGE); 1001 1002 DwarfRangesSection = Ctx->getXCOFFSection( 1003 ".dwrnges", SectionKind::getMetadata(), /* CsectProperties */ None, 1004 /* MultiSymbolsAllowed */ true, ".dwrnges", XCOFF::SSUBTYP_DWRNGES); 1005 1006 DwarfMacinfoSection = Ctx->getXCOFFSection( 1007 ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ None, 1008 /* MultiSymbolsAllowed */ true, ".dwmac", XCOFF::SSUBTYP_DWMAC); 1009 } 1010 1011 MCObjectFileInfo::~MCObjectFileInfo() = default; 1012 1013 void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, 1014 bool LargeCodeModel) { 1015 PositionIndependent = PIC; 1016 Ctx = &MCCtx; 1017 1018 // Common. 1019 CommDirectiveSupportsAlignment = true; 1020 SupportsWeakOmittedEHFrame = true; 1021 SupportsCompactUnwindWithoutEHFrame = false; 1022 OmitDwarfIfHaveCompactUnwind = false; 1023 1024 FDECFIEncoding = dwarf::DW_EH_PE_absptr; 1025 1026 CompactUnwindDwarfEHFrameOnly = 0; 1027 1028 EHFrameSection = nullptr; // Created on demand. 1029 CompactUnwindSection = nullptr; // Used only by selected targets. 1030 DwarfAccelNamesSection = nullptr; // Used only by selected targets. 1031 DwarfAccelObjCSection = nullptr; // Used only by selected targets. 1032 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. 1033 DwarfAccelTypesSection = nullptr; // Used only by selected targets. 1034 1035 Triple TheTriple = Ctx->getTargetTriple(); 1036 switch (Ctx->getObjectFileType()) { 1037 case MCContext::IsMachO: 1038 initMachOMCObjectFileInfo(TheTriple); 1039 break; 1040 case MCContext::IsCOFF: 1041 initCOFFMCObjectFileInfo(TheTriple); 1042 break; 1043 case MCContext::IsELF: 1044 initELFMCObjectFileInfo(TheTriple, LargeCodeModel); 1045 break; 1046 case MCContext::IsGOFF: 1047 initGOFFMCObjectFileInfo(TheTriple); 1048 break; 1049 case MCContext::IsSPIRV: 1050 initSPIRVMCObjectFileInfo(TheTriple); 1051 break; 1052 case MCContext::IsWasm: 1053 initWasmMCObjectFileInfo(TheTriple); 1054 break; 1055 case MCContext::IsXCOFF: 1056 initXCOFFMCObjectFileInfo(TheTriple); 1057 break; 1058 case MCContext::IsDXContainer: 1059 break; 1060 } 1061 } 1062 1063 MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, 1064 uint64_t Hash) const { 1065 switch (Ctx->getTargetTriple().getObjectFormat()) { 1066 case Triple::ELF: 1067 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, 1068 utostr(Hash), /*IsComdat=*/true); 1069 case Triple::Wasm: 1070 return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0, 1071 utostr(Hash), MCContext::GenericSectionID); 1072 case Triple::MachO: 1073 case Triple::COFF: 1074 case Triple::GOFF: 1075 case Triple::SPIRV: 1076 case Triple::XCOFF: 1077 case Triple::DXContainer: 1078 case Triple::UnknownObjectFormat: 1079 report_fatal_error("Cannot get DWARF comdat section for this object file " 1080 "format: not implemented."); 1081 break; 1082 } 1083 llvm_unreachable("Unknown ObjectFormatType"); 1084 } 1085 1086 MCSection * 1087 MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { 1088 if (Ctx->getObjectFileType() != MCContext::IsELF) 1089 return StackSizesSection; 1090 1091 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1092 unsigned Flags = ELF::SHF_LINK_ORDER; 1093 StringRef GroupName; 1094 if (const MCSymbol *Group = ElfSec.getGroup()) { 1095 GroupName = Group->getName(); 1096 Flags |= ELF::SHF_GROUP; 1097 } 1098 1099 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, 1100 GroupName, true, ElfSec.getUniqueID(), 1101 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1102 } 1103 1104 MCSection * 1105 MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { 1106 if (Ctx->getObjectFileType() != MCContext::IsELF) 1107 return nullptr; 1108 1109 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1110 unsigned Flags = ELF::SHF_LINK_ORDER; 1111 StringRef GroupName; 1112 if (const MCSymbol *Group = ElfSec.getGroup()) { 1113 GroupName = Group->getName(); 1114 Flags |= ELF::SHF_GROUP; 1115 } 1116 1117 // Use the text section's begin symbol and unique ID to create a separate 1118 // .llvm_bb_addr_map section associated with every unique text section. 1119 return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, 1120 Flags, 0, GroupName, true, ElfSec.getUniqueID(), 1121 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1122 } 1123 1124 MCSection * 1125 MCObjectFileInfo::getPseudoProbeSection(const MCSection *TextSec) const { 1126 if (Ctx->getObjectFileType() == MCContext::IsELF) { 1127 const auto *ElfSec = static_cast<const MCSectionELF *>(TextSec); 1128 // Create a separate section for probes that comes with a comdat function. 1129 if (const MCSymbol *Group = ElfSec->getGroup()) { 1130 auto *S = static_cast<MCSectionELF *>(PseudoProbeSection); 1131 auto Flags = S->getFlags() | ELF::SHF_GROUP; 1132 return Ctx->getELFSection(S->getName(), S->getType(), Flags, 1133 S->getEntrySize(), Group->getName(), 1134 /*IsComdat=*/true); 1135 } 1136 } 1137 return PseudoProbeSection; 1138 } 1139 1140 MCSection * 1141 MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { 1142 if (Ctx->getObjectFileType() == MCContext::IsELF) { 1143 // Create a separate comdat group for each function's descriptor in order 1144 // for the linker to deduplicate. The duplication, must be from different 1145 // tranlation unit, can come from: 1146 // 1. Inline functions defined in header files; 1147 // 2. ThinLTO imported funcions; 1148 // 3. Weak-linkage definitions. 1149 // Use a concatenation of the section name and the function name as the 1150 // group name so that descriptor-only groups won't be folded with groups of 1151 // code. 1152 if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) { 1153 auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); 1154 auto Flags = S->getFlags() | ELF::SHF_GROUP; 1155 return Ctx->getELFSection(S->getName(), S->getType(), Flags, 1156 S->getEntrySize(), 1157 S->getName() + "_" + FuncName, 1158 /*IsComdat=*/true); 1159 } 1160 } 1161 return PseudoProbeDescSection; 1162 } 1163