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