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/MC/MCAsmInfo.h" 15 #include "llvm/MC/MCContext.h" 16 #include "llvm/MC/MCSection.h" 17 #include "llvm/MC/MCSectionCOFF.h" 18 #include "llvm/MC/MCSectionELF.h" 19 #include "llvm/MC/MCSectionMachO.h" 20 #include "llvm/MC/MCSectionWasm.h" 21 #include "llvm/MC/MCSectionXCOFF.h" 22 23 using namespace llvm; 24 25 static bool useCompactUnwind(const Triple &T) { 26 // Only on darwin. 27 if (!T.isOSDarwin()) 28 return false; 29 30 // aarch64 always has it. 31 if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) 32 return true; 33 34 // armv7k always has it. 35 if (T.isWatchABI()) 36 return true; 37 38 // Use it on newer version of OS X. 39 if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) 40 return true; 41 42 // And the iOS simulator. 43 if (T.isiOS() && T.isX86()) 44 return true; 45 46 return false; 47 } 48 49 void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { 50 // MachO 51 SupportsWeakOmittedEHFrame = false; 52 53 EHFrameSection = Ctx->getMachOSection( 54 "__TEXT", "__eh_frame", 55 MachO::S_COALESCED | MachO::S_ATTR_NO_TOC | 56 MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT, 57 SectionKind::getReadOnly()); 58 59 if (T.isOSDarwin() && 60 (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)) 61 SupportsCompactUnwindWithoutEHFrame = true; 62 63 if (T.isWatchABI()) 64 OmitDwarfIfHaveCompactUnwind = true; 65 66 FDECFIEncoding = dwarf::DW_EH_PE_pcrel; 67 68 // .comm doesn't support alignment before Leopard. 69 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 5)) 70 CommDirectiveSupportsAlignment = false; 71 72 TextSection // .text 73 = Ctx->getMachOSection("__TEXT", "__text", 74 MachO::S_ATTR_PURE_INSTRUCTIONS, 75 SectionKind::getText()); 76 DataSection // .data 77 = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData()); 78 79 // BSSSection might not be expected initialized on msvc. 80 BSSSection = nullptr; 81 82 TLSDataSection // .tdata 83 = Ctx->getMachOSection("__DATA", "__thread_data", 84 MachO::S_THREAD_LOCAL_REGULAR, 85 SectionKind::getData()); 86 TLSBSSSection // .tbss 87 = Ctx->getMachOSection("__DATA", "__thread_bss", 88 MachO::S_THREAD_LOCAL_ZEROFILL, 89 SectionKind::getThreadBSS()); 90 91 // TODO: Verify datarel below. 92 TLSTLVSection // .tlv 93 = Ctx->getMachOSection("__DATA", "__thread_vars", 94 MachO::S_THREAD_LOCAL_VARIABLES, 95 SectionKind::getData()); 96 97 TLSThreadInitSection = Ctx->getMachOSection( 98 "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 99 SectionKind::getData()); 100 101 CStringSection // .cstring 102 = Ctx->getMachOSection("__TEXT", "__cstring", 103 MachO::S_CSTRING_LITERALS, 104 SectionKind::getMergeable1ByteCString()); 105 UStringSection 106 = Ctx->getMachOSection("__TEXT","__ustring", 0, 107 SectionKind::getMergeable2ByteCString()); 108 FourByteConstantSection // .literal4 109 = Ctx->getMachOSection("__TEXT", "__literal4", 110 MachO::S_4BYTE_LITERALS, 111 SectionKind::getMergeableConst4()); 112 EightByteConstantSection // .literal8 113 = Ctx->getMachOSection("__TEXT", "__literal8", 114 MachO::S_8BYTE_LITERALS, 115 SectionKind::getMergeableConst8()); 116 117 SixteenByteConstantSection // .literal16 118 = Ctx->getMachOSection("__TEXT", "__literal16", 119 MachO::S_16BYTE_LITERALS, 120 SectionKind::getMergeableConst16()); 121 122 ReadOnlySection // .const 123 = Ctx->getMachOSection("__TEXT", "__const", 0, 124 SectionKind::getReadOnly()); 125 126 // If the target is not powerpc, map the coal sections to the non-coal 127 // sections. 128 // 129 // "__TEXT/__textcoal_nt" => section "__TEXT/__text" 130 // "__TEXT/__const_coal" => section "__TEXT/__const" 131 // "__DATA/__datacoal_nt" => section "__DATA/__data" 132 Triple::ArchType ArchTy = T.getArch(); 133 134 ConstDataSection // .const_data 135 = Ctx->getMachOSection("__DATA", "__const", 0, 136 SectionKind::getReadOnlyWithRel()); 137 138 if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) { 139 TextCoalSection 140 = Ctx->getMachOSection("__TEXT", "__textcoal_nt", 141 MachO::S_COALESCED | 142 MachO::S_ATTR_PURE_INSTRUCTIONS, 143 SectionKind::getText()); 144 ConstTextCoalSection 145 = Ctx->getMachOSection("__TEXT", "__const_coal", 146 MachO::S_COALESCED, 147 SectionKind::getReadOnly()); 148 DataCoalSection = Ctx->getMachOSection( 149 "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData()); 150 ConstDataCoalSection = DataCoalSection; 151 } else { 152 TextCoalSection = TextSection; 153 ConstTextCoalSection = ReadOnlySection; 154 DataCoalSection = DataSection; 155 ConstDataCoalSection = ConstDataSection; 156 } 157 158 DataCommonSection 159 = Ctx->getMachOSection("__DATA","__common", 160 MachO::S_ZEROFILL, 161 SectionKind::getBSS()); 162 DataBSSSection 163 = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL, 164 SectionKind::getBSS()); 165 166 167 LazySymbolPointerSection 168 = Ctx->getMachOSection("__DATA", "__la_symbol_ptr", 169 MachO::S_LAZY_SYMBOL_POINTERS, 170 SectionKind::getMetadata()); 171 NonLazySymbolPointerSection 172 = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr", 173 MachO::S_NON_LAZY_SYMBOL_POINTERS, 174 SectionKind::getMetadata()); 175 176 ThreadLocalPointerSection 177 = Ctx->getMachOSection("__DATA", "__thread_ptr", 178 MachO::S_THREAD_LOCAL_VARIABLE_POINTERS, 179 SectionKind::getMetadata()); 180 181 // Exception Handling. 182 LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0, 183 SectionKind::getReadOnlyWithRel()); 184 185 COFFDebugSymbolsSection = nullptr; 186 COFFDebugTypesSection = nullptr; 187 COFFGlobalTypeHashesSection = nullptr; 188 189 if (useCompactUnwind(T)) { 190 CompactUnwindSection = 191 Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG, 192 SectionKind::getReadOnly()); 193 194 if (T.isX86()) 195 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF 196 else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) 197 CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF 198 else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb) 199 CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF 200 } 201 202 // Debug Information. 203 DwarfDebugNamesSection = 204 Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG, 205 SectionKind::getMetadata(), "debug_names_begin"); 206 DwarfAccelNamesSection = 207 Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG, 208 SectionKind::getMetadata(), "names_begin"); 209 DwarfAccelObjCSection = 210 Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG, 211 SectionKind::getMetadata(), "objc_begin"); 212 // 16 character section limit... 213 DwarfAccelNamespaceSection = 214 Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG, 215 SectionKind::getMetadata(), "namespac_begin"); 216 DwarfAccelTypesSection = 217 Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG, 218 SectionKind::getMetadata(), "types_begin"); 219 220 DwarfSwiftASTSection = 221 Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG, 222 SectionKind::getMetadata()); 223 224 DwarfAbbrevSection = 225 Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG, 226 SectionKind::getMetadata(), "section_abbrev"); 227 DwarfInfoSection = 228 Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG, 229 SectionKind::getMetadata(), "section_info"); 230 DwarfLineSection = 231 Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG, 232 SectionKind::getMetadata(), "section_line"); 233 DwarfLineStrSection = 234 Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG, 235 SectionKind::getMetadata(), "section_line_str"); 236 DwarfFrameSection = 237 Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG, 238 SectionKind::getMetadata()); 239 DwarfPubNamesSection = 240 Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG, 241 SectionKind::getMetadata()); 242 DwarfPubTypesSection = 243 Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG, 244 SectionKind::getMetadata()); 245 DwarfGnuPubNamesSection = 246 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG, 247 SectionKind::getMetadata()); 248 DwarfGnuPubTypesSection = 249 Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG, 250 SectionKind::getMetadata()); 251 DwarfStrSection = 252 Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG, 253 SectionKind::getMetadata(), "info_string"); 254 DwarfStrOffSection = 255 Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG, 256 SectionKind::getMetadata(), "section_str_off"); 257 DwarfAddrSection = 258 Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG, 259 SectionKind::getMetadata(), "section_info"); 260 DwarfLocSection = 261 Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG, 262 SectionKind::getMetadata(), "section_debug_loc"); 263 DwarfLoclistsSection = 264 Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG, 265 SectionKind::getMetadata(), "section_debug_loc"); 266 267 DwarfARangesSection = 268 Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG, 269 SectionKind::getMetadata()); 270 DwarfRangesSection = 271 Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG, 272 SectionKind::getMetadata(), "debug_range"); 273 DwarfRnglistsSection = 274 Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG, 275 SectionKind::getMetadata(), "debug_range"); 276 DwarfMacinfoSection = 277 Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG, 278 SectionKind::getMetadata(), "debug_macinfo"); 279 DwarfMacroSection = 280 Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG, 281 SectionKind::getMetadata(), "debug_macro"); 282 DwarfDebugInlineSection = 283 Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG, 284 SectionKind::getMetadata()); 285 DwarfCUIndexSection = 286 Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG, 287 SectionKind::getMetadata()); 288 DwarfTUIndexSection = 289 Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG, 290 SectionKind::getMetadata()); 291 StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 292 0, SectionKind::getMetadata()); 293 294 FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps", 295 0, SectionKind::getMetadata()); 296 297 RemarksSection = Ctx->getMachOSection( 298 "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata()); 299 300 TLSExtraDataSection = TLSTLVSection; 301 } 302 303 void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) { 304 switch (T.getArch()) { 305 case Triple::mips: 306 case Triple::mipsel: 307 case Triple::mips64: 308 case Triple::mips64el: 309 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case 310 // since there is no R_MIPS_PC64 relocation (only a 32-bit version). 311 if (PositionIndependent && !Large) 312 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 313 else 314 FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4 315 ? dwarf::DW_EH_PE_sdata4 316 : dwarf::DW_EH_PE_sdata8; 317 break; 318 case Triple::ppc64: 319 case Triple::ppc64le: 320 case Triple::x86_64: 321 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | 322 (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4); 323 break; 324 case Triple::bpfel: 325 case Triple::bpfeb: 326 FDECFIEncoding = dwarf::DW_EH_PE_sdata8; 327 break; 328 case Triple::hexagon: 329 FDECFIEncoding = 330 PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr; 331 break; 332 default: 333 FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 334 break; 335 } 336 337 unsigned EHSectionType = T.getArch() == Triple::x86_64 338 ? ELF::SHT_X86_64_UNWIND 339 : ELF::SHT_PROGBITS; 340 341 // Solaris requires different flags for .eh_frame to seemingly every other 342 // platform. 343 unsigned EHSectionFlags = ELF::SHF_ALLOC; 344 if (T.isOSSolaris() && T.getArch() != Triple::x86_64) 345 EHSectionFlags |= ELF::SHF_WRITE; 346 347 // ELF 348 BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS, 349 ELF::SHF_WRITE | ELF::SHF_ALLOC); 350 351 TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS, 352 ELF::SHF_EXECINSTR | ELF::SHF_ALLOC); 353 354 DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS, 355 ELF::SHF_WRITE | ELF::SHF_ALLOC); 356 357 ReadOnlySection = 358 Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 359 360 TLSDataSection = 361 Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, 362 ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); 363 364 TLSBSSSection = Ctx->getELFSection( 365 ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); 366 367 DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, 368 ELF::SHF_ALLOC | ELF::SHF_WRITE); 369 370 MergeableConst4Section = 371 Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, 372 ELF::SHF_ALLOC | ELF::SHF_MERGE, 4, ""); 373 374 MergeableConst8Section = 375 Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, 376 ELF::SHF_ALLOC | ELF::SHF_MERGE, 8, ""); 377 378 MergeableConst16Section = 379 Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, 380 ELF::SHF_ALLOC | ELF::SHF_MERGE, 16, ""); 381 382 MergeableConst32Section = 383 Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS, 384 ELF::SHF_ALLOC | ELF::SHF_MERGE, 32, ""); 385 386 // Exception Handling Sections. 387 388 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though 389 // it contains relocatable pointers. In PIC mode, this is probably a big 390 // runtime hit for C++ apps. Either the contents of the LSDA need to be 391 // adjusted or this should be a data section. 392 LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, 393 ELF::SHF_ALLOC); 394 395 COFFDebugSymbolsSection = nullptr; 396 COFFDebugTypesSection = nullptr; 397 398 unsigned DebugSecType = ELF::SHT_PROGBITS; 399 400 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type 401 // to distinguish among sections contain DWARF and ECOFF debug formats. 402 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS. 403 if (T.isMIPS()) 404 DebugSecType = ELF::SHT_MIPS_DWARF; 405 406 // Debug Info Sections. 407 DwarfAbbrevSection = 408 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0); 409 DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0); 410 DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0); 411 DwarfLineStrSection = 412 Ctx->getELFSection(".debug_line_str", DebugSecType, 413 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, ""); 414 DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0); 415 DwarfPubNamesSection = 416 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0); 417 DwarfPubTypesSection = 418 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0); 419 DwarfGnuPubNamesSection = 420 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0); 421 DwarfGnuPubTypesSection = 422 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0); 423 DwarfStrSection = 424 Ctx->getELFSection(".debug_str", DebugSecType, 425 ELF::SHF_MERGE | ELF::SHF_STRINGS, 1, ""); 426 DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0); 427 DwarfARangesSection = 428 Ctx->getELFSection(".debug_aranges", DebugSecType, 0); 429 DwarfRangesSection = 430 Ctx->getELFSection(".debug_ranges", DebugSecType, 0); 431 DwarfMacinfoSection = 432 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0); 433 DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0); 434 435 // DWARF5 Experimental Debug Info 436 437 // Accelerator Tables 438 DwarfDebugNamesSection = 439 Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0); 440 DwarfAccelNamesSection = 441 Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0); 442 DwarfAccelObjCSection = 443 Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0); 444 DwarfAccelNamespaceSection = 445 Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0); 446 DwarfAccelTypesSection = 447 Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0); 448 449 // String Offset and Address Sections 450 DwarfStrOffSection = 451 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0); 452 DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0); 453 DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0); 454 DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0); 455 456 // Fission Sections 457 DwarfInfoDWOSection = 458 Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE); 459 DwarfTypesDWOSection = 460 Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE); 461 DwarfAbbrevDWOSection = 462 Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE); 463 DwarfStrDWOSection = Ctx->getELFSection( 464 ".debug_str.dwo", DebugSecType, 465 ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1, ""); 466 DwarfLineDWOSection = 467 Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE); 468 DwarfLocDWOSection = 469 Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE); 470 DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo", 471 DebugSecType, ELF::SHF_EXCLUDE); 472 DwarfRnglistsDWOSection = 473 Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE); 474 DwarfMacinfoDWOSection = 475 Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE); 476 477 DwarfLoclistsDWOSection = 478 Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE); 479 480 // DWP Sections 481 DwarfCUIndexSection = 482 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0); 483 DwarfTUIndexSection = 484 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0); 485 486 StackMapSection = 487 Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 488 489 FaultMapSection = 490 Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 491 492 EHFrameSection = 493 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags); 494 495 StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0); 496 } 497 498 void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) { 499 EHFrameSection = 500 Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 501 COFF::IMAGE_SCN_MEM_READ, 502 SectionKind::getData()); 503 504 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is 505 // used to indicate to the linker that the text segment contains thumb instructions 506 // and to set the ISA selection bit for calls accordingly. 507 const bool IsThumb = T.getArch() == Triple::thumb; 508 509 CommDirectiveSupportsAlignment = true; 510 511 // COFF 512 BSSSection = Ctx->getCOFFSection( 513 ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | 514 COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE, 515 SectionKind::getBSS()); 516 TextSection = Ctx->getCOFFSection( 517 ".text", 518 (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) | 519 COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | 520 COFF::IMAGE_SCN_MEM_READ, 521 SectionKind::getText()); 522 DataSection = Ctx->getCOFFSection( 523 ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 524 COFF::IMAGE_SCN_MEM_WRITE, 525 SectionKind::getData()); 526 ReadOnlySection = Ctx->getCOFFSection( 527 ".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 528 SectionKind::getReadOnly()); 529 530 if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64) { 531 // On Windows 64 with SEH, the LSDA is emitted into the .xdata section 532 LSDASection = nullptr; 533 } else { 534 LSDASection = Ctx->getCOFFSection(".gcc_except_table", 535 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 536 COFF::IMAGE_SCN_MEM_READ, 537 SectionKind::getReadOnly()); 538 } 539 540 // Debug info. 541 COFFDebugSymbolsSection = 542 Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 543 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 544 COFF::IMAGE_SCN_MEM_READ), 545 SectionKind::getMetadata()); 546 COFFDebugTypesSection = 547 Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 548 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 549 COFF::IMAGE_SCN_MEM_READ), 550 SectionKind::getMetadata()); 551 COFFGlobalTypeHashesSection = Ctx->getCOFFSection( 552 ".debug$H", 553 (COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 554 COFF::IMAGE_SCN_MEM_READ), 555 SectionKind::getMetadata()); 556 557 DwarfAbbrevSection = Ctx->getCOFFSection( 558 ".debug_abbrev", 559 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 560 COFF::IMAGE_SCN_MEM_READ, 561 SectionKind::getMetadata(), "section_abbrev"); 562 DwarfInfoSection = Ctx->getCOFFSection( 563 ".debug_info", 564 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 565 COFF::IMAGE_SCN_MEM_READ, 566 SectionKind::getMetadata(), "section_info"); 567 DwarfLineSection = Ctx->getCOFFSection( 568 ".debug_line", 569 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 570 COFF::IMAGE_SCN_MEM_READ, 571 SectionKind::getMetadata(), "section_line"); 572 DwarfLineStrSection = Ctx->getCOFFSection( 573 ".debug_line_str", 574 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 575 COFF::IMAGE_SCN_MEM_READ, 576 SectionKind::getMetadata(), "section_line_str"); 577 DwarfFrameSection = Ctx->getCOFFSection( 578 ".debug_frame", 579 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 580 COFF::IMAGE_SCN_MEM_READ, 581 SectionKind::getMetadata()); 582 DwarfPubNamesSection = Ctx->getCOFFSection( 583 ".debug_pubnames", 584 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 585 COFF::IMAGE_SCN_MEM_READ, 586 SectionKind::getMetadata()); 587 DwarfPubTypesSection = Ctx->getCOFFSection( 588 ".debug_pubtypes", 589 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 590 COFF::IMAGE_SCN_MEM_READ, 591 SectionKind::getMetadata()); 592 DwarfGnuPubNamesSection = Ctx->getCOFFSection( 593 ".debug_gnu_pubnames", 594 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 595 COFF::IMAGE_SCN_MEM_READ, 596 SectionKind::getMetadata()); 597 DwarfGnuPubTypesSection = Ctx->getCOFFSection( 598 ".debug_gnu_pubtypes", 599 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 600 COFF::IMAGE_SCN_MEM_READ, 601 SectionKind::getMetadata()); 602 DwarfStrSection = Ctx->getCOFFSection( 603 ".debug_str", 604 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 605 COFF::IMAGE_SCN_MEM_READ, 606 SectionKind::getMetadata(), "info_string"); 607 DwarfStrOffSection = Ctx->getCOFFSection( 608 ".debug_str_offsets", 609 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 610 COFF::IMAGE_SCN_MEM_READ, 611 SectionKind::getMetadata(), "section_str_off"); 612 DwarfLocSection = Ctx->getCOFFSection( 613 ".debug_loc", 614 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 615 COFF::IMAGE_SCN_MEM_READ, 616 SectionKind::getMetadata(), "section_debug_loc"); 617 DwarfLoclistsSection = Ctx->getCOFFSection( 618 ".debug_loclists", 619 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 620 COFF::IMAGE_SCN_MEM_READ, 621 SectionKind::getMetadata(), "section_debug_loclists"); 622 DwarfARangesSection = Ctx->getCOFFSection( 623 ".debug_aranges", 624 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 625 COFF::IMAGE_SCN_MEM_READ, 626 SectionKind::getMetadata()); 627 DwarfRangesSection = Ctx->getCOFFSection( 628 ".debug_ranges", 629 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 630 COFF::IMAGE_SCN_MEM_READ, 631 SectionKind::getMetadata(), "debug_range"); 632 DwarfRnglistsSection = Ctx->getCOFFSection( 633 ".debug_rnglists", 634 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 635 COFF::IMAGE_SCN_MEM_READ, 636 SectionKind::getMetadata(), "debug_rnglists"); 637 DwarfMacinfoSection = Ctx->getCOFFSection( 638 ".debug_macinfo", 639 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 640 COFF::IMAGE_SCN_MEM_READ, 641 SectionKind::getMetadata(), "debug_macinfo"); 642 DwarfMacroSection = Ctx->getCOFFSection( 643 ".debug_macro", 644 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 645 COFF::IMAGE_SCN_MEM_READ, 646 SectionKind::getMetadata(), "debug_macro"); 647 DwarfMacinfoDWOSection = Ctx->getCOFFSection( 648 ".debug_macinfo.dwo", 649 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 650 COFF::IMAGE_SCN_MEM_READ, 651 SectionKind::getMetadata(), "debug_macinfo.dwo"); 652 DwarfInfoDWOSection = Ctx->getCOFFSection( 653 ".debug_info.dwo", 654 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 655 COFF::IMAGE_SCN_MEM_READ, 656 SectionKind::getMetadata(), "section_info_dwo"); 657 DwarfTypesDWOSection = Ctx->getCOFFSection( 658 ".debug_types.dwo", 659 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 660 COFF::IMAGE_SCN_MEM_READ, 661 SectionKind::getMetadata(), "section_types_dwo"); 662 DwarfAbbrevDWOSection = Ctx->getCOFFSection( 663 ".debug_abbrev.dwo", 664 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 665 COFF::IMAGE_SCN_MEM_READ, 666 SectionKind::getMetadata(), "section_abbrev_dwo"); 667 DwarfStrDWOSection = Ctx->getCOFFSection( 668 ".debug_str.dwo", 669 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 670 COFF::IMAGE_SCN_MEM_READ, 671 SectionKind::getMetadata(), "skel_string"); 672 DwarfLineDWOSection = Ctx->getCOFFSection( 673 ".debug_line.dwo", 674 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 675 COFF::IMAGE_SCN_MEM_READ, 676 SectionKind::getMetadata()); 677 DwarfLocDWOSection = Ctx->getCOFFSection( 678 ".debug_loc.dwo", 679 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 680 COFF::IMAGE_SCN_MEM_READ, 681 SectionKind::getMetadata(), "skel_loc"); 682 DwarfStrOffDWOSection = Ctx->getCOFFSection( 683 ".debug_str_offsets.dwo", 684 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 685 COFF::IMAGE_SCN_MEM_READ, 686 SectionKind::getMetadata(), "section_str_off_dwo"); 687 DwarfAddrSection = Ctx->getCOFFSection( 688 ".debug_addr", 689 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 690 COFF::IMAGE_SCN_MEM_READ, 691 SectionKind::getMetadata(), "addr_sec"); 692 DwarfCUIndexSection = Ctx->getCOFFSection( 693 ".debug_cu_index", 694 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 695 COFF::IMAGE_SCN_MEM_READ, 696 SectionKind::getMetadata()); 697 DwarfTUIndexSection = Ctx->getCOFFSection( 698 ".debug_tu_index", 699 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 700 COFF::IMAGE_SCN_MEM_READ, 701 SectionKind::getMetadata()); 702 DwarfDebugNamesSection = Ctx->getCOFFSection( 703 ".debug_names", 704 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 705 COFF::IMAGE_SCN_MEM_READ, 706 SectionKind::getMetadata(), "debug_names_begin"); 707 DwarfAccelNamesSection = Ctx->getCOFFSection( 708 ".apple_names", 709 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 710 COFF::IMAGE_SCN_MEM_READ, 711 SectionKind::getMetadata(), "names_begin"); 712 DwarfAccelNamespaceSection = Ctx->getCOFFSection( 713 ".apple_namespaces", 714 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 715 COFF::IMAGE_SCN_MEM_READ, 716 SectionKind::getMetadata(), "namespac_begin"); 717 DwarfAccelTypesSection = Ctx->getCOFFSection( 718 ".apple_types", 719 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 720 COFF::IMAGE_SCN_MEM_READ, 721 SectionKind::getMetadata(), "types_begin"); 722 DwarfAccelObjCSection = Ctx->getCOFFSection( 723 ".apple_objc", 724 COFF::IMAGE_SCN_MEM_DISCARDABLE | COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 725 COFF::IMAGE_SCN_MEM_READ, 726 SectionKind::getMetadata(), "objc_begin"); 727 728 DrectveSection = Ctx->getCOFFSection( 729 ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE, 730 SectionKind::getMetadata()); 731 732 PDataSection = Ctx->getCOFFSection( 733 ".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 734 SectionKind::getData()); 735 736 XDataSection = Ctx->getCOFFSection( 737 ".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ, 738 SectionKind::getData()); 739 740 SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO, 741 SectionKind::getMetadata()); 742 743 GFIDsSection = Ctx->getCOFFSection(".gfids$y", 744 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 745 COFF::IMAGE_SCN_MEM_READ, 746 SectionKind::getMetadata()); 747 748 GLJMPSection = Ctx->getCOFFSection(".gljmp$y", 749 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 750 COFF::IMAGE_SCN_MEM_READ, 751 SectionKind::getMetadata()); 752 753 TLSDataSection = Ctx->getCOFFSection( 754 ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 755 COFF::IMAGE_SCN_MEM_WRITE, 756 SectionKind::getData()); 757 758 StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps", 759 COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 760 COFF::IMAGE_SCN_MEM_READ, 761 SectionKind::getReadOnly()); 762 } 763 764 void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) { 765 TextSection = Ctx->getWasmSection(".text", SectionKind::getText()); 766 DataSection = Ctx->getWasmSection(".data", SectionKind::getData()); 767 768 DwarfLineSection = 769 Ctx->getWasmSection(".debug_line", SectionKind::getMetadata()); 770 DwarfLineStrSection = 771 Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata()); 772 DwarfStrSection = 773 Ctx->getWasmSection(".debug_str", SectionKind::getMetadata()); 774 DwarfLocSection = 775 Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata()); 776 DwarfAbbrevSection = 777 Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata()); 778 DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata()); 779 DwarfRangesSection = 780 Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata()); 781 DwarfMacinfoSection = 782 Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata()); 783 DwarfMacroSection = 784 Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata()); 785 DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 786 DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 787 DwarfInfoSection = 788 Ctx->getWasmSection(".debug_info", SectionKind::getMetadata()); 789 DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata()); 790 DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata()); 791 DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata()); 792 793 DwarfDebugNamesSection = 794 Ctx->getWasmSection(".debug_names", SectionKind::getMetadata()); 795 DwarfStrOffSection = 796 Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata()); 797 DwarfAddrSection = 798 Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata()); 799 DwarfRnglistsSection = 800 Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata()); 801 DwarfLoclistsSection = 802 Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata()); 803 804 // Wasm use data section for LSDA. 805 // TODO Consider putting each function's exception table in a separate 806 // section, as in -function-sections, to facilitate lld's --gc-section. 807 LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table", 808 SectionKind::getReadOnlyWithRel()); 809 810 // TODO: Define more sections. 811 } 812 813 void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) { 814 // The default csect for program code. Functions without a specified section 815 // get placed into this csect. The choice of csect name is not a property of 816 // the ABI or object file format. For example, the XL compiler uses an unnamed 817 // csect for program code. 818 TextSection = Ctx->getXCOFFSection( 819 ".text", XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD, 820 XCOFF::C_HIDEXT, SectionKind::getText()); 821 822 DataSection = Ctx->getXCOFFSection( 823 ".data", XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD, 824 XCOFF::C_HIDEXT, SectionKind::getData()); 825 826 ReadOnlySection = Ctx->getXCOFFSection( 827 ".rodata", XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD, 828 XCOFF::C_HIDEXT, SectionKind::getReadOnly()); 829 830 TOCBaseSection = Ctx->getXCOFFSection( 831 "TOC", XCOFF::StorageMappingClass::XMC_TC0, XCOFF::XTY_SD, 832 XCOFF::C_HIDEXT, SectionKind::getData()); 833 834 // The TOC-base always has 0 size, but 4 byte alignment. 835 TOCBaseSection->setAlignment(Align(4)); 836 837 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF 838 // sections, and the individual DWARF sections are distinguished by their 839 // section subtype. 840 // TODO: Populate the DWARF sections appropriately. 841 DwarfAbbrevSection = nullptr; // SSUBTYP_DWABREV 842 DwarfInfoSection = nullptr; // SSUBTYP_DWINFO 843 DwarfLineSection = nullptr; // SSUBTYP_DWLINE 844 DwarfFrameSection = nullptr; // SSUBTYP_DWFRAME 845 DwarfPubNamesSection = nullptr; // SSUBTYP_DWPBNMS 846 DwarfPubTypesSection = nullptr; // SSUBTYP_DWPBTYP 847 DwarfStrSection = nullptr; // SSUBTYP_DWSTR 848 DwarfLocSection = nullptr; // SSUBTYP_DWLOC 849 DwarfARangesSection = nullptr; // SSUBTYP_DWARNGE 850 DwarfRangesSection = nullptr; // SSUBTYP_DWRNGES 851 DwarfMacinfoSection = nullptr; // SSUBTYP_DWMAC 852 } 853 854 void MCObjectFileInfo::InitMCObjectFileInfo(const Triple &TheTriple, bool PIC, 855 MCContext &ctx, 856 bool LargeCodeModel) { 857 PositionIndependent = PIC; 858 Ctx = &ctx; 859 860 // Common. 861 CommDirectiveSupportsAlignment = true; 862 SupportsWeakOmittedEHFrame = true; 863 SupportsCompactUnwindWithoutEHFrame = false; 864 OmitDwarfIfHaveCompactUnwind = false; 865 866 FDECFIEncoding = dwarf::DW_EH_PE_absptr; 867 868 CompactUnwindDwarfEHFrameOnly = 0; 869 870 EHFrameSection = nullptr; // Created on demand. 871 CompactUnwindSection = nullptr; // Used only by selected targets. 872 DwarfAccelNamesSection = nullptr; // Used only by selected targets. 873 DwarfAccelObjCSection = nullptr; // Used only by selected targets. 874 DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. 875 DwarfAccelTypesSection = nullptr; // Used only by selected targets. 876 877 TT = TheTriple; 878 879 switch (TT.getObjectFormat()) { 880 case Triple::MachO: 881 Env = IsMachO; 882 initMachOMCObjectFileInfo(TT); 883 break; 884 case Triple::COFF: 885 if (!TT.isOSWindows()) 886 report_fatal_error( 887 "Cannot initialize MC for non-Windows COFF object files."); 888 889 Env = IsCOFF; 890 initCOFFMCObjectFileInfo(TT); 891 break; 892 case Triple::ELF: 893 Env = IsELF; 894 initELFMCObjectFileInfo(TT, LargeCodeModel); 895 break; 896 case Triple::Wasm: 897 Env = IsWasm; 898 initWasmMCObjectFileInfo(TT); 899 break; 900 case Triple::XCOFF: 901 Env = IsXCOFF; 902 initXCOFFMCObjectFileInfo(TT); 903 break; 904 case Triple::UnknownObjectFormat: 905 report_fatal_error("Cannot initialize MC for unknown object file format."); 906 break; 907 } 908 } 909 910 MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, 911 uint64_t Hash) const { 912 switch (TT.getObjectFormat()) { 913 case Triple::ELF: 914 return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, 915 utostr(Hash)); 916 case Triple::MachO: 917 case Triple::COFF: 918 case Triple::Wasm: 919 case Triple::XCOFF: 920 case Triple::UnknownObjectFormat: 921 report_fatal_error("Cannot get DWARF comdat section for this object file " 922 "format: not implemented."); 923 break; 924 } 925 llvm_unreachable("Unknown ObjectFormatType"); 926 } 927 928 MCSection * 929 MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { 930 if (Env != IsELF) 931 return StackSizesSection; 932 933 const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 934 unsigned Flags = ELF::SHF_LINK_ORDER; 935 StringRef GroupName; 936 if (const MCSymbol *Group = ElfSec.getGroup()) { 937 GroupName = Group->getName(); 938 Flags |= ELF::SHF_GROUP; 939 } 940 941 return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, 942 GroupName, MCSection::NonUniqueID, 943 cast<MCSymbolELF>(TextSec.getBeginSymbol())); 944 } 945