10b57cec5SDimitry Andric //===-- MCObjectFileInfo.cpp - Object File Information --------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #include "llvm/MC/MCObjectFileInfo.h" 100b57cec5SDimitry Andric #include "llvm/ADT/StringExtras.h" 110b57cec5SDimitry Andric #include "llvm/BinaryFormat/COFF.h" 120b57cec5SDimitry Andric #include "llvm/BinaryFormat/ELF.h" 13fe6060f1SDimitry Andric #include "llvm/BinaryFormat/Wasm.h" 140b57cec5SDimitry Andric #include "llvm/MC/MCAsmInfo.h" 150b57cec5SDimitry Andric #include "llvm/MC/MCContext.h" 160b57cec5SDimitry Andric #include "llvm/MC/MCSection.h" 170b57cec5SDimitry Andric #include "llvm/MC/MCSectionCOFF.h" 1881ad6265SDimitry Andric #include "llvm/MC/MCSectionDXContainer.h" 190b57cec5SDimitry Andric #include "llvm/MC/MCSectionELF.h" 20fe6060f1SDimitry Andric #include "llvm/MC/MCSectionGOFF.h" 210b57cec5SDimitry Andric #include "llvm/MC/MCSectionMachO.h" 2281ad6265SDimitry Andric #include "llvm/MC/MCSectionSPIRV.h" 230b57cec5SDimitry Andric #include "llvm/MC/MCSectionWasm.h" 240b57cec5SDimitry Andric #include "llvm/MC/MCSectionXCOFF.h" 2581ad6265SDimitry Andric #include "llvm/Support/Casting.h" 2606c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h" 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric using namespace llvm; 290b57cec5SDimitry Andric 300b57cec5SDimitry Andric static bool useCompactUnwind(const Triple &T) { 310b57cec5SDimitry Andric // Only on darwin. 320b57cec5SDimitry Andric if (!T.isOSDarwin()) 330b57cec5SDimitry Andric return false; 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric // aarch64 always has it. 368bcb0991SDimitry Andric if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) 370b57cec5SDimitry Andric return true; 380b57cec5SDimitry Andric 390b57cec5SDimitry Andric // armv7k always has it. 400b57cec5SDimitry Andric if (T.isWatchABI()) 410b57cec5SDimitry Andric return true; 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric // Use it on newer version of OS X. 440b57cec5SDimitry Andric if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6)) 450b57cec5SDimitry Andric return true; 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric // And the iOS simulator. 48480093f4SDimitry Andric if (T.isiOS() && T.isX86()) 490b57cec5SDimitry Andric return true; 500b57cec5SDimitry Andric 5106c3fb27SDimitry Andric // The rest of the simulators always have it. 5206c3fb27SDimitry Andric if (T.isSimulatorEnvironment()) 5306c3fb27SDimitry Andric return true; 5406c3fb27SDimitry Andric 557a6dacacSDimitry Andric // XROS always has it. 567a6dacacSDimitry Andric if (T.isXROS()) 577a6dacacSDimitry Andric return true; 587a6dacacSDimitry Andric 590b57cec5SDimitry Andric return false; 600b57cec5SDimitry Andric } 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) { 630b57cec5SDimitry Andric // MachO 640b57cec5SDimitry Andric SupportsWeakOmittedEHFrame = false; 650b57cec5SDimitry Andric 660b57cec5SDimitry Andric EHFrameSection = Ctx->getMachOSection( 670b57cec5SDimitry Andric "__TEXT", "__eh_frame", 680b57cec5SDimitry Andric MachO::S_COALESCED | MachO::S_ATTR_NO_TOC | 690b57cec5SDimitry Andric MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT, 700b57cec5SDimitry Andric SectionKind::getReadOnly()); 710b57cec5SDimitry Andric 728bcb0991SDimitry Andric if (T.isOSDarwin() && 7306c3fb27SDimitry Andric (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 || 7406c3fb27SDimitry Andric T.isSimulatorEnvironment())) 750b57cec5SDimitry Andric SupportsCompactUnwindWithoutEHFrame = true; 760b57cec5SDimitry Andric 7781ad6265SDimitry Andric switch (Ctx->emitDwarfUnwindInfo()) { 7881ad6265SDimitry Andric case EmitDwarfUnwindType::Always: 7981ad6265SDimitry Andric OmitDwarfIfHaveCompactUnwind = false; 8081ad6265SDimitry Andric break; 8181ad6265SDimitry Andric case EmitDwarfUnwindType::NoCompactUnwind: 820b57cec5SDimitry Andric OmitDwarfIfHaveCompactUnwind = true; 8381ad6265SDimitry Andric break; 8481ad6265SDimitry Andric case EmitDwarfUnwindType::Default: 8581ad6265SDimitry Andric OmitDwarfIfHaveCompactUnwind = 8681ad6265SDimitry Andric T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame; 8781ad6265SDimitry Andric break; 8881ad6265SDimitry Andric } 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric FDECFIEncoding = dwarf::DW_EH_PE_pcrel; 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric TextSection // .text 930b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__text", 940b57cec5SDimitry Andric MachO::S_ATTR_PURE_INSTRUCTIONS, 950b57cec5SDimitry Andric SectionKind::getText()); 960b57cec5SDimitry Andric DataSection // .data 970b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData()); 980b57cec5SDimitry Andric 990b57cec5SDimitry Andric // BSSSection might not be expected initialized on msvc. 1000b57cec5SDimitry Andric BSSSection = nullptr; 1010b57cec5SDimitry Andric 1020b57cec5SDimitry Andric TLSDataSection // .tdata 1030b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__thread_data", 1040b57cec5SDimitry Andric MachO::S_THREAD_LOCAL_REGULAR, 1050b57cec5SDimitry Andric SectionKind::getData()); 1060b57cec5SDimitry Andric TLSBSSSection // .tbss 1070b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__thread_bss", 1080b57cec5SDimitry Andric MachO::S_THREAD_LOCAL_ZEROFILL, 1090b57cec5SDimitry Andric SectionKind::getThreadBSS()); 1100b57cec5SDimitry Andric 1110b57cec5SDimitry Andric // TODO: Verify datarel below. 1120b57cec5SDimitry Andric TLSTLVSection // .tlv 1130b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__thread_vars", 1140b57cec5SDimitry Andric MachO::S_THREAD_LOCAL_VARIABLES, 1150b57cec5SDimitry Andric SectionKind::getData()); 1160b57cec5SDimitry Andric 1170b57cec5SDimitry Andric TLSThreadInitSection = Ctx->getMachOSection( 1180b57cec5SDimitry Andric "__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS, 1190b57cec5SDimitry Andric SectionKind::getData()); 1200b57cec5SDimitry Andric 1210b57cec5SDimitry Andric CStringSection // .cstring 1220b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__cstring", 1230b57cec5SDimitry Andric MachO::S_CSTRING_LITERALS, 1240b57cec5SDimitry Andric SectionKind::getMergeable1ByteCString()); 1250b57cec5SDimitry Andric UStringSection 1260b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT","__ustring", 0, 1270b57cec5SDimitry Andric SectionKind::getMergeable2ByteCString()); 1280b57cec5SDimitry Andric FourByteConstantSection // .literal4 1290b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__literal4", 1300b57cec5SDimitry Andric MachO::S_4BYTE_LITERALS, 1310b57cec5SDimitry Andric SectionKind::getMergeableConst4()); 1320b57cec5SDimitry Andric EightByteConstantSection // .literal8 1330b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__literal8", 1340b57cec5SDimitry Andric MachO::S_8BYTE_LITERALS, 1350b57cec5SDimitry Andric SectionKind::getMergeableConst8()); 1360b57cec5SDimitry Andric 1370b57cec5SDimitry Andric SixteenByteConstantSection // .literal16 1380b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__literal16", 1390b57cec5SDimitry Andric MachO::S_16BYTE_LITERALS, 1400b57cec5SDimitry Andric SectionKind::getMergeableConst16()); 1410b57cec5SDimitry Andric 1420b57cec5SDimitry Andric ReadOnlySection // .const 1430b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__const", 0, 1440b57cec5SDimitry Andric SectionKind::getReadOnly()); 1450b57cec5SDimitry Andric 1460b57cec5SDimitry Andric // If the target is not powerpc, map the coal sections to the non-coal 1470b57cec5SDimitry Andric // sections. 1480b57cec5SDimitry Andric // 1490b57cec5SDimitry Andric // "__TEXT/__textcoal_nt" => section "__TEXT/__text" 1500b57cec5SDimitry Andric // "__TEXT/__const_coal" => section "__TEXT/__const" 1510b57cec5SDimitry Andric // "__DATA/__datacoal_nt" => section "__DATA/__data" 1520b57cec5SDimitry Andric Triple::ArchType ArchTy = T.getArch(); 1530b57cec5SDimitry Andric 1540b57cec5SDimitry Andric ConstDataSection // .const_data 1550b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__const", 0, 1560b57cec5SDimitry Andric SectionKind::getReadOnlyWithRel()); 1570b57cec5SDimitry Andric 1580b57cec5SDimitry Andric if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) { 1590b57cec5SDimitry Andric TextCoalSection 1600b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__textcoal_nt", 1610b57cec5SDimitry Andric MachO::S_COALESCED | 1620b57cec5SDimitry Andric MachO::S_ATTR_PURE_INSTRUCTIONS, 1630b57cec5SDimitry Andric SectionKind::getText()); 1640b57cec5SDimitry Andric ConstTextCoalSection 1650b57cec5SDimitry Andric = Ctx->getMachOSection("__TEXT", "__const_coal", 1660b57cec5SDimitry Andric MachO::S_COALESCED, 1670b57cec5SDimitry Andric SectionKind::getReadOnly()); 1680b57cec5SDimitry Andric DataCoalSection = Ctx->getMachOSection( 1690b57cec5SDimitry Andric "__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData()); 1700b57cec5SDimitry Andric ConstDataCoalSection = DataCoalSection; 1710b57cec5SDimitry Andric } else { 1720b57cec5SDimitry Andric TextCoalSection = TextSection; 1730b57cec5SDimitry Andric ConstTextCoalSection = ReadOnlySection; 1740b57cec5SDimitry Andric DataCoalSection = DataSection; 1750b57cec5SDimitry Andric ConstDataCoalSection = ConstDataSection; 1760b57cec5SDimitry Andric } 1770b57cec5SDimitry Andric 1780b57cec5SDimitry Andric DataCommonSection 1790b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA","__common", 1800b57cec5SDimitry Andric MachO::S_ZEROFILL, 1810b57cec5SDimitry Andric SectionKind::getBSS()); 1820b57cec5SDimitry Andric DataBSSSection 1830b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL, 1840b57cec5SDimitry Andric SectionKind::getBSS()); 1850b57cec5SDimitry Andric 1860b57cec5SDimitry Andric 1870b57cec5SDimitry Andric LazySymbolPointerSection 1880b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__la_symbol_ptr", 1890b57cec5SDimitry Andric MachO::S_LAZY_SYMBOL_POINTERS, 1900b57cec5SDimitry Andric SectionKind::getMetadata()); 1910b57cec5SDimitry Andric NonLazySymbolPointerSection 1920b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__nl_symbol_ptr", 1930b57cec5SDimitry Andric MachO::S_NON_LAZY_SYMBOL_POINTERS, 1940b57cec5SDimitry Andric SectionKind::getMetadata()); 1950b57cec5SDimitry Andric 1960b57cec5SDimitry Andric ThreadLocalPointerSection 1970b57cec5SDimitry Andric = Ctx->getMachOSection("__DATA", "__thread_ptr", 1980b57cec5SDimitry Andric MachO::S_THREAD_LOCAL_VARIABLE_POINTERS, 1990b57cec5SDimitry Andric SectionKind::getMetadata()); 2000b57cec5SDimitry Andric 20181ad6265SDimitry Andric AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0, 20281ad6265SDimitry Andric SectionKind::getData()); 20381ad6265SDimitry Andric 2040b57cec5SDimitry Andric // Exception Handling. 2050b57cec5SDimitry Andric LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0, 2060b57cec5SDimitry Andric SectionKind::getReadOnlyWithRel()); 2070b57cec5SDimitry Andric 2080b57cec5SDimitry Andric COFFDebugSymbolsSection = nullptr; 2090b57cec5SDimitry Andric COFFDebugTypesSection = nullptr; 2100b57cec5SDimitry Andric COFFGlobalTypeHashesSection = nullptr; 2110b57cec5SDimitry Andric 2120b57cec5SDimitry Andric if (useCompactUnwind(T)) { 2130b57cec5SDimitry Andric CompactUnwindSection = 2140b57cec5SDimitry Andric Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG, 2150b57cec5SDimitry Andric SectionKind::getReadOnly()); 2160b57cec5SDimitry Andric 217480093f4SDimitry Andric if (T.isX86()) 2180b57cec5SDimitry Andric CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF 2198bcb0991SDimitry Andric else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32) 2200b57cec5SDimitry Andric CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF 2210b57cec5SDimitry Andric else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb) 2220b57cec5SDimitry Andric CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF 2230b57cec5SDimitry Andric } 2240b57cec5SDimitry Andric 2250b57cec5SDimitry Andric // Debug Information. 2260b57cec5SDimitry Andric DwarfDebugNamesSection = 2270b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG, 2280b57cec5SDimitry Andric SectionKind::getMetadata(), "debug_names_begin"); 2290b57cec5SDimitry Andric DwarfAccelNamesSection = 2300b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG, 2310b57cec5SDimitry Andric SectionKind::getMetadata(), "names_begin"); 2320b57cec5SDimitry Andric DwarfAccelObjCSection = 2330b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG, 2340b57cec5SDimitry Andric SectionKind::getMetadata(), "objc_begin"); 2350b57cec5SDimitry Andric // 16 character section limit... 2360b57cec5SDimitry Andric DwarfAccelNamespaceSection = 2370b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG, 2380b57cec5SDimitry Andric SectionKind::getMetadata(), "namespac_begin"); 2390b57cec5SDimitry Andric DwarfAccelTypesSection = 2400b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG, 2410b57cec5SDimitry Andric SectionKind::getMetadata(), "types_begin"); 2420b57cec5SDimitry Andric 2430b57cec5SDimitry Andric DwarfSwiftASTSection = 2440b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG, 2450b57cec5SDimitry Andric SectionKind::getMetadata()); 2460b57cec5SDimitry Andric 2470b57cec5SDimitry Andric DwarfAbbrevSection = 2480b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG, 2490b57cec5SDimitry Andric SectionKind::getMetadata(), "section_abbrev"); 2500b57cec5SDimitry Andric DwarfInfoSection = 2510b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG, 2520b57cec5SDimitry Andric SectionKind::getMetadata(), "section_info"); 2530b57cec5SDimitry Andric DwarfLineSection = 2540b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG, 2550b57cec5SDimitry Andric SectionKind::getMetadata(), "section_line"); 2560b57cec5SDimitry Andric DwarfLineStrSection = 2570b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG, 2580b57cec5SDimitry Andric SectionKind::getMetadata(), "section_line_str"); 2590b57cec5SDimitry Andric DwarfFrameSection = 2600b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG, 26106c3fb27SDimitry Andric SectionKind::getMetadata(), "section_frame"); 2620b57cec5SDimitry Andric DwarfPubNamesSection = 2630b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG, 2640b57cec5SDimitry Andric SectionKind::getMetadata()); 2650b57cec5SDimitry Andric DwarfPubTypesSection = 2660b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG, 2670b57cec5SDimitry Andric SectionKind::getMetadata()); 2680b57cec5SDimitry Andric DwarfGnuPubNamesSection = 2690b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG, 2700b57cec5SDimitry Andric SectionKind::getMetadata()); 2710b57cec5SDimitry Andric DwarfGnuPubTypesSection = 2720b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG, 2730b57cec5SDimitry Andric SectionKind::getMetadata()); 2740b57cec5SDimitry Andric DwarfStrSection = 2750b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG, 2760b57cec5SDimitry Andric SectionKind::getMetadata(), "info_string"); 2770b57cec5SDimitry Andric DwarfStrOffSection = 2780b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG, 2790b57cec5SDimitry Andric SectionKind::getMetadata(), "section_str_off"); 2800b57cec5SDimitry Andric DwarfAddrSection = 2810b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG, 2820b57cec5SDimitry Andric SectionKind::getMetadata(), "section_info"); 2830b57cec5SDimitry Andric DwarfLocSection = 2840b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG, 2850b57cec5SDimitry Andric SectionKind::getMetadata(), "section_debug_loc"); 2860b57cec5SDimitry Andric DwarfLoclistsSection = 2870b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG, 2880b57cec5SDimitry Andric SectionKind::getMetadata(), "section_debug_loc"); 2890b57cec5SDimitry Andric 2900b57cec5SDimitry Andric DwarfARangesSection = 2910b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG, 2920b57cec5SDimitry Andric SectionKind::getMetadata()); 2930b57cec5SDimitry Andric DwarfRangesSection = 2940b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG, 2950b57cec5SDimitry Andric SectionKind::getMetadata(), "debug_range"); 2960b57cec5SDimitry Andric DwarfRnglistsSection = 2970b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG, 2980b57cec5SDimitry Andric SectionKind::getMetadata(), "debug_range"); 2990b57cec5SDimitry Andric DwarfMacinfoSection = 3000b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG, 3010b57cec5SDimitry Andric SectionKind::getMetadata(), "debug_macinfo"); 3025ffd83dbSDimitry Andric DwarfMacroSection = 3035ffd83dbSDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG, 3045ffd83dbSDimitry Andric SectionKind::getMetadata(), "debug_macro"); 3050b57cec5SDimitry Andric DwarfDebugInlineSection = 3060b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG, 3070b57cec5SDimitry Andric SectionKind::getMetadata()); 3080b57cec5SDimitry Andric DwarfCUIndexSection = 3090b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG, 3100b57cec5SDimitry Andric SectionKind::getMetadata()); 3110b57cec5SDimitry Andric DwarfTUIndexSection = 3120b57cec5SDimitry Andric Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG, 3130b57cec5SDimitry Andric SectionKind::getMetadata()); 3140b57cec5SDimitry Andric StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps", 3150b57cec5SDimitry Andric 0, SectionKind::getMetadata()); 3160b57cec5SDimitry Andric 3170b57cec5SDimitry Andric FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps", 3180b57cec5SDimitry Andric 0, SectionKind::getMetadata()); 3190b57cec5SDimitry Andric 3200b57cec5SDimitry Andric RemarksSection = Ctx->getMachOSection( 3210b57cec5SDimitry Andric "__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata()); 3220b57cec5SDimitry Andric 3231fd87a68SDimitry Andric // The architecture of dsymutil makes it very difficult to copy the Swift 3241fd87a68SDimitry Andric // reflection metadata sections into the __TEXT segment, so dsymutil creates 3251fd87a68SDimitry Andric // these sections in the __DWARF segment instead. 3261fd87a68SDimitry Andric if (!Ctx->getSwift5ReflectionSegmentName().empty()) { 3271fd87a68SDimitry Andric #define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \ 3281fd87a68SDimitry Andric Swift5ReflectionSections \ 3291fd87a68SDimitry Andric [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \ 3301fd87a68SDimitry Andric Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \ 3311fd87a68SDimitry Andric MACHO, 0, SectionKind::getMetadata()); 3321fd87a68SDimitry Andric #include "llvm/BinaryFormat/Swift.def" 3331fd87a68SDimitry Andric } 3341fd87a68SDimitry Andric 3350b57cec5SDimitry Andric TLSExtraDataSection = TLSTLVSection; 3360b57cec5SDimitry Andric } 3370b57cec5SDimitry Andric 3380b57cec5SDimitry Andric void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) { 3390b57cec5SDimitry Andric switch (T.getArch()) { 3400b57cec5SDimitry Andric case Triple::mips: 3410b57cec5SDimitry Andric case Triple::mipsel: 3420b57cec5SDimitry Andric case Triple::mips64: 3430b57cec5SDimitry Andric case Triple::mips64el: 34480500f4eSAlex Richardson // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case 34580500f4eSAlex Richardson // since there is no R_MIPS_PC64 relocation (only a 32-bit version). 346*0fca6ea1SDimitry Andric // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't 347*0fca6ea1SDimitry Andric // support pcrel|sdata8 well. Let's use sdata4 for now. 348*0fca6ea1SDimitry Andric if (PositionIndependent) 34980500f4eSAlex Richardson FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 35080500f4eSAlex Richardson else 3510b57cec5SDimitry Andric FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4 3520b57cec5SDimitry Andric ? dwarf::DW_EH_PE_sdata4 3530b57cec5SDimitry Andric : dwarf::DW_EH_PE_sdata8; 3540b57cec5SDimitry Andric break; 3550b57cec5SDimitry Andric case Triple::ppc64: 3560b57cec5SDimitry Andric case Triple::ppc64le: 357eaeb601bSDimitry Andric case Triple::aarch64: 358eaeb601bSDimitry Andric case Triple::aarch64_be: 3590b57cec5SDimitry Andric case Triple::x86_64: 3600b57cec5SDimitry Andric FDECFIEncoding = dwarf::DW_EH_PE_pcrel | 3610b57cec5SDimitry Andric (Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4); 3620b57cec5SDimitry Andric break; 3630b57cec5SDimitry Andric case Triple::bpfel: 3640b57cec5SDimitry Andric case Triple::bpfeb: 3650b57cec5SDimitry Andric FDECFIEncoding = dwarf::DW_EH_PE_sdata8; 3660b57cec5SDimitry Andric break; 3670b57cec5SDimitry Andric case Triple::hexagon: 3680b57cec5SDimitry Andric FDECFIEncoding = 3690b57cec5SDimitry Andric PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr; 3700b57cec5SDimitry Andric break; 371bdd1243dSDimitry Andric case Triple::xtensa: 372bdd1243dSDimitry Andric FDECFIEncoding = dwarf::DW_EH_PE_sdata4; 373bdd1243dSDimitry Andric break; 3740b57cec5SDimitry Andric default: 3750b57cec5SDimitry Andric FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; 3760b57cec5SDimitry Andric break; 3770b57cec5SDimitry Andric } 3780b57cec5SDimitry Andric 3790b57cec5SDimitry Andric unsigned EHSectionType = T.getArch() == Triple::x86_64 3800b57cec5SDimitry Andric ? ELF::SHT_X86_64_UNWIND 3810b57cec5SDimitry Andric : ELF::SHT_PROGBITS; 3820b57cec5SDimitry Andric 3830b57cec5SDimitry Andric // Solaris requires different flags for .eh_frame to seemingly every other 3840b57cec5SDimitry Andric // platform. 3850b57cec5SDimitry Andric unsigned EHSectionFlags = ELF::SHF_ALLOC; 3860b57cec5SDimitry Andric if (T.isOSSolaris() && T.getArch() != Triple::x86_64) 3870b57cec5SDimitry Andric EHSectionFlags |= ELF::SHF_WRITE; 3880b57cec5SDimitry Andric 3890b57cec5SDimitry Andric // ELF 3900b57cec5SDimitry Andric BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS, 3910b57cec5SDimitry Andric ELF::SHF_WRITE | ELF::SHF_ALLOC); 3920b57cec5SDimitry Andric 3930b57cec5SDimitry Andric TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS, 3940b57cec5SDimitry Andric ELF::SHF_EXECINSTR | ELF::SHF_ALLOC); 3950b57cec5SDimitry Andric 3960b57cec5SDimitry Andric DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS, 3970b57cec5SDimitry Andric ELF::SHF_WRITE | ELF::SHF_ALLOC); 3980b57cec5SDimitry Andric 3990b57cec5SDimitry Andric ReadOnlySection = 4000b57cec5SDimitry Andric Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 4010b57cec5SDimitry Andric 4020b57cec5SDimitry Andric TLSDataSection = 4030b57cec5SDimitry Andric Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS, 4040b57cec5SDimitry Andric ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); 4050b57cec5SDimitry Andric 4060b57cec5SDimitry Andric TLSBSSSection = Ctx->getELFSection( 4070b57cec5SDimitry Andric ".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE); 4080b57cec5SDimitry Andric 4090b57cec5SDimitry Andric DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS, 4100b57cec5SDimitry Andric ELF::SHF_ALLOC | ELF::SHF_WRITE); 4110b57cec5SDimitry Andric 4120b57cec5SDimitry Andric MergeableConst4Section = 4130b57cec5SDimitry Andric Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS, 414fe6060f1SDimitry Andric ELF::SHF_ALLOC | ELF::SHF_MERGE, 4); 4150b57cec5SDimitry Andric 4160b57cec5SDimitry Andric MergeableConst8Section = 4170b57cec5SDimitry Andric Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS, 418fe6060f1SDimitry Andric ELF::SHF_ALLOC | ELF::SHF_MERGE, 8); 4190b57cec5SDimitry Andric 4200b57cec5SDimitry Andric MergeableConst16Section = 4210b57cec5SDimitry Andric Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS, 422fe6060f1SDimitry Andric ELF::SHF_ALLOC | ELF::SHF_MERGE, 16); 4230b57cec5SDimitry Andric 4240b57cec5SDimitry Andric MergeableConst32Section = 4250b57cec5SDimitry Andric Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS, 426fe6060f1SDimitry Andric ELF::SHF_ALLOC | ELF::SHF_MERGE, 32); 4270b57cec5SDimitry Andric 4280b57cec5SDimitry Andric // Exception Handling Sections. 4290b57cec5SDimitry Andric 4300b57cec5SDimitry Andric // FIXME: We're emitting LSDA info into a readonly section on ELF, even though 4310b57cec5SDimitry Andric // it contains relocatable pointers. In PIC mode, this is probably a big 4320b57cec5SDimitry Andric // runtime hit for C++ apps. Either the contents of the LSDA need to be 4330b57cec5SDimitry Andric // adjusted or this should be a data section. 4340b57cec5SDimitry Andric LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS, 4350b57cec5SDimitry Andric ELF::SHF_ALLOC); 4360b57cec5SDimitry Andric 4370b57cec5SDimitry Andric COFFDebugSymbolsSection = nullptr; 4380b57cec5SDimitry Andric COFFDebugTypesSection = nullptr; 4390b57cec5SDimitry Andric 4400b57cec5SDimitry Andric unsigned DebugSecType = ELF::SHT_PROGBITS; 4410b57cec5SDimitry Andric 4420b57cec5SDimitry Andric // MIPS .debug_* sections should have SHT_MIPS_DWARF section type 4430b57cec5SDimitry Andric // to distinguish among sections contain DWARF and ECOFF debug formats. 4440b57cec5SDimitry Andric // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS. 4450b57cec5SDimitry Andric if (T.isMIPS()) 4460b57cec5SDimitry Andric DebugSecType = ELF::SHT_MIPS_DWARF; 4470b57cec5SDimitry Andric 4480b57cec5SDimitry Andric // Debug Info Sections. 4490b57cec5SDimitry Andric DwarfAbbrevSection = 4500b57cec5SDimitry Andric Ctx->getELFSection(".debug_abbrev", DebugSecType, 0); 4510b57cec5SDimitry Andric DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0); 4520b57cec5SDimitry Andric DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0); 4530b57cec5SDimitry Andric DwarfLineStrSection = 4540b57cec5SDimitry Andric Ctx->getELFSection(".debug_line_str", DebugSecType, 455fe6060f1SDimitry Andric ELF::SHF_MERGE | ELF::SHF_STRINGS, 1); 4560b57cec5SDimitry Andric DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0); 4570b57cec5SDimitry Andric DwarfPubNamesSection = 4580b57cec5SDimitry Andric Ctx->getELFSection(".debug_pubnames", DebugSecType, 0); 4590b57cec5SDimitry Andric DwarfPubTypesSection = 4600b57cec5SDimitry Andric Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0); 4610b57cec5SDimitry Andric DwarfGnuPubNamesSection = 4620b57cec5SDimitry Andric Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0); 4630b57cec5SDimitry Andric DwarfGnuPubTypesSection = 4640b57cec5SDimitry Andric Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0); 4650b57cec5SDimitry Andric DwarfStrSection = 4660b57cec5SDimitry Andric Ctx->getELFSection(".debug_str", DebugSecType, 467fe6060f1SDimitry Andric ELF::SHF_MERGE | ELF::SHF_STRINGS, 1); 4680b57cec5SDimitry Andric DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0); 4690b57cec5SDimitry Andric DwarfARangesSection = 4700b57cec5SDimitry Andric Ctx->getELFSection(".debug_aranges", DebugSecType, 0); 4710b57cec5SDimitry Andric DwarfRangesSection = 4720b57cec5SDimitry Andric Ctx->getELFSection(".debug_ranges", DebugSecType, 0); 4730b57cec5SDimitry Andric DwarfMacinfoSection = 4740b57cec5SDimitry Andric Ctx->getELFSection(".debug_macinfo", DebugSecType, 0); 4755ffd83dbSDimitry Andric DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0); 4760b57cec5SDimitry Andric 4770b57cec5SDimitry Andric // DWARF5 Experimental Debug Info 4780b57cec5SDimitry Andric 4790b57cec5SDimitry Andric // Accelerator Tables 4800b57cec5SDimitry Andric DwarfDebugNamesSection = 4810b57cec5SDimitry Andric Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0); 4820b57cec5SDimitry Andric DwarfAccelNamesSection = 4830b57cec5SDimitry Andric Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0); 4840b57cec5SDimitry Andric DwarfAccelObjCSection = 4850b57cec5SDimitry Andric Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0); 4860b57cec5SDimitry Andric DwarfAccelNamespaceSection = 4870b57cec5SDimitry Andric Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0); 4880b57cec5SDimitry Andric DwarfAccelTypesSection = 4890b57cec5SDimitry Andric Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0); 4900b57cec5SDimitry Andric 4910b57cec5SDimitry Andric // String Offset and Address Sections 4920b57cec5SDimitry Andric DwarfStrOffSection = 4930b57cec5SDimitry Andric Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0); 4940b57cec5SDimitry Andric DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0); 4950b57cec5SDimitry Andric DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0); 4960b57cec5SDimitry Andric DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0); 4970b57cec5SDimitry Andric 4980b57cec5SDimitry Andric // Fission Sections 4990b57cec5SDimitry Andric DwarfInfoDWOSection = 5000b57cec5SDimitry Andric Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5010b57cec5SDimitry Andric DwarfTypesDWOSection = 5020b57cec5SDimitry Andric Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5030b57cec5SDimitry Andric DwarfAbbrevDWOSection = 5040b57cec5SDimitry Andric Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5050b57cec5SDimitry Andric DwarfStrDWOSection = Ctx->getELFSection( 5060b57cec5SDimitry Andric ".debug_str.dwo", DebugSecType, 507fe6060f1SDimitry Andric ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1); 5080b57cec5SDimitry Andric DwarfLineDWOSection = 5090b57cec5SDimitry Andric Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5100b57cec5SDimitry Andric DwarfLocDWOSection = 5110b57cec5SDimitry Andric Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5120b57cec5SDimitry Andric DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo", 5130b57cec5SDimitry Andric DebugSecType, ELF::SHF_EXCLUDE); 5140b57cec5SDimitry Andric DwarfRnglistsDWOSection = 5150b57cec5SDimitry Andric Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE); 516480093f4SDimitry Andric DwarfMacinfoDWOSection = 517480093f4SDimitry Andric Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5185ffd83dbSDimitry Andric DwarfMacroDWOSection = 5195ffd83dbSDimitry Andric Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE); 520480093f4SDimitry Andric 521480093f4SDimitry Andric DwarfLoclistsDWOSection = 522480093f4SDimitry Andric Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE); 5230b57cec5SDimitry Andric 5240b57cec5SDimitry Andric // DWP Sections 5250b57cec5SDimitry Andric DwarfCUIndexSection = 5260b57cec5SDimitry Andric Ctx->getELFSection(".debug_cu_index", DebugSecType, 0); 5270b57cec5SDimitry Andric DwarfTUIndexSection = 5280b57cec5SDimitry Andric Ctx->getELFSection(".debug_tu_index", DebugSecType, 0); 5290b57cec5SDimitry Andric 5300b57cec5SDimitry Andric StackMapSection = 5310b57cec5SDimitry Andric Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 5320b57cec5SDimitry Andric 5330b57cec5SDimitry Andric FaultMapSection = 5340b57cec5SDimitry Andric Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC); 5350b57cec5SDimitry Andric 5360b57cec5SDimitry Andric EHFrameSection = 5370b57cec5SDimitry Andric Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags); 5380b57cec5SDimitry Andric 5390b57cec5SDimitry Andric StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0); 540e8d8bef9SDimitry Andric 541e8d8bef9SDimitry Andric PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0); 542e8d8bef9SDimitry Andric PseudoProbeDescSection = 543e8d8bef9SDimitry Andric Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0); 544bdd1243dSDimitry Andric 545bdd1243dSDimitry Andric LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0); 5460b57cec5SDimitry Andric } 5470b57cec5SDimitry Andric 548fe6060f1SDimitry Andric void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) { 549*0fca6ea1SDimitry Andric TextSection = Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr); 550*0fca6ea1SDimitry Andric BSSSection = Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr); 551*0fca6ea1SDimitry Andric PPA1Section = Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(), 552*0fca6ea1SDimitry Andric TextSection, GOFF::SK_PPA1); 553*0fca6ea1SDimitry Andric PPA2Section = Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(), 554*0fca6ea1SDimitry Andric TextSection, GOFF::SK_PPA2); 555*0fca6ea1SDimitry Andric 556*0fca6ea1SDimitry Andric PPA2ListSection = 557*0fca6ea1SDimitry Andric Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), nullptr); 558*0fca6ea1SDimitry Andric 559*0fca6ea1SDimitry Andric ADASection = Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr); 560*0fca6ea1SDimitry Andric IDRLSection = Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr); 561fe6060f1SDimitry Andric } 562fe6060f1SDimitry Andric 5630b57cec5SDimitry Andric void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) { 5640b57cec5SDimitry Andric EHFrameSection = 5650b57cec5SDimitry Andric Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 566*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 5670b57cec5SDimitry Andric 5680b57cec5SDimitry Andric // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is 5690b57cec5SDimitry Andric // used to indicate to the linker that the text segment contains thumb instructions 5700b57cec5SDimitry Andric // and to set the ISA selection bit for calls accordingly. 5710b57cec5SDimitry Andric const bool IsThumb = T.getArch() == Triple::thumb; 5720b57cec5SDimitry Andric 5730b57cec5SDimitry Andric // COFF 5740b57cec5SDimitry Andric BSSSection = Ctx->getCOFFSection( 5750b57cec5SDimitry Andric ".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA | 576*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE); 5770b57cec5SDimitry Andric TextSection = Ctx->getCOFFSection( 5780b57cec5SDimitry Andric ".text", 5790b57cec5SDimitry Andric (IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) | 5800b57cec5SDimitry Andric COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE | 581*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 5820b57cec5SDimitry Andric DataSection = Ctx->getCOFFSection( 5830b57cec5SDimitry Andric ".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 584*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_WRITE); 585*0fca6ea1SDimitry Andric ReadOnlySection = 586*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 587*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 5880b57cec5SDimitry Andric 58981ad6265SDimitry Andric if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 || 59081ad6265SDimitry Andric T.getArch() == Triple::arm || T.getArch() == Triple::thumb) { 59181ad6265SDimitry Andric // On Windows with SEH, the LSDA is emitted into the .xdata section 5920b57cec5SDimitry Andric LSDASection = nullptr; 5930b57cec5SDimitry Andric } else { 5940b57cec5SDimitry Andric LSDASection = Ctx->getCOFFSection(".gcc_except_table", 5950b57cec5SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 596*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 5970b57cec5SDimitry Andric } 5980b57cec5SDimitry Andric 5990b57cec5SDimitry Andric // Debug info. 6000b57cec5SDimitry Andric COFFDebugSymbolsSection = 6010b57cec5SDimitry Andric Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 6020b57cec5SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 603*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ)); 6040b57cec5SDimitry Andric COFFDebugTypesSection = 6050b57cec5SDimitry Andric Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 6060b57cec5SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 607*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ)); 608*0fca6ea1SDimitry Andric COFFGlobalTypeHashesSection = 609*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE | 610*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 611*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ)); 6120b57cec5SDimitry Andric 6130b57cec5SDimitry Andric DwarfAbbrevSection = Ctx->getCOFFSection( 614*0fca6ea1SDimitry Andric ".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE | 615*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 616*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6170b57cec5SDimitry Andric DwarfInfoSection = Ctx->getCOFFSection( 618*0fca6ea1SDimitry Andric ".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE | 619*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 620*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6210b57cec5SDimitry Andric DwarfLineSection = Ctx->getCOFFSection( 622*0fca6ea1SDimitry Andric ".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE | 623*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 624*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6250b57cec5SDimitry Andric DwarfLineStrSection = Ctx->getCOFFSection( 626*0fca6ea1SDimitry Andric ".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE | 627*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 628*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6290b57cec5SDimitry Andric DwarfFrameSection = Ctx->getCOFFSection( 630*0fca6ea1SDimitry Andric ".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE | 631*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 632*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6330b57cec5SDimitry Andric DwarfPubNamesSection = Ctx->getCOFFSection( 634*0fca6ea1SDimitry Andric ".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE | 635*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 636*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6370b57cec5SDimitry Andric DwarfPubTypesSection = Ctx->getCOFFSection( 638*0fca6ea1SDimitry Andric ".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE | 639*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 640*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6410b57cec5SDimitry Andric DwarfGnuPubNamesSection = Ctx->getCOFFSection( 642*0fca6ea1SDimitry Andric ".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE | 643*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 644*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6450b57cec5SDimitry Andric DwarfGnuPubTypesSection = Ctx->getCOFFSection( 646*0fca6ea1SDimitry Andric ".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE | 647*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 648*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6490b57cec5SDimitry Andric DwarfStrSection = Ctx->getCOFFSection( 650*0fca6ea1SDimitry Andric ".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE | 651*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 652*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6530b57cec5SDimitry Andric DwarfStrOffSection = Ctx->getCOFFSection( 654*0fca6ea1SDimitry Andric ".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE | 655*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 656*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6570b57cec5SDimitry Andric DwarfLocSection = Ctx->getCOFFSection( 658*0fca6ea1SDimitry Andric ".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE | 659*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 660*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6615ffd83dbSDimitry Andric DwarfLoclistsSection = Ctx->getCOFFSection( 662*0fca6ea1SDimitry Andric ".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE | 663*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 664*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6650b57cec5SDimitry Andric DwarfARangesSection = Ctx->getCOFFSection( 666*0fca6ea1SDimitry Andric ".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE | 667*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 668*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6690b57cec5SDimitry Andric DwarfRangesSection = Ctx->getCOFFSection( 670*0fca6ea1SDimitry Andric ".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE | 671*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 672*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6735ffd83dbSDimitry Andric DwarfRnglistsSection = Ctx->getCOFFSection( 674*0fca6ea1SDimitry Andric ".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE | 675*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 676*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6770b57cec5SDimitry Andric DwarfMacinfoSection = Ctx->getCOFFSection( 678*0fca6ea1SDimitry Andric ".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 679*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 680*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6815ffd83dbSDimitry Andric DwarfMacroSection = Ctx->getCOFFSection( 682*0fca6ea1SDimitry Andric ".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE | 683*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 684*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 685480093f4SDimitry Andric DwarfMacinfoDWOSection = Ctx->getCOFFSection( 686*0fca6ea1SDimitry Andric ".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 687*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 688*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6895ffd83dbSDimitry Andric DwarfMacroDWOSection = Ctx->getCOFFSection( 690*0fca6ea1SDimitry Andric ".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 691*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 692*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6930b57cec5SDimitry Andric DwarfInfoDWOSection = Ctx->getCOFFSection( 694*0fca6ea1SDimitry Andric ".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 695*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 696*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 6970b57cec5SDimitry Andric DwarfTypesDWOSection = Ctx->getCOFFSection( 698*0fca6ea1SDimitry Andric ".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 699*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 700*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7010b57cec5SDimitry Andric DwarfAbbrevDWOSection = Ctx->getCOFFSection( 702*0fca6ea1SDimitry Andric ".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 703*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 704*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7050b57cec5SDimitry Andric DwarfStrDWOSection = Ctx->getCOFFSection( 706*0fca6ea1SDimitry Andric ".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 707*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 708*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7090b57cec5SDimitry Andric DwarfLineDWOSection = Ctx->getCOFFSection( 710*0fca6ea1SDimitry Andric ".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 711*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 712*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7130b57cec5SDimitry Andric DwarfLocDWOSection = Ctx->getCOFFSection( 714*0fca6ea1SDimitry Andric ".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 715*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 716*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7170b57cec5SDimitry Andric DwarfStrOffDWOSection = Ctx->getCOFFSection( 718*0fca6ea1SDimitry Andric ".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE | 719*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 720*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7210b57cec5SDimitry Andric DwarfAddrSection = Ctx->getCOFFSection( 722*0fca6ea1SDimitry Andric ".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE | 723*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 724*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7250b57cec5SDimitry Andric DwarfCUIndexSection = Ctx->getCOFFSection( 726*0fca6ea1SDimitry Andric ".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE | 727*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 728*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7290b57cec5SDimitry Andric DwarfTUIndexSection = Ctx->getCOFFSection( 730*0fca6ea1SDimitry Andric ".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE | 731*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 732*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7330b57cec5SDimitry Andric DwarfDebugNamesSection = Ctx->getCOFFSection( 734*0fca6ea1SDimitry Andric ".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE | 735*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 736*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7370b57cec5SDimitry Andric DwarfAccelNamesSection = Ctx->getCOFFSection( 738*0fca6ea1SDimitry Andric ".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE | 739*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 740*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7410b57cec5SDimitry Andric DwarfAccelNamespaceSection = Ctx->getCOFFSection( 742*0fca6ea1SDimitry Andric ".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE | 743*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 744*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7450b57cec5SDimitry Andric DwarfAccelTypesSection = Ctx->getCOFFSection( 746*0fca6ea1SDimitry Andric ".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE | 747*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 748*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7490b57cec5SDimitry Andric DwarfAccelObjCSection = Ctx->getCOFFSection( 750*0fca6ea1SDimitry Andric ".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE | 751*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 752*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7530b57cec5SDimitry Andric 7540b57cec5SDimitry Andric DrectveSection = Ctx->getCOFFSection( 755*0fca6ea1SDimitry Andric ".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE); 7560b57cec5SDimitry Andric 757*0fca6ea1SDimitry Andric PDataSection = 758*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 759*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7600b57cec5SDimitry Andric 761*0fca6ea1SDimitry Andric XDataSection = 762*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 763*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7640b57cec5SDimitry Andric 765*0fca6ea1SDimitry Andric SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO); 7660b57cec5SDimitry Andric 767*0fca6ea1SDimitry Andric GEHContSection = 768*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 769*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 770fe6060f1SDimitry Andric 771*0fca6ea1SDimitry Andric GFIDsSection = 772*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 773*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7740b57cec5SDimitry Andric 775*0fca6ea1SDimitry Andric GIATsSection = 776*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 777*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 778e8d8bef9SDimitry Andric 779*0fca6ea1SDimitry Andric GLJMPSection = 780*0fca6ea1SDimitry Andric Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 781*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 782480093f4SDimitry Andric 7830b57cec5SDimitry Andric TLSDataSection = Ctx->getCOFFSection( 7840b57cec5SDimitry Andric ".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ | 785*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_WRITE); 7860b57cec5SDimitry Andric 7870b57cec5SDimitry Andric StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps", 7880b57cec5SDimitry Andric COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | 789*0fca6ea1SDimitry Andric COFF::IMAGE_SCN_MEM_READ); 7900b57cec5SDimitry Andric } 7910b57cec5SDimitry Andric 79281ad6265SDimitry Andric void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) { 79381ad6265SDimitry Andric // Put everything in a single binary section. 79481ad6265SDimitry Andric TextSection = Ctx->getSPIRVSection(); 79581ad6265SDimitry Andric } 79681ad6265SDimitry Andric 7970b57cec5SDimitry Andric void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) { 7980b57cec5SDimitry Andric TextSection = Ctx->getWasmSection(".text", SectionKind::getText()); 7990b57cec5SDimitry Andric DataSection = Ctx->getWasmSection(".data", SectionKind::getData()); 8000b57cec5SDimitry Andric 8010b57cec5SDimitry Andric DwarfLineSection = 8020b57cec5SDimitry Andric Ctx->getWasmSection(".debug_line", SectionKind::getMetadata()); 8030b57cec5SDimitry Andric DwarfLineStrSection = 804fe6060f1SDimitry Andric Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(), 805fe6060f1SDimitry Andric wasm::WASM_SEG_FLAG_STRINGS); 806fe6060f1SDimitry Andric DwarfStrSection = Ctx->getWasmSection( 807fe6060f1SDimitry Andric ".debug_str", SectionKind::getMetadata(), wasm::WASM_SEG_FLAG_STRINGS); 8080b57cec5SDimitry Andric DwarfLocSection = 8090b57cec5SDimitry Andric Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata()); 8100b57cec5SDimitry Andric DwarfAbbrevSection = 8110b57cec5SDimitry Andric Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata()); 8120b57cec5SDimitry Andric DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata()); 8130b57cec5SDimitry Andric DwarfRangesSection = 8140b57cec5SDimitry Andric Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata()); 8150b57cec5SDimitry Andric DwarfMacinfoSection = 8160b57cec5SDimitry Andric Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata()); 8175ffd83dbSDimitry Andric DwarfMacroSection = 8185ffd83dbSDimitry Andric Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata()); 8190b57cec5SDimitry Andric DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 8200b57cec5SDimitry Andric DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 8210b57cec5SDimitry Andric DwarfInfoSection = 8220b57cec5SDimitry Andric Ctx->getWasmSection(".debug_info", SectionKind::getMetadata()); 8230b57cec5SDimitry Andric DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata()); 8240b57cec5SDimitry Andric DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata()); 8250b57cec5SDimitry Andric DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata()); 826e8d8bef9SDimitry Andric DwarfGnuPubNamesSection = 827e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata()); 828e8d8bef9SDimitry Andric DwarfGnuPubTypesSection = 829e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata()); 8300b57cec5SDimitry Andric 831d65cd7a5SDimitry Andric DwarfDebugNamesSection = 832d65cd7a5SDimitry Andric Ctx->getWasmSection(".debug_names", SectionKind::getMetadata()); 833d65cd7a5SDimitry Andric DwarfStrOffSection = 834d65cd7a5SDimitry Andric Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata()); 835d65cd7a5SDimitry Andric DwarfAddrSection = 836d65cd7a5SDimitry Andric Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata()); 837d65cd7a5SDimitry Andric DwarfRnglistsSection = 838d65cd7a5SDimitry Andric Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata()); 839d65cd7a5SDimitry Andric DwarfLoclistsSection = 840d65cd7a5SDimitry Andric Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata()); 841d65cd7a5SDimitry Andric 842e8d8bef9SDimitry Andric // Fission Sections 843e8d8bef9SDimitry Andric DwarfInfoDWOSection = 844e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata()); 845e8d8bef9SDimitry Andric DwarfTypesDWOSection = 846e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata()); 847e8d8bef9SDimitry Andric DwarfAbbrevDWOSection = 848e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata()); 849e8d8bef9SDimitry Andric DwarfStrDWOSection = 850fe6060f1SDimitry Andric Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(), 851fe6060f1SDimitry Andric wasm::WASM_SEG_FLAG_STRINGS); 852e8d8bef9SDimitry Andric DwarfLineDWOSection = 853e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata()); 854e8d8bef9SDimitry Andric DwarfLocDWOSection = 855e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata()); 856e8d8bef9SDimitry Andric DwarfStrOffDWOSection = 857e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata()); 858e8d8bef9SDimitry Andric DwarfRnglistsDWOSection = 859e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata()); 860e8d8bef9SDimitry Andric DwarfMacinfoDWOSection = 861e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata()); 862e8d8bef9SDimitry Andric DwarfMacroDWOSection = 863e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata()); 864e8d8bef9SDimitry Andric 865e8d8bef9SDimitry Andric DwarfLoclistsDWOSection = 866e8d8bef9SDimitry Andric Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata()); 867e8d8bef9SDimitry Andric 868e8d8bef9SDimitry Andric // DWP Sections 869e8d8bef9SDimitry Andric DwarfCUIndexSection = 870fe6060f1SDimitry Andric Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata()); 871e8d8bef9SDimitry Andric DwarfTUIndexSection = 872fe6060f1SDimitry Andric Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata()); 873e8d8bef9SDimitry Andric 8740b57cec5SDimitry Andric // Wasm use data section for LSDA. 8750b57cec5SDimitry Andric // TODO Consider putting each function's exception table in a separate 8760b57cec5SDimitry Andric // section, as in -function-sections, to facilitate lld's --gc-section. 8770b57cec5SDimitry Andric LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table", 8780b57cec5SDimitry Andric SectionKind::getReadOnlyWithRel()); 8790b57cec5SDimitry Andric 8800b57cec5SDimitry Andric // TODO: Define more sections. 8810b57cec5SDimitry Andric } 8820b57cec5SDimitry Andric 8830b57cec5SDimitry Andric void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) { 8840b57cec5SDimitry Andric // The default csect for program code. Functions without a specified section 8850b57cec5SDimitry Andric // get placed into this csect. The choice of csect name is not a property of 88606c3fb27SDimitry Andric // the ABI or object file format, but various tools rely on the section 88706c3fb27SDimitry Andric // name being empty (considering named symbols to be "user symbol names"). 8880b57cec5SDimitry Andric TextSection = Ctx->getXCOFFSection( 8895f757f3fSDimitry Andric "..text..", // Use a non-null name to work around an AIX assembler bug... 8905f757f3fSDimitry Andric SectionKind::getText(), 891fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD), 892fe6060f1SDimitry Andric /* MultiSymbolsAllowed*/ true); 8938bcb0991SDimitry Andric 8945f757f3fSDimitry Andric // ... but use a null name when generating the symbol table. 8955f757f3fSDimitry Andric MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection); 8965f757f3fSDimitry Andric TS->getQualNameSymbol()->setSymbolTableName(""); 8975f757f3fSDimitry Andric TS->setSymbolTableName(""); 8985f757f3fSDimitry Andric 8998bcb0991SDimitry Andric DataSection = Ctx->getXCOFFSection( 900fe6060f1SDimitry Andric ".data", SectionKind::getData(), 901fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD), 902fe6060f1SDimitry Andric /* MultiSymbolsAllowed*/ true); 903480093f4SDimitry Andric 904480093f4SDimitry Andric ReadOnlySection = Ctx->getXCOFFSection( 905fe6060f1SDimitry Andric ".rodata", SectionKind::getReadOnly(), 906fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 907fe6060f1SDimitry Andric /* MultiSymbolsAllowed*/ true); 908349cc55cSDimitry Andric ReadOnlySection->setAlignment(Align(4)); 909349cc55cSDimitry Andric 910349cc55cSDimitry Andric ReadOnly8Section = Ctx->getXCOFFSection( 911349cc55cSDimitry Andric ".rodata.8", SectionKind::getReadOnly(), 912349cc55cSDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 913349cc55cSDimitry Andric /* MultiSymbolsAllowed*/ true); 914349cc55cSDimitry Andric ReadOnly8Section->setAlignment(Align(8)); 915349cc55cSDimitry Andric 916349cc55cSDimitry Andric ReadOnly16Section = Ctx->getXCOFFSection( 917349cc55cSDimitry Andric ".rodata.16", SectionKind::getReadOnly(), 918349cc55cSDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD), 919349cc55cSDimitry Andric /* MultiSymbolsAllowed*/ true); 920349cc55cSDimitry Andric ReadOnly16Section->setAlignment(Align(16)); 9215ffd83dbSDimitry Andric 922fe6060f1SDimitry Andric TLSDataSection = Ctx->getXCOFFSection( 923fe6060f1SDimitry Andric ".tdata", SectionKind::getThreadData(), 924fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD), 925fe6060f1SDimitry Andric /* MultiSymbolsAllowed*/ true); 926fe6060f1SDimitry Andric 927fe6060f1SDimitry Andric TOCBaseSection = Ctx->getXCOFFSection( 928fe6060f1SDimitry Andric "TOC", SectionKind::getData(), 929fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0, 930fe6060f1SDimitry Andric XCOFF::XTY_SD)); 9315ffd83dbSDimitry Andric 9325ffd83dbSDimitry Andric // The TOC-base always has 0 size, but 4 byte alignment. 9335ffd83dbSDimitry Andric TOCBaseSection->setAlignment(Align(4)); 9345ffd83dbSDimitry Andric 935fe6060f1SDimitry Andric LSDASection = Ctx->getXCOFFSection( 936fe6060f1SDimitry Andric ".gcc_except_table", SectionKind::getReadOnly(), 937fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, 938fe6060f1SDimitry Andric XCOFF::XTY_SD)); 939e8d8bef9SDimitry Andric 940fe6060f1SDimitry Andric CompactUnwindSection = Ctx->getXCOFFSection( 941fe6060f1SDimitry Andric ".eh_info_table", SectionKind::getData(), 942fe6060f1SDimitry Andric XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, 943fe6060f1SDimitry Andric XCOFF::XTY_SD)); 944e8d8bef9SDimitry Andric 9455ffd83dbSDimitry Andric // DWARF sections for XCOFF are not csects. They are special STYP_DWARF 9465ffd83dbSDimitry Andric // sections, and the individual DWARF sections are distinguished by their 9475ffd83dbSDimitry Andric // section subtype. 948fe6060f1SDimitry Andric DwarfAbbrevSection = Ctx->getXCOFFSection( 949bdd1243dSDimitry Andric ".dwabrev", SectionKind::getMetadata(), 950bdd1243dSDimitry Andric /* CsectProperties */ std::nullopt, 951*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV); 952fe6060f1SDimitry Andric 953fe6060f1SDimitry Andric DwarfInfoSection = Ctx->getXCOFFSection( 954bdd1243dSDimitry Andric ".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 955*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO); 956fe6060f1SDimitry Andric 957fe6060f1SDimitry Andric DwarfLineSection = Ctx->getXCOFFSection( 958bdd1243dSDimitry Andric ".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 959*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE); 960fe6060f1SDimitry Andric 961fe6060f1SDimitry Andric DwarfFrameSection = Ctx->getXCOFFSection( 962bdd1243dSDimitry Andric ".dwframe", SectionKind::getMetadata(), 963bdd1243dSDimitry Andric /* CsectProperties */ std::nullopt, 964*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME); 965fe6060f1SDimitry Andric 966fe6060f1SDimitry Andric DwarfPubNamesSection = Ctx->getXCOFFSection( 967bdd1243dSDimitry Andric ".dwpbnms", SectionKind::getMetadata(), 968bdd1243dSDimitry Andric /* CsectProperties */ std::nullopt, 969*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS); 970fe6060f1SDimitry Andric 971fe6060f1SDimitry Andric DwarfPubTypesSection = Ctx->getXCOFFSection( 972bdd1243dSDimitry Andric ".dwpbtyp", SectionKind::getMetadata(), 973bdd1243dSDimitry Andric /* CsectProperties */ std::nullopt, 974*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP); 975fe6060f1SDimitry Andric 976fe6060f1SDimitry Andric DwarfStrSection = Ctx->getXCOFFSection( 977bdd1243dSDimitry Andric ".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 978*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR); 979fe6060f1SDimitry Andric 980fe6060f1SDimitry Andric DwarfLocSection = Ctx->getXCOFFSection( 981bdd1243dSDimitry Andric ".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 982*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC); 983fe6060f1SDimitry Andric 984fe6060f1SDimitry Andric DwarfARangesSection = Ctx->getXCOFFSection( 985bdd1243dSDimitry Andric ".dwarnge", SectionKind::getMetadata(), 986bdd1243dSDimitry Andric /* CsectProperties */ std::nullopt, 987*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE); 988fe6060f1SDimitry Andric 989fe6060f1SDimitry Andric DwarfRangesSection = Ctx->getXCOFFSection( 990bdd1243dSDimitry Andric ".dwrnges", SectionKind::getMetadata(), 991bdd1243dSDimitry Andric /* CsectProperties */ std::nullopt, 992*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES); 993fe6060f1SDimitry Andric 994fe6060f1SDimitry Andric DwarfMacinfoSection = Ctx->getXCOFFSection( 995bdd1243dSDimitry Andric ".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt, 996*0fca6ea1SDimitry Andric /* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC); 9970b57cec5SDimitry Andric } 9980b57cec5SDimitry Andric 99981ad6265SDimitry Andric void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) { 100081ad6265SDimitry Andric // At the moment the DXBC section should end up empty. 100181ad6265SDimitry Andric TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText()); 100281ad6265SDimitry Andric } 100381ad6265SDimitry Andric 100481ad6265SDimitry Andric MCObjectFileInfo::~MCObjectFileInfo() = default; 1005349cc55cSDimitry Andric 1006fe6060f1SDimitry Andric void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC, 10070b57cec5SDimitry Andric bool LargeCodeModel) { 10080b57cec5SDimitry Andric PositionIndependent = PIC; 1009fe6060f1SDimitry Andric Ctx = &MCCtx; 10100b57cec5SDimitry Andric 10110b57cec5SDimitry Andric // Common. 10120b57cec5SDimitry Andric SupportsWeakOmittedEHFrame = true; 10130b57cec5SDimitry Andric SupportsCompactUnwindWithoutEHFrame = false; 10140b57cec5SDimitry Andric OmitDwarfIfHaveCompactUnwind = false; 10150b57cec5SDimitry Andric 10160b57cec5SDimitry Andric FDECFIEncoding = dwarf::DW_EH_PE_absptr; 10170b57cec5SDimitry Andric 10180b57cec5SDimitry Andric CompactUnwindDwarfEHFrameOnly = 0; 10190b57cec5SDimitry Andric 10200b57cec5SDimitry Andric EHFrameSection = nullptr; // Created on demand. 10210b57cec5SDimitry Andric CompactUnwindSection = nullptr; // Used only by selected targets. 10220b57cec5SDimitry Andric DwarfAccelNamesSection = nullptr; // Used only by selected targets. 10230b57cec5SDimitry Andric DwarfAccelObjCSection = nullptr; // Used only by selected targets. 10240b57cec5SDimitry Andric DwarfAccelNamespaceSection = nullptr; // Used only by selected targets. 10250b57cec5SDimitry Andric DwarfAccelTypesSection = nullptr; // Used only by selected targets. 10260b57cec5SDimitry Andric 1027fe6060f1SDimitry Andric Triple TheTriple = Ctx->getTargetTriple(); 1028fe6060f1SDimitry Andric switch (Ctx->getObjectFileType()) { 1029fe6060f1SDimitry Andric case MCContext::IsMachO: 1030fe6060f1SDimitry Andric initMachOMCObjectFileInfo(TheTriple); 10310b57cec5SDimitry Andric break; 1032fe6060f1SDimitry Andric case MCContext::IsCOFF: 1033fe6060f1SDimitry Andric initCOFFMCObjectFileInfo(TheTriple); 10340b57cec5SDimitry Andric break; 1035fe6060f1SDimitry Andric case MCContext::IsELF: 1036fe6060f1SDimitry Andric initELFMCObjectFileInfo(TheTriple, LargeCodeModel); 10370b57cec5SDimitry Andric break; 1038fe6060f1SDimitry Andric case MCContext::IsGOFF: 1039fe6060f1SDimitry Andric initGOFFMCObjectFileInfo(TheTriple); 10400b57cec5SDimitry Andric break; 104181ad6265SDimitry Andric case MCContext::IsSPIRV: 104281ad6265SDimitry Andric initSPIRVMCObjectFileInfo(TheTriple); 104381ad6265SDimitry Andric break; 1044fe6060f1SDimitry Andric case MCContext::IsWasm: 1045fe6060f1SDimitry Andric initWasmMCObjectFileInfo(TheTriple); 1046e8d8bef9SDimitry Andric break; 1047fe6060f1SDimitry Andric case MCContext::IsXCOFF: 1048fe6060f1SDimitry Andric initXCOFFMCObjectFileInfo(TheTriple); 10490b57cec5SDimitry Andric break; 105081ad6265SDimitry Andric case MCContext::IsDXContainer: 105181ad6265SDimitry Andric initDXContainerObjectFileInfo(TheTriple); 105281ad6265SDimitry Andric break; 10530b57cec5SDimitry Andric } 10540b57cec5SDimitry Andric } 10550b57cec5SDimitry Andric 10560b57cec5SDimitry Andric MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name, 10570b57cec5SDimitry Andric uint64_t Hash) const { 1058fe6060f1SDimitry Andric switch (Ctx->getTargetTriple().getObjectFormat()) { 10590b57cec5SDimitry Andric case Triple::ELF: 10600b57cec5SDimitry Andric return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0, 1061fe6060f1SDimitry Andric utostr(Hash), /*IsComdat=*/true); 1062e8d8bef9SDimitry Andric case Triple::Wasm: 1063fe6060f1SDimitry Andric return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0, 1064fe6060f1SDimitry Andric utostr(Hash), MCContext::GenericSectionID); 10650b57cec5SDimitry Andric case Triple::MachO: 10660b57cec5SDimitry Andric case Triple::COFF: 1067e8d8bef9SDimitry Andric case Triple::GOFF: 106881ad6265SDimitry Andric case Triple::SPIRV: 10690b57cec5SDimitry Andric case Triple::XCOFF: 107081ad6265SDimitry Andric case Triple::DXContainer: 10710b57cec5SDimitry Andric case Triple::UnknownObjectFormat: 10720b57cec5SDimitry Andric report_fatal_error("Cannot get DWARF comdat section for this object file " 10730b57cec5SDimitry Andric "format: not implemented."); 10740b57cec5SDimitry Andric break; 10750b57cec5SDimitry Andric } 10760b57cec5SDimitry Andric llvm_unreachable("Unknown ObjectFormatType"); 10770b57cec5SDimitry Andric } 10780b57cec5SDimitry Andric 10790b57cec5SDimitry Andric MCSection * 10800b57cec5SDimitry Andric MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const { 1081bdd1243dSDimitry Andric if ((Ctx->getObjectFileType() != MCContext::IsELF) || 1082bdd1243dSDimitry Andric Ctx->getTargetTriple().isPS4()) 10830b57cec5SDimitry Andric return StackSizesSection; 10840b57cec5SDimitry Andric 10850b57cec5SDimitry Andric const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 10860b57cec5SDimitry Andric unsigned Flags = ELF::SHF_LINK_ORDER; 10870b57cec5SDimitry Andric StringRef GroupName; 10880b57cec5SDimitry Andric if (const MCSymbol *Group = ElfSec.getGroup()) { 10890b57cec5SDimitry Andric GroupName = Group->getName(); 10900b57cec5SDimitry Andric Flags |= ELF::SHF_GROUP; 10910b57cec5SDimitry Andric } 10920b57cec5SDimitry Andric 10930b57cec5SDimitry Andric return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0, 1094fe6060f1SDimitry Andric GroupName, true, ElfSec.getUniqueID(), 10955ffd83dbSDimitry Andric cast<MCSymbolELF>(TextSec.getBeginSymbol())); 10960b57cec5SDimitry Andric } 1097e8d8bef9SDimitry Andric 1098e8d8bef9SDimitry Andric MCSection * 1099e8d8bef9SDimitry Andric MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const { 1100fe6060f1SDimitry Andric if (Ctx->getObjectFileType() != MCContext::IsELF) 1101e8d8bef9SDimitry Andric return nullptr; 1102e8d8bef9SDimitry Andric 1103e8d8bef9SDimitry Andric const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1104e8d8bef9SDimitry Andric unsigned Flags = ELF::SHF_LINK_ORDER; 1105e8d8bef9SDimitry Andric StringRef GroupName; 1106e8d8bef9SDimitry Andric if (const MCSymbol *Group = ElfSec.getGroup()) { 1107e8d8bef9SDimitry Andric GroupName = Group->getName(); 1108e8d8bef9SDimitry Andric Flags |= ELF::SHF_GROUP; 1109e8d8bef9SDimitry Andric } 1110e8d8bef9SDimitry Andric 1111e8d8bef9SDimitry Andric // Use the text section's begin symbol and unique ID to create a separate 1112e8d8bef9SDimitry Andric // .llvm_bb_addr_map section associated with every unique text section. 1113e8d8bef9SDimitry Andric return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP, 1114fe6060f1SDimitry Andric Flags, 0, GroupName, true, ElfSec.getUniqueID(), 1115e8d8bef9SDimitry Andric cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1116e8d8bef9SDimitry Andric } 1117e8d8bef9SDimitry Andric 1118e8d8bef9SDimitry Andric MCSection * 1119bdd1243dSDimitry Andric MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const { 1120bdd1243dSDimitry Andric if (Ctx->getObjectFileType() != MCContext::IsELF) 1121bdd1243dSDimitry Andric return nullptr; 1122bdd1243dSDimitry Andric 1123bdd1243dSDimitry Andric const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec); 1124bdd1243dSDimitry Andric unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC; 1125bdd1243dSDimitry Andric StringRef GroupName; 1126bdd1243dSDimitry Andric if (const MCSymbol *Group = ElfSec.getGroup()) { 1127bdd1243dSDimitry Andric GroupName = Group->getName(); 1128bdd1243dSDimitry Andric Flags |= ELF::SHF_GROUP; 1129bdd1243dSDimitry Andric } 1130bdd1243dSDimitry Andric 1131bdd1243dSDimitry Andric return Ctx->getELFSection(".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0, 1132bdd1243dSDimitry Andric GroupName, 1133bdd1243dSDimitry Andric /*IsComdat=*/true, ElfSec.getUniqueID(), 1134bdd1243dSDimitry Andric cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1135bdd1243dSDimitry Andric } 1136bdd1243dSDimitry Andric 1137bdd1243dSDimitry Andric MCSection * 1138bdd1243dSDimitry Andric MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const { 113906c3fb27SDimitry Andric if (Ctx->getObjectFileType() != MCContext::IsELF) 1140e8d8bef9SDimitry Andric return PseudoProbeSection; 114106c3fb27SDimitry Andric 114206c3fb27SDimitry Andric const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec); 114306c3fb27SDimitry Andric unsigned Flags = ELF::SHF_LINK_ORDER; 114406c3fb27SDimitry Andric StringRef GroupName; 114506c3fb27SDimitry Andric if (const MCSymbol *Group = ElfSec.getGroup()) { 114606c3fb27SDimitry Andric GroupName = Group->getName(); 114706c3fb27SDimitry Andric Flags |= ELF::SHF_GROUP; 114806c3fb27SDimitry Andric } 114906c3fb27SDimitry Andric 115006c3fb27SDimitry Andric return Ctx->getELFSection(PseudoProbeSection->getName(), ELF::SHT_PROGBITS, 115106c3fb27SDimitry Andric Flags, 0, GroupName, true, ElfSec.getUniqueID(), 115206c3fb27SDimitry Andric cast<MCSymbolELF>(TextSec.getBeginSymbol())); 1153e8d8bef9SDimitry Andric } 1154e8d8bef9SDimitry Andric 1155e8d8bef9SDimitry Andric MCSection * 1156e8d8bef9SDimitry Andric MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const { 1157fe6060f1SDimitry Andric if (Ctx->getObjectFileType() == MCContext::IsELF) { 1158e8d8bef9SDimitry Andric // Create a separate comdat group for each function's descriptor in order 1159e8d8bef9SDimitry Andric // for the linker to deduplicate. The duplication, must be from different 1160e8d8bef9SDimitry Andric // tranlation unit, can come from: 1161e8d8bef9SDimitry Andric // 1. Inline functions defined in header files; 1162e8d8bef9SDimitry Andric // 2. ThinLTO imported funcions; 1163e8d8bef9SDimitry Andric // 3. Weak-linkage definitions. 1164e8d8bef9SDimitry Andric // Use a concatenation of the section name and the function name as the 1165e8d8bef9SDimitry Andric // group name so that descriptor-only groups won't be folded with groups of 1166e8d8bef9SDimitry Andric // code. 1167fe6060f1SDimitry Andric if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) { 1168e8d8bef9SDimitry Andric auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection); 1169e8d8bef9SDimitry Andric auto Flags = S->getFlags() | ELF::SHF_GROUP; 1170e8d8bef9SDimitry Andric return Ctx->getELFSection(S->getName(), S->getType(), Flags, 1171e8d8bef9SDimitry Andric S->getEntrySize(), 1172fe6060f1SDimitry Andric S->getName() + "_" + FuncName, 1173fe6060f1SDimitry Andric /*IsComdat=*/true); 1174e8d8bef9SDimitry Andric } 1175e8d8bef9SDimitry Andric } 1176e8d8bef9SDimitry Andric return PseudoProbeDescSection; 1177e8d8bef9SDimitry Andric } 1178bdd1243dSDimitry Andric 1179bdd1243dSDimitry Andric MCSection *MCObjectFileInfo::getLLVMStatsSection() const { 1180bdd1243dSDimitry Andric return LLVMStatsSection; 1181bdd1243dSDimitry Andric } 1182bdd1243dSDimitry Andric 1183bdd1243dSDimitry Andric MCSection *MCObjectFileInfo::getPCSection(StringRef Name, 1184bdd1243dSDimitry Andric const MCSection *TextSec) const { 1185bdd1243dSDimitry Andric if (Ctx->getObjectFileType() != MCContext::IsELF) 1186bdd1243dSDimitry Andric return nullptr; 1187bdd1243dSDimitry Andric 1188bdd1243dSDimitry Andric // SHF_WRITE for relocations, and let user post-process data in-place. 1189bdd1243dSDimitry Andric unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER; 1190bdd1243dSDimitry Andric 1191bdd1243dSDimitry Andric if (!TextSec) 1192bdd1243dSDimitry Andric TextSec = getTextSection(); 1193bdd1243dSDimitry Andric 1194bdd1243dSDimitry Andric StringRef GroupName; 1195bdd1243dSDimitry Andric const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec); 1196bdd1243dSDimitry Andric if (const MCSymbol *Group = ElfSec.getGroup()) { 1197bdd1243dSDimitry Andric GroupName = Group->getName(); 1198bdd1243dSDimitry Andric Flags |= ELF::SHF_GROUP; 1199bdd1243dSDimitry Andric } 1200bdd1243dSDimitry Andric return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true, 1201bdd1243dSDimitry Andric ElfSec.getUniqueID(), 1202bdd1243dSDimitry Andric cast<MCSymbolELF>(TextSec->getBeginSymbol())); 1203bdd1243dSDimitry Andric } 1204