Path: blob/main/contrib/llvm-project/llvm/lib/MC/MCObjectFileInfo.cpp
35232 views
//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#include "llvm/MC/MCObjectFileInfo.h"9#include "llvm/ADT/StringExtras.h"10#include "llvm/BinaryFormat/COFF.h"11#include "llvm/BinaryFormat/ELF.h"12#include "llvm/BinaryFormat/Wasm.h"13#include "llvm/MC/MCAsmInfo.h"14#include "llvm/MC/MCContext.h"15#include "llvm/MC/MCSection.h"16#include "llvm/MC/MCSectionCOFF.h"17#include "llvm/MC/MCSectionDXContainer.h"18#include "llvm/MC/MCSectionELF.h"19#include "llvm/MC/MCSectionGOFF.h"20#include "llvm/MC/MCSectionMachO.h"21#include "llvm/MC/MCSectionSPIRV.h"22#include "llvm/MC/MCSectionWasm.h"23#include "llvm/MC/MCSectionXCOFF.h"24#include "llvm/Support/Casting.h"25#include "llvm/TargetParser/Triple.h"2627using namespace llvm;2829static bool useCompactUnwind(const Triple &T) {30// Only on darwin.31if (!T.isOSDarwin())32return false;3334// aarch64 always has it.35if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)36return true;3738// armv7k always has it.39if (T.isWatchABI())40return true;4142// Use it on newer version of OS X.43if (T.isMacOSX() && !T.isMacOSXVersionLT(10, 6))44return true;4546// And the iOS simulator.47if (T.isiOS() && T.isX86())48return true;4950// The rest of the simulators always have it.51if (T.isSimulatorEnvironment())52return true;5354// XROS always has it.55if (T.isXROS())56return true;5758return false;59}6061void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {62// MachO63SupportsWeakOmittedEHFrame = false;6465EHFrameSection = Ctx->getMachOSection(66"__TEXT", "__eh_frame",67MachO::S_COALESCED | MachO::S_ATTR_NO_TOC |68MachO::S_ATTR_STRIP_STATIC_SYMS | MachO::S_ATTR_LIVE_SUPPORT,69SectionKind::getReadOnly());7071if (T.isOSDarwin() &&72(T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32 ||73T.isSimulatorEnvironment()))74SupportsCompactUnwindWithoutEHFrame = true;7576switch (Ctx->emitDwarfUnwindInfo()) {77case EmitDwarfUnwindType::Always:78OmitDwarfIfHaveCompactUnwind = false;79break;80case EmitDwarfUnwindType::NoCompactUnwind:81OmitDwarfIfHaveCompactUnwind = true;82break;83case EmitDwarfUnwindType::Default:84OmitDwarfIfHaveCompactUnwind =85T.isWatchABI() || SupportsCompactUnwindWithoutEHFrame;86break;87}8889FDECFIEncoding = dwarf::DW_EH_PE_pcrel;9091TextSection // .text92= Ctx->getMachOSection("__TEXT", "__text",93MachO::S_ATTR_PURE_INSTRUCTIONS,94SectionKind::getText());95DataSection // .data96= Ctx->getMachOSection("__DATA", "__data", 0, SectionKind::getData());9798// BSSSection might not be expected initialized on msvc.99BSSSection = nullptr;100101TLSDataSection // .tdata102= Ctx->getMachOSection("__DATA", "__thread_data",103MachO::S_THREAD_LOCAL_REGULAR,104SectionKind::getData());105TLSBSSSection // .tbss106= Ctx->getMachOSection("__DATA", "__thread_bss",107MachO::S_THREAD_LOCAL_ZEROFILL,108SectionKind::getThreadBSS());109110// TODO: Verify datarel below.111TLSTLVSection // .tlv112= Ctx->getMachOSection("__DATA", "__thread_vars",113MachO::S_THREAD_LOCAL_VARIABLES,114SectionKind::getData());115116TLSThreadInitSection = Ctx->getMachOSection(117"__DATA", "__thread_init", MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS,118SectionKind::getData());119120CStringSection // .cstring121= Ctx->getMachOSection("__TEXT", "__cstring",122MachO::S_CSTRING_LITERALS,123SectionKind::getMergeable1ByteCString());124UStringSection125= Ctx->getMachOSection("__TEXT","__ustring", 0,126SectionKind::getMergeable2ByteCString());127FourByteConstantSection // .literal4128= Ctx->getMachOSection("__TEXT", "__literal4",129MachO::S_4BYTE_LITERALS,130SectionKind::getMergeableConst4());131EightByteConstantSection // .literal8132= Ctx->getMachOSection("__TEXT", "__literal8",133MachO::S_8BYTE_LITERALS,134SectionKind::getMergeableConst8());135136SixteenByteConstantSection // .literal16137= Ctx->getMachOSection("__TEXT", "__literal16",138MachO::S_16BYTE_LITERALS,139SectionKind::getMergeableConst16());140141ReadOnlySection // .const142= Ctx->getMachOSection("__TEXT", "__const", 0,143SectionKind::getReadOnly());144145// If the target is not powerpc, map the coal sections to the non-coal146// sections.147//148// "__TEXT/__textcoal_nt" => section "__TEXT/__text"149// "__TEXT/__const_coal" => section "__TEXT/__const"150// "__DATA/__datacoal_nt" => section "__DATA/__data"151Triple::ArchType ArchTy = T.getArch();152153ConstDataSection // .const_data154= Ctx->getMachOSection("__DATA", "__const", 0,155SectionKind::getReadOnlyWithRel());156157if (ArchTy == Triple::ppc || ArchTy == Triple::ppc64) {158TextCoalSection159= Ctx->getMachOSection("__TEXT", "__textcoal_nt",160MachO::S_COALESCED |161MachO::S_ATTR_PURE_INSTRUCTIONS,162SectionKind::getText());163ConstTextCoalSection164= Ctx->getMachOSection("__TEXT", "__const_coal",165MachO::S_COALESCED,166SectionKind::getReadOnly());167DataCoalSection = Ctx->getMachOSection(168"__DATA", "__datacoal_nt", MachO::S_COALESCED, SectionKind::getData());169ConstDataCoalSection = DataCoalSection;170} else {171TextCoalSection = TextSection;172ConstTextCoalSection = ReadOnlySection;173DataCoalSection = DataSection;174ConstDataCoalSection = ConstDataSection;175}176177DataCommonSection178= Ctx->getMachOSection("__DATA","__common",179MachO::S_ZEROFILL,180SectionKind::getBSS());181DataBSSSection182= Ctx->getMachOSection("__DATA","__bss", MachO::S_ZEROFILL,183SectionKind::getBSS());184185186LazySymbolPointerSection187= Ctx->getMachOSection("__DATA", "__la_symbol_ptr",188MachO::S_LAZY_SYMBOL_POINTERS,189SectionKind::getMetadata());190NonLazySymbolPointerSection191= Ctx->getMachOSection("__DATA", "__nl_symbol_ptr",192MachO::S_NON_LAZY_SYMBOL_POINTERS,193SectionKind::getMetadata());194195ThreadLocalPointerSection196= Ctx->getMachOSection("__DATA", "__thread_ptr",197MachO::S_THREAD_LOCAL_VARIABLE_POINTERS,198SectionKind::getMetadata());199200AddrSigSection = Ctx->getMachOSection("__DATA", "__llvm_addrsig", 0,201SectionKind::getData());202203// Exception Handling.204LSDASection = Ctx->getMachOSection("__TEXT", "__gcc_except_tab", 0,205SectionKind::getReadOnlyWithRel());206207COFFDebugSymbolsSection = nullptr;208COFFDebugTypesSection = nullptr;209COFFGlobalTypeHashesSection = nullptr;210211if (useCompactUnwind(T)) {212CompactUnwindSection =213Ctx->getMachOSection("__LD", "__compact_unwind", MachO::S_ATTR_DEBUG,214SectionKind::getReadOnly());215216if (T.isX86())217CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_X86_64_MODE_DWARF218else if (T.getArch() == Triple::aarch64 || T.getArch() == Triple::aarch64_32)219CompactUnwindDwarfEHFrameOnly = 0x03000000; // UNWIND_ARM64_MODE_DWARF220else if (T.getArch() == Triple::arm || T.getArch() == Triple::thumb)221CompactUnwindDwarfEHFrameOnly = 0x04000000; // UNWIND_ARM_MODE_DWARF222}223224// Debug Information.225DwarfDebugNamesSection =226Ctx->getMachOSection("__DWARF", "__debug_names", MachO::S_ATTR_DEBUG,227SectionKind::getMetadata(), "debug_names_begin");228DwarfAccelNamesSection =229Ctx->getMachOSection("__DWARF", "__apple_names", MachO::S_ATTR_DEBUG,230SectionKind::getMetadata(), "names_begin");231DwarfAccelObjCSection =232Ctx->getMachOSection("__DWARF", "__apple_objc", MachO::S_ATTR_DEBUG,233SectionKind::getMetadata(), "objc_begin");234// 16 character section limit...235DwarfAccelNamespaceSection =236Ctx->getMachOSection("__DWARF", "__apple_namespac", MachO::S_ATTR_DEBUG,237SectionKind::getMetadata(), "namespac_begin");238DwarfAccelTypesSection =239Ctx->getMachOSection("__DWARF", "__apple_types", MachO::S_ATTR_DEBUG,240SectionKind::getMetadata(), "types_begin");241242DwarfSwiftASTSection =243Ctx->getMachOSection("__DWARF", "__swift_ast", MachO::S_ATTR_DEBUG,244SectionKind::getMetadata());245246DwarfAbbrevSection =247Ctx->getMachOSection("__DWARF", "__debug_abbrev", MachO::S_ATTR_DEBUG,248SectionKind::getMetadata(), "section_abbrev");249DwarfInfoSection =250Ctx->getMachOSection("__DWARF", "__debug_info", MachO::S_ATTR_DEBUG,251SectionKind::getMetadata(), "section_info");252DwarfLineSection =253Ctx->getMachOSection("__DWARF", "__debug_line", MachO::S_ATTR_DEBUG,254SectionKind::getMetadata(), "section_line");255DwarfLineStrSection =256Ctx->getMachOSection("__DWARF", "__debug_line_str", MachO::S_ATTR_DEBUG,257SectionKind::getMetadata(), "section_line_str");258DwarfFrameSection =259Ctx->getMachOSection("__DWARF", "__debug_frame", MachO::S_ATTR_DEBUG,260SectionKind::getMetadata(), "section_frame");261DwarfPubNamesSection =262Ctx->getMachOSection("__DWARF", "__debug_pubnames", MachO::S_ATTR_DEBUG,263SectionKind::getMetadata());264DwarfPubTypesSection =265Ctx->getMachOSection("__DWARF", "__debug_pubtypes", MachO::S_ATTR_DEBUG,266SectionKind::getMetadata());267DwarfGnuPubNamesSection =268Ctx->getMachOSection("__DWARF", "__debug_gnu_pubn", MachO::S_ATTR_DEBUG,269SectionKind::getMetadata());270DwarfGnuPubTypesSection =271Ctx->getMachOSection("__DWARF", "__debug_gnu_pubt", MachO::S_ATTR_DEBUG,272SectionKind::getMetadata());273DwarfStrSection =274Ctx->getMachOSection("__DWARF", "__debug_str", MachO::S_ATTR_DEBUG,275SectionKind::getMetadata(), "info_string");276DwarfStrOffSection =277Ctx->getMachOSection("__DWARF", "__debug_str_offs", MachO::S_ATTR_DEBUG,278SectionKind::getMetadata(), "section_str_off");279DwarfAddrSection =280Ctx->getMachOSection("__DWARF", "__debug_addr", MachO::S_ATTR_DEBUG,281SectionKind::getMetadata(), "section_info");282DwarfLocSection =283Ctx->getMachOSection("__DWARF", "__debug_loc", MachO::S_ATTR_DEBUG,284SectionKind::getMetadata(), "section_debug_loc");285DwarfLoclistsSection =286Ctx->getMachOSection("__DWARF", "__debug_loclists", MachO::S_ATTR_DEBUG,287SectionKind::getMetadata(), "section_debug_loc");288289DwarfARangesSection =290Ctx->getMachOSection("__DWARF", "__debug_aranges", MachO::S_ATTR_DEBUG,291SectionKind::getMetadata());292DwarfRangesSection =293Ctx->getMachOSection("__DWARF", "__debug_ranges", MachO::S_ATTR_DEBUG,294SectionKind::getMetadata(), "debug_range");295DwarfRnglistsSection =296Ctx->getMachOSection("__DWARF", "__debug_rnglists", MachO::S_ATTR_DEBUG,297SectionKind::getMetadata(), "debug_range");298DwarfMacinfoSection =299Ctx->getMachOSection("__DWARF", "__debug_macinfo", MachO::S_ATTR_DEBUG,300SectionKind::getMetadata(), "debug_macinfo");301DwarfMacroSection =302Ctx->getMachOSection("__DWARF", "__debug_macro", MachO::S_ATTR_DEBUG,303SectionKind::getMetadata(), "debug_macro");304DwarfDebugInlineSection =305Ctx->getMachOSection("__DWARF", "__debug_inlined", MachO::S_ATTR_DEBUG,306SectionKind::getMetadata());307DwarfCUIndexSection =308Ctx->getMachOSection("__DWARF", "__debug_cu_index", MachO::S_ATTR_DEBUG,309SectionKind::getMetadata());310DwarfTUIndexSection =311Ctx->getMachOSection("__DWARF", "__debug_tu_index", MachO::S_ATTR_DEBUG,312SectionKind::getMetadata());313StackMapSection = Ctx->getMachOSection("__LLVM_STACKMAPS", "__llvm_stackmaps",3140, SectionKind::getMetadata());315316FaultMapSection = Ctx->getMachOSection("__LLVM_FAULTMAPS", "__llvm_faultmaps",3170, SectionKind::getMetadata());318319RemarksSection = Ctx->getMachOSection(320"__LLVM", "__remarks", MachO::S_ATTR_DEBUG, SectionKind::getMetadata());321322// The architecture of dsymutil makes it very difficult to copy the Swift323// reflection metadata sections into the __TEXT segment, so dsymutil creates324// these sections in the __DWARF segment instead.325if (!Ctx->getSwift5ReflectionSegmentName().empty()) {326#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \327Swift5ReflectionSections \328[llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \329Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \330MACHO, 0, SectionKind::getMetadata());331#include "llvm/BinaryFormat/Swift.def"332}333334TLSExtraDataSection = TLSTLVSection;335}336337void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {338switch (T.getArch()) {339case Triple::mips:340case Triple::mipsel:341case Triple::mips64:342case Triple::mips64el:343// We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case344// since there is no R_MIPS_PC64 relocation (only a 32-bit version).345// In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't346// support pcrel|sdata8 well. Let's use sdata4 for now.347if (PositionIndependent)348FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;349else350FDECFIEncoding = Ctx->getAsmInfo()->getCodePointerSize() == 4351? dwarf::DW_EH_PE_sdata4352: dwarf::DW_EH_PE_sdata8;353break;354case Triple::ppc64:355case Triple::ppc64le:356case Triple::aarch64:357case Triple::aarch64_be:358case Triple::x86_64:359FDECFIEncoding = dwarf::DW_EH_PE_pcrel |360(Large ? dwarf::DW_EH_PE_sdata8 : dwarf::DW_EH_PE_sdata4);361break;362case Triple::bpfel:363case Triple::bpfeb:364FDECFIEncoding = dwarf::DW_EH_PE_sdata8;365break;366case Triple::hexagon:367FDECFIEncoding =368PositionIndependent ? dwarf::DW_EH_PE_pcrel : dwarf::DW_EH_PE_absptr;369break;370case Triple::xtensa:371FDECFIEncoding = dwarf::DW_EH_PE_sdata4;372break;373default:374FDECFIEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4;375break;376}377378unsigned EHSectionType = T.getArch() == Triple::x86_64379? ELF::SHT_X86_64_UNWIND380: ELF::SHT_PROGBITS;381382// Solaris requires different flags for .eh_frame to seemingly every other383// platform.384unsigned EHSectionFlags = ELF::SHF_ALLOC;385if (T.isOSSolaris() && T.getArch() != Triple::x86_64)386EHSectionFlags |= ELF::SHF_WRITE;387388// ELF389BSSSection = Ctx->getELFSection(".bss", ELF::SHT_NOBITS,390ELF::SHF_WRITE | ELF::SHF_ALLOC);391392TextSection = Ctx->getELFSection(".text", ELF::SHT_PROGBITS,393ELF::SHF_EXECINSTR | ELF::SHF_ALLOC);394395DataSection = Ctx->getELFSection(".data", ELF::SHT_PROGBITS,396ELF::SHF_WRITE | ELF::SHF_ALLOC);397398ReadOnlySection =399Ctx->getELFSection(".rodata", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);400401TLSDataSection =402Ctx->getELFSection(".tdata", ELF::SHT_PROGBITS,403ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);404405TLSBSSSection = Ctx->getELFSection(406".tbss", ELF::SHT_NOBITS, ELF::SHF_ALLOC | ELF::SHF_TLS | ELF::SHF_WRITE);407408DataRelROSection = Ctx->getELFSection(".data.rel.ro", ELF::SHT_PROGBITS,409ELF::SHF_ALLOC | ELF::SHF_WRITE);410411MergeableConst4Section =412Ctx->getELFSection(".rodata.cst4", ELF::SHT_PROGBITS,413ELF::SHF_ALLOC | ELF::SHF_MERGE, 4);414415MergeableConst8Section =416Ctx->getELFSection(".rodata.cst8", ELF::SHT_PROGBITS,417ELF::SHF_ALLOC | ELF::SHF_MERGE, 8);418419MergeableConst16Section =420Ctx->getELFSection(".rodata.cst16", ELF::SHT_PROGBITS,421ELF::SHF_ALLOC | ELF::SHF_MERGE, 16);422423MergeableConst32Section =424Ctx->getELFSection(".rodata.cst32", ELF::SHT_PROGBITS,425ELF::SHF_ALLOC | ELF::SHF_MERGE, 32);426427// Exception Handling Sections.428429// FIXME: We're emitting LSDA info into a readonly section on ELF, even though430// it contains relocatable pointers. In PIC mode, this is probably a big431// runtime hit for C++ apps. Either the contents of the LSDA need to be432// adjusted or this should be a data section.433LSDASection = Ctx->getELFSection(".gcc_except_table", ELF::SHT_PROGBITS,434ELF::SHF_ALLOC);435436COFFDebugSymbolsSection = nullptr;437COFFDebugTypesSection = nullptr;438439unsigned DebugSecType = ELF::SHT_PROGBITS;440441// MIPS .debug_* sections should have SHT_MIPS_DWARF section type442// to distinguish among sections contain DWARF and ECOFF debug formats.443// Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.444if (T.isMIPS())445DebugSecType = ELF::SHT_MIPS_DWARF;446447// Debug Info Sections.448DwarfAbbrevSection =449Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);450DwarfInfoSection = Ctx->getELFSection(".debug_info", DebugSecType, 0);451DwarfLineSection = Ctx->getELFSection(".debug_line", DebugSecType, 0);452DwarfLineStrSection =453Ctx->getELFSection(".debug_line_str", DebugSecType,454ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);455DwarfFrameSection = Ctx->getELFSection(".debug_frame", DebugSecType, 0);456DwarfPubNamesSection =457Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);458DwarfPubTypesSection =459Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);460DwarfGnuPubNamesSection =461Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);462DwarfGnuPubTypesSection =463Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);464DwarfStrSection =465Ctx->getELFSection(".debug_str", DebugSecType,466ELF::SHF_MERGE | ELF::SHF_STRINGS, 1);467DwarfLocSection = Ctx->getELFSection(".debug_loc", DebugSecType, 0);468DwarfARangesSection =469Ctx->getELFSection(".debug_aranges", DebugSecType, 0);470DwarfRangesSection =471Ctx->getELFSection(".debug_ranges", DebugSecType, 0);472DwarfMacinfoSection =473Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);474DwarfMacroSection = Ctx->getELFSection(".debug_macro", DebugSecType, 0);475476// DWARF5 Experimental Debug Info477478// Accelerator Tables479DwarfDebugNamesSection =480Ctx->getELFSection(".debug_names", ELF::SHT_PROGBITS, 0);481DwarfAccelNamesSection =482Ctx->getELFSection(".apple_names", ELF::SHT_PROGBITS, 0);483DwarfAccelObjCSection =484Ctx->getELFSection(".apple_objc", ELF::SHT_PROGBITS, 0);485DwarfAccelNamespaceSection =486Ctx->getELFSection(".apple_namespaces", ELF::SHT_PROGBITS, 0);487DwarfAccelTypesSection =488Ctx->getELFSection(".apple_types", ELF::SHT_PROGBITS, 0);489490// String Offset and Address Sections491DwarfStrOffSection =492Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);493DwarfAddrSection = Ctx->getELFSection(".debug_addr", DebugSecType, 0);494DwarfRnglistsSection = Ctx->getELFSection(".debug_rnglists", DebugSecType, 0);495DwarfLoclistsSection = Ctx->getELFSection(".debug_loclists", DebugSecType, 0);496497// Fission Sections498DwarfInfoDWOSection =499Ctx->getELFSection(".debug_info.dwo", DebugSecType, ELF::SHF_EXCLUDE);500DwarfTypesDWOSection =501Ctx->getELFSection(".debug_types.dwo", DebugSecType, ELF::SHF_EXCLUDE);502DwarfAbbrevDWOSection =503Ctx->getELFSection(".debug_abbrev.dwo", DebugSecType, ELF::SHF_EXCLUDE);504DwarfStrDWOSection = Ctx->getELFSection(505".debug_str.dwo", DebugSecType,506ELF::SHF_MERGE | ELF::SHF_STRINGS | ELF::SHF_EXCLUDE, 1);507DwarfLineDWOSection =508Ctx->getELFSection(".debug_line.dwo", DebugSecType, ELF::SHF_EXCLUDE);509DwarfLocDWOSection =510Ctx->getELFSection(".debug_loc.dwo", DebugSecType, ELF::SHF_EXCLUDE);511DwarfStrOffDWOSection = Ctx->getELFSection(".debug_str_offsets.dwo",512DebugSecType, ELF::SHF_EXCLUDE);513DwarfRnglistsDWOSection =514Ctx->getELFSection(".debug_rnglists.dwo", DebugSecType, ELF::SHF_EXCLUDE);515DwarfMacinfoDWOSection =516Ctx->getELFSection(".debug_macinfo.dwo", DebugSecType, ELF::SHF_EXCLUDE);517DwarfMacroDWOSection =518Ctx->getELFSection(".debug_macro.dwo", DebugSecType, ELF::SHF_EXCLUDE);519520DwarfLoclistsDWOSection =521Ctx->getELFSection(".debug_loclists.dwo", DebugSecType, ELF::SHF_EXCLUDE);522523// DWP Sections524DwarfCUIndexSection =525Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);526DwarfTUIndexSection =527Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);528529StackMapSection =530Ctx->getELFSection(".llvm_stackmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);531532FaultMapSection =533Ctx->getELFSection(".llvm_faultmaps", ELF::SHT_PROGBITS, ELF::SHF_ALLOC);534535EHFrameSection =536Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);537538StackSizesSection = Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, 0);539540PseudoProbeSection = Ctx->getELFSection(".pseudo_probe", DebugSecType, 0);541PseudoProbeDescSection =542Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);543544LLVMStatsSection = Ctx->getELFSection(".llvm_stats", ELF::SHT_PROGBITS, 0);545}546547void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {548TextSection = Ctx->getGOFFSection(".text", SectionKind::getText(), nullptr);549BSSSection = Ctx->getGOFFSection(".bss", SectionKind::getBSS(), nullptr);550PPA1Section = Ctx->getGOFFSection(".ppa1", SectionKind::getMetadata(),551TextSection, GOFF::SK_PPA1);552PPA2Section = Ctx->getGOFFSection(".ppa2", SectionKind::getMetadata(),553TextSection, GOFF::SK_PPA2);554555PPA2ListSection =556Ctx->getGOFFSection(".ppa2list", SectionKind::getData(), nullptr);557558ADASection = Ctx->getGOFFSection(".ada", SectionKind::getData(), nullptr);559IDRLSection = Ctx->getGOFFSection("B_IDRL", SectionKind::getData(), nullptr);560}561562void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {563EHFrameSection =564Ctx->getCOFFSection(".eh_frame", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |565COFF::IMAGE_SCN_MEM_READ);566567// Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is568// used to indicate to the linker that the text segment contains thumb instructions569// and to set the ISA selection bit for calls accordingly.570const bool IsThumb = T.getArch() == Triple::thumb;571572// COFF573BSSSection = Ctx->getCOFFSection(574".bss", COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA |575COFF::IMAGE_SCN_MEM_READ | COFF::IMAGE_SCN_MEM_WRITE);576TextSection = Ctx->getCOFFSection(577".text",578(IsThumb ? COFF::IMAGE_SCN_MEM_16BIT : (COFF::SectionCharacteristics)0) |579COFF::IMAGE_SCN_CNT_CODE | COFF::IMAGE_SCN_MEM_EXECUTE |580COFF::IMAGE_SCN_MEM_READ);581DataSection = Ctx->getCOFFSection(582".data", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |583COFF::IMAGE_SCN_MEM_WRITE);584ReadOnlySection =585Ctx->getCOFFSection(".rdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |586COFF::IMAGE_SCN_MEM_READ);587588if (T.getArch() == Triple::x86_64 || T.getArch() == Triple::aarch64 ||589T.getArch() == Triple::arm || T.getArch() == Triple::thumb) {590// On Windows with SEH, the LSDA is emitted into the .xdata section591LSDASection = nullptr;592} else {593LSDASection = Ctx->getCOFFSection(".gcc_except_table",594COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |595COFF::IMAGE_SCN_MEM_READ);596}597598// Debug info.599COFFDebugSymbolsSection =600Ctx->getCOFFSection(".debug$S", (COFF::IMAGE_SCN_MEM_DISCARDABLE |601COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |602COFF::IMAGE_SCN_MEM_READ));603COFFDebugTypesSection =604Ctx->getCOFFSection(".debug$T", (COFF::IMAGE_SCN_MEM_DISCARDABLE |605COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |606COFF::IMAGE_SCN_MEM_READ));607COFFGlobalTypeHashesSection =608Ctx->getCOFFSection(".debug$H", (COFF::IMAGE_SCN_MEM_DISCARDABLE |609COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |610COFF::IMAGE_SCN_MEM_READ));611612DwarfAbbrevSection = Ctx->getCOFFSection(613".debug_abbrev", COFF::IMAGE_SCN_MEM_DISCARDABLE |614COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |615COFF::IMAGE_SCN_MEM_READ);616DwarfInfoSection = Ctx->getCOFFSection(617".debug_info", COFF::IMAGE_SCN_MEM_DISCARDABLE |618COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |619COFF::IMAGE_SCN_MEM_READ);620DwarfLineSection = Ctx->getCOFFSection(621".debug_line", COFF::IMAGE_SCN_MEM_DISCARDABLE |622COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |623COFF::IMAGE_SCN_MEM_READ);624DwarfLineStrSection = Ctx->getCOFFSection(625".debug_line_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |626COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |627COFF::IMAGE_SCN_MEM_READ);628DwarfFrameSection = Ctx->getCOFFSection(629".debug_frame", COFF::IMAGE_SCN_MEM_DISCARDABLE |630COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |631COFF::IMAGE_SCN_MEM_READ);632DwarfPubNamesSection = Ctx->getCOFFSection(633".debug_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |634COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |635COFF::IMAGE_SCN_MEM_READ);636DwarfPubTypesSection = Ctx->getCOFFSection(637".debug_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |638COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |639COFF::IMAGE_SCN_MEM_READ);640DwarfGnuPubNamesSection = Ctx->getCOFFSection(641".debug_gnu_pubnames", COFF::IMAGE_SCN_MEM_DISCARDABLE |642COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |643COFF::IMAGE_SCN_MEM_READ);644DwarfGnuPubTypesSection = Ctx->getCOFFSection(645".debug_gnu_pubtypes", COFF::IMAGE_SCN_MEM_DISCARDABLE |646COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |647COFF::IMAGE_SCN_MEM_READ);648DwarfStrSection = Ctx->getCOFFSection(649".debug_str", COFF::IMAGE_SCN_MEM_DISCARDABLE |650COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |651COFF::IMAGE_SCN_MEM_READ);652DwarfStrOffSection = Ctx->getCOFFSection(653".debug_str_offsets", COFF::IMAGE_SCN_MEM_DISCARDABLE |654COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |655COFF::IMAGE_SCN_MEM_READ);656DwarfLocSection = Ctx->getCOFFSection(657".debug_loc", COFF::IMAGE_SCN_MEM_DISCARDABLE |658COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |659COFF::IMAGE_SCN_MEM_READ);660DwarfLoclistsSection = Ctx->getCOFFSection(661".debug_loclists", COFF::IMAGE_SCN_MEM_DISCARDABLE |662COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |663COFF::IMAGE_SCN_MEM_READ);664DwarfARangesSection = Ctx->getCOFFSection(665".debug_aranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |666COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |667COFF::IMAGE_SCN_MEM_READ);668DwarfRangesSection = Ctx->getCOFFSection(669".debug_ranges", COFF::IMAGE_SCN_MEM_DISCARDABLE |670COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |671COFF::IMAGE_SCN_MEM_READ);672DwarfRnglistsSection = Ctx->getCOFFSection(673".debug_rnglists", COFF::IMAGE_SCN_MEM_DISCARDABLE |674COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |675COFF::IMAGE_SCN_MEM_READ);676DwarfMacinfoSection = Ctx->getCOFFSection(677".debug_macinfo", COFF::IMAGE_SCN_MEM_DISCARDABLE |678COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |679COFF::IMAGE_SCN_MEM_READ);680DwarfMacroSection = Ctx->getCOFFSection(681".debug_macro", COFF::IMAGE_SCN_MEM_DISCARDABLE |682COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |683COFF::IMAGE_SCN_MEM_READ);684DwarfMacinfoDWOSection = Ctx->getCOFFSection(685".debug_macinfo.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |686COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |687COFF::IMAGE_SCN_MEM_READ);688DwarfMacroDWOSection = Ctx->getCOFFSection(689".debug_macro.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |690COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |691COFF::IMAGE_SCN_MEM_READ);692DwarfInfoDWOSection = Ctx->getCOFFSection(693".debug_info.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |694COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |695COFF::IMAGE_SCN_MEM_READ);696DwarfTypesDWOSection = Ctx->getCOFFSection(697".debug_types.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |698COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |699COFF::IMAGE_SCN_MEM_READ);700DwarfAbbrevDWOSection = Ctx->getCOFFSection(701".debug_abbrev.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |702COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |703COFF::IMAGE_SCN_MEM_READ);704DwarfStrDWOSection = Ctx->getCOFFSection(705".debug_str.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |706COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |707COFF::IMAGE_SCN_MEM_READ);708DwarfLineDWOSection = Ctx->getCOFFSection(709".debug_line.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |710COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |711COFF::IMAGE_SCN_MEM_READ);712DwarfLocDWOSection = Ctx->getCOFFSection(713".debug_loc.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |714COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |715COFF::IMAGE_SCN_MEM_READ);716DwarfStrOffDWOSection = Ctx->getCOFFSection(717".debug_str_offsets.dwo", COFF::IMAGE_SCN_MEM_DISCARDABLE |718COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |719COFF::IMAGE_SCN_MEM_READ);720DwarfAddrSection = Ctx->getCOFFSection(721".debug_addr", COFF::IMAGE_SCN_MEM_DISCARDABLE |722COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |723COFF::IMAGE_SCN_MEM_READ);724DwarfCUIndexSection = Ctx->getCOFFSection(725".debug_cu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |726COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |727COFF::IMAGE_SCN_MEM_READ);728DwarfTUIndexSection = Ctx->getCOFFSection(729".debug_tu_index", COFF::IMAGE_SCN_MEM_DISCARDABLE |730COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |731COFF::IMAGE_SCN_MEM_READ);732DwarfDebugNamesSection = Ctx->getCOFFSection(733".debug_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |734COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |735COFF::IMAGE_SCN_MEM_READ);736DwarfAccelNamesSection = Ctx->getCOFFSection(737".apple_names", COFF::IMAGE_SCN_MEM_DISCARDABLE |738COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |739COFF::IMAGE_SCN_MEM_READ);740DwarfAccelNamespaceSection = Ctx->getCOFFSection(741".apple_namespaces", COFF::IMAGE_SCN_MEM_DISCARDABLE |742COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |743COFF::IMAGE_SCN_MEM_READ);744DwarfAccelTypesSection = Ctx->getCOFFSection(745".apple_types", COFF::IMAGE_SCN_MEM_DISCARDABLE |746COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |747COFF::IMAGE_SCN_MEM_READ);748DwarfAccelObjCSection = Ctx->getCOFFSection(749".apple_objc", COFF::IMAGE_SCN_MEM_DISCARDABLE |750COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |751COFF::IMAGE_SCN_MEM_READ);752753DrectveSection = Ctx->getCOFFSection(754".drectve", COFF::IMAGE_SCN_LNK_INFO | COFF::IMAGE_SCN_LNK_REMOVE);755756PDataSection =757Ctx->getCOFFSection(".pdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |758COFF::IMAGE_SCN_MEM_READ);759760XDataSection =761Ctx->getCOFFSection(".xdata", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |762COFF::IMAGE_SCN_MEM_READ);763764SXDataSection = Ctx->getCOFFSection(".sxdata", COFF::IMAGE_SCN_LNK_INFO);765766GEHContSection =767Ctx->getCOFFSection(".gehcont$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |768COFF::IMAGE_SCN_MEM_READ);769770GFIDsSection =771Ctx->getCOFFSection(".gfids$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |772COFF::IMAGE_SCN_MEM_READ);773774GIATsSection =775Ctx->getCOFFSection(".giats$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |776COFF::IMAGE_SCN_MEM_READ);777778GLJMPSection =779Ctx->getCOFFSection(".gljmp$y", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |780COFF::IMAGE_SCN_MEM_READ);781782TLSDataSection = Ctx->getCOFFSection(783".tls$", COFF::IMAGE_SCN_CNT_INITIALIZED_DATA | COFF::IMAGE_SCN_MEM_READ |784COFF::IMAGE_SCN_MEM_WRITE);785786StackMapSection = Ctx->getCOFFSection(".llvm_stackmaps",787COFF::IMAGE_SCN_CNT_INITIALIZED_DATA |788COFF::IMAGE_SCN_MEM_READ);789}790791void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {792// Put everything in a single binary section.793TextSection = Ctx->getSPIRVSection();794}795796void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {797TextSection = Ctx->getWasmSection(".text", SectionKind::getText());798DataSection = Ctx->getWasmSection(".data", SectionKind::getData());799800DwarfLineSection =801Ctx->getWasmSection(".debug_line", SectionKind::getMetadata());802DwarfLineStrSection =803Ctx->getWasmSection(".debug_line_str", SectionKind::getMetadata(),804wasm::WASM_SEG_FLAG_STRINGS);805DwarfStrSection = Ctx->getWasmSection(806".debug_str", SectionKind::getMetadata(), wasm::WASM_SEG_FLAG_STRINGS);807DwarfLocSection =808Ctx->getWasmSection(".debug_loc", SectionKind::getMetadata());809DwarfAbbrevSection =810Ctx->getWasmSection(".debug_abbrev", SectionKind::getMetadata());811DwarfARangesSection = Ctx->getWasmSection(".debug_aranges", SectionKind::getMetadata());812DwarfRangesSection =813Ctx->getWasmSection(".debug_ranges", SectionKind::getMetadata());814DwarfMacinfoSection =815Ctx->getWasmSection(".debug_macinfo", SectionKind::getMetadata());816DwarfMacroSection =817Ctx->getWasmSection(".debug_macro", SectionKind::getMetadata());818DwarfCUIndexSection = Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());819DwarfTUIndexSection = Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());820DwarfInfoSection =821Ctx->getWasmSection(".debug_info", SectionKind::getMetadata());822DwarfFrameSection = Ctx->getWasmSection(".debug_frame", SectionKind::getMetadata());823DwarfPubNamesSection = Ctx->getWasmSection(".debug_pubnames", SectionKind::getMetadata());824DwarfPubTypesSection = Ctx->getWasmSection(".debug_pubtypes", SectionKind::getMetadata());825DwarfGnuPubNamesSection =826Ctx->getWasmSection(".debug_gnu_pubnames", SectionKind::getMetadata());827DwarfGnuPubTypesSection =828Ctx->getWasmSection(".debug_gnu_pubtypes", SectionKind::getMetadata());829830DwarfDebugNamesSection =831Ctx->getWasmSection(".debug_names", SectionKind::getMetadata());832DwarfStrOffSection =833Ctx->getWasmSection(".debug_str_offsets", SectionKind::getMetadata());834DwarfAddrSection =835Ctx->getWasmSection(".debug_addr", SectionKind::getMetadata());836DwarfRnglistsSection =837Ctx->getWasmSection(".debug_rnglists", SectionKind::getMetadata());838DwarfLoclistsSection =839Ctx->getWasmSection(".debug_loclists", SectionKind::getMetadata());840841// Fission Sections842DwarfInfoDWOSection =843Ctx->getWasmSection(".debug_info.dwo", SectionKind::getMetadata());844DwarfTypesDWOSection =845Ctx->getWasmSection(".debug_types.dwo", SectionKind::getMetadata());846DwarfAbbrevDWOSection =847Ctx->getWasmSection(".debug_abbrev.dwo", SectionKind::getMetadata());848DwarfStrDWOSection =849Ctx->getWasmSection(".debug_str.dwo", SectionKind::getMetadata(),850wasm::WASM_SEG_FLAG_STRINGS);851DwarfLineDWOSection =852Ctx->getWasmSection(".debug_line.dwo", SectionKind::getMetadata());853DwarfLocDWOSection =854Ctx->getWasmSection(".debug_loc.dwo", SectionKind::getMetadata());855DwarfStrOffDWOSection =856Ctx->getWasmSection(".debug_str_offsets.dwo", SectionKind::getMetadata());857DwarfRnglistsDWOSection =858Ctx->getWasmSection(".debug_rnglists.dwo", SectionKind::getMetadata());859DwarfMacinfoDWOSection =860Ctx->getWasmSection(".debug_macinfo.dwo", SectionKind::getMetadata());861DwarfMacroDWOSection =862Ctx->getWasmSection(".debug_macro.dwo", SectionKind::getMetadata());863864DwarfLoclistsDWOSection =865Ctx->getWasmSection(".debug_loclists.dwo", SectionKind::getMetadata());866867// DWP Sections868DwarfCUIndexSection =869Ctx->getWasmSection(".debug_cu_index", SectionKind::getMetadata());870DwarfTUIndexSection =871Ctx->getWasmSection(".debug_tu_index", SectionKind::getMetadata());872873// Wasm use data section for LSDA.874// TODO Consider putting each function's exception table in a separate875// section, as in -function-sections, to facilitate lld's --gc-section.876LSDASection = Ctx->getWasmSection(".rodata.gcc_except_table",877SectionKind::getReadOnlyWithRel());878879// TODO: Define more sections.880}881882void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {883// The default csect for program code. Functions without a specified section884// get placed into this csect. The choice of csect name is not a property of885// the ABI or object file format, but various tools rely on the section886// name being empty (considering named symbols to be "user symbol names").887TextSection = Ctx->getXCOFFSection(888"..text..", // Use a non-null name to work around an AIX assembler bug...889SectionKind::getText(),890XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_PR, XCOFF::XTY_SD),891/* MultiSymbolsAllowed*/ true);892893// ... but use a null name when generating the symbol table.894MCSectionXCOFF *TS = static_cast<MCSectionXCOFF *>(TextSection);895TS->getQualNameSymbol()->setSymbolTableName("");896TS->setSymbolTableName("");897898DataSection = Ctx->getXCOFFSection(899".data", SectionKind::getData(),900XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW, XCOFF::XTY_SD),901/* MultiSymbolsAllowed*/ true);902903ReadOnlySection = Ctx->getXCOFFSection(904".rodata", SectionKind::getReadOnly(),905XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),906/* MultiSymbolsAllowed*/ true);907ReadOnlySection->setAlignment(Align(4));908909ReadOnly8Section = Ctx->getXCOFFSection(910".rodata.8", SectionKind::getReadOnly(),911XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),912/* MultiSymbolsAllowed*/ true);913ReadOnly8Section->setAlignment(Align(8));914915ReadOnly16Section = Ctx->getXCOFFSection(916".rodata.16", SectionKind::getReadOnly(),917XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO, XCOFF::XTY_SD),918/* MultiSymbolsAllowed*/ true);919ReadOnly16Section->setAlignment(Align(16));920921TLSDataSection = Ctx->getXCOFFSection(922".tdata", SectionKind::getThreadData(),923XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TL, XCOFF::XTY_SD),924/* MultiSymbolsAllowed*/ true);925926TOCBaseSection = Ctx->getXCOFFSection(927"TOC", SectionKind::getData(),928XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_TC0,929XCOFF::XTY_SD));930931// The TOC-base always has 0 size, but 4 byte alignment.932TOCBaseSection->setAlignment(Align(4));933934LSDASection = Ctx->getXCOFFSection(935".gcc_except_table", SectionKind::getReadOnly(),936XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RO,937XCOFF::XTY_SD));938939CompactUnwindSection = Ctx->getXCOFFSection(940".eh_info_table", SectionKind::getData(),941XCOFF::CsectProperties(XCOFF::StorageMappingClass::XMC_RW,942XCOFF::XTY_SD));943944// DWARF sections for XCOFF are not csects. They are special STYP_DWARF945// sections, and the individual DWARF sections are distinguished by their946// section subtype.947DwarfAbbrevSection = Ctx->getXCOFFSection(948".dwabrev", SectionKind::getMetadata(),949/* CsectProperties */ std::nullopt,950/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWABREV);951952DwarfInfoSection = Ctx->getXCOFFSection(953".dwinfo", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,954/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWINFO);955956DwarfLineSection = Ctx->getXCOFFSection(957".dwline", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,958/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLINE);959960DwarfFrameSection = Ctx->getXCOFFSection(961".dwframe", SectionKind::getMetadata(),962/* CsectProperties */ std::nullopt,963/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWFRAME);964965DwarfPubNamesSection = Ctx->getXCOFFSection(966".dwpbnms", SectionKind::getMetadata(),967/* CsectProperties */ std::nullopt,968/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBNMS);969970DwarfPubTypesSection = Ctx->getXCOFFSection(971".dwpbtyp", SectionKind::getMetadata(),972/* CsectProperties */ std::nullopt,973/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWPBTYP);974975DwarfStrSection = Ctx->getXCOFFSection(976".dwstr", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,977/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWSTR);978979DwarfLocSection = Ctx->getXCOFFSection(980".dwloc", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,981/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWLOC);982983DwarfARangesSection = Ctx->getXCOFFSection(984".dwarnge", SectionKind::getMetadata(),985/* CsectProperties */ std::nullopt,986/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWARNGE);987988DwarfRangesSection = Ctx->getXCOFFSection(989".dwrnges", SectionKind::getMetadata(),990/* CsectProperties */ std::nullopt,991/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWRNGES);992993DwarfMacinfoSection = Ctx->getXCOFFSection(994".dwmac", SectionKind::getMetadata(), /* CsectProperties */ std::nullopt,995/* MultiSymbolsAllowed */ true, XCOFF::SSUBTYP_DWMAC);996}997998void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {999// At the moment the DXBC section should end up empty.1000TextSection = Ctx->getDXContainerSection("DXBC", SectionKind::getText());1001}10021003MCObjectFileInfo::~MCObjectFileInfo() = default;10041005void MCObjectFileInfo::initMCObjectFileInfo(MCContext &MCCtx, bool PIC,1006bool LargeCodeModel) {1007PositionIndependent = PIC;1008Ctx = &MCCtx;10091010// Common.1011SupportsWeakOmittedEHFrame = true;1012SupportsCompactUnwindWithoutEHFrame = false;1013OmitDwarfIfHaveCompactUnwind = false;10141015FDECFIEncoding = dwarf::DW_EH_PE_absptr;10161017CompactUnwindDwarfEHFrameOnly = 0;10181019EHFrameSection = nullptr; // Created on demand.1020CompactUnwindSection = nullptr; // Used only by selected targets.1021DwarfAccelNamesSection = nullptr; // Used only by selected targets.1022DwarfAccelObjCSection = nullptr; // Used only by selected targets.1023DwarfAccelNamespaceSection = nullptr; // Used only by selected targets.1024DwarfAccelTypesSection = nullptr; // Used only by selected targets.10251026Triple TheTriple = Ctx->getTargetTriple();1027switch (Ctx->getObjectFileType()) {1028case MCContext::IsMachO:1029initMachOMCObjectFileInfo(TheTriple);1030break;1031case MCContext::IsCOFF:1032initCOFFMCObjectFileInfo(TheTriple);1033break;1034case MCContext::IsELF:1035initELFMCObjectFileInfo(TheTriple, LargeCodeModel);1036break;1037case MCContext::IsGOFF:1038initGOFFMCObjectFileInfo(TheTriple);1039break;1040case MCContext::IsSPIRV:1041initSPIRVMCObjectFileInfo(TheTriple);1042break;1043case MCContext::IsWasm:1044initWasmMCObjectFileInfo(TheTriple);1045break;1046case MCContext::IsXCOFF:1047initXCOFFMCObjectFileInfo(TheTriple);1048break;1049case MCContext::IsDXContainer:1050initDXContainerObjectFileInfo(TheTriple);1051break;1052}1053}10541055MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,1056uint64_t Hash) const {1057switch (Ctx->getTargetTriple().getObjectFormat()) {1058case Triple::ELF:1059return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, ELF::SHF_GROUP, 0,1060utostr(Hash), /*IsComdat=*/true);1061case Triple::Wasm:1062return Ctx->getWasmSection(Name, SectionKind::getMetadata(), 0,1063utostr(Hash), MCContext::GenericSectionID);1064case Triple::MachO:1065case Triple::COFF:1066case Triple::GOFF:1067case Triple::SPIRV:1068case Triple::XCOFF:1069case Triple::DXContainer:1070case Triple::UnknownObjectFormat:1071report_fatal_error("Cannot get DWARF comdat section for this object file "1072"format: not implemented.");1073break;1074}1075llvm_unreachable("Unknown ObjectFormatType");1076}10771078MCSection *1079MCObjectFileInfo::getStackSizesSection(const MCSection &TextSec) const {1080if ((Ctx->getObjectFileType() != MCContext::IsELF) ||1081Ctx->getTargetTriple().isPS4())1082return StackSizesSection;10831084const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);1085unsigned Flags = ELF::SHF_LINK_ORDER;1086StringRef GroupName;1087if (const MCSymbol *Group = ElfSec.getGroup()) {1088GroupName = Group->getName();1089Flags |= ELF::SHF_GROUP;1090}10911092return Ctx->getELFSection(".stack_sizes", ELF::SHT_PROGBITS, Flags, 0,1093GroupName, true, ElfSec.getUniqueID(),1094cast<MCSymbolELF>(TextSec.getBeginSymbol()));1095}10961097MCSection *1098MCObjectFileInfo::getBBAddrMapSection(const MCSection &TextSec) const {1099if (Ctx->getObjectFileType() != MCContext::IsELF)1100return nullptr;11011102const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);1103unsigned Flags = ELF::SHF_LINK_ORDER;1104StringRef GroupName;1105if (const MCSymbol *Group = ElfSec.getGroup()) {1106GroupName = Group->getName();1107Flags |= ELF::SHF_GROUP;1108}11091110// Use the text section's begin symbol and unique ID to create a separate1111// .llvm_bb_addr_map section associated with every unique text section.1112return Ctx->getELFSection(".llvm_bb_addr_map", ELF::SHT_LLVM_BB_ADDR_MAP,1113Flags, 0, GroupName, true, ElfSec.getUniqueID(),1114cast<MCSymbolELF>(TextSec.getBeginSymbol()));1115}11161117MCSection *1118MCObjectFileInfo::getKCFITrapSection(const MCSection &TextSec) const {1119if (Ctx->getObjectFileType() != MCContext::IsELF)1120return nullptr;11211122const MCSectionELF &ElfSec = static_cast<const MCSectionELF &>(TextSec);1123unsigned Flags = ELF::SHF_LINK_ORDER | ELF::SHF_ALLOC;1124StringRef GroupName;1125if (const MCSymbol *Group = ElfSec.getGroup()) {1126GroupName = Group->getName();1127Flags |= ELF::SHF_GROUP;1128}11291130return Ctx->getELFSection(".kcfi_traps", ELF::SHT_PROGBITS, Flags, 0,1131GroupName,1132/*IsComdat=*/true, ElfSec.getUniqueID(),1133cast<MCSymbolELF>(TextSec.getBeginSymbol()));1134}11351136MCSection *1137MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {1138if (Ctx->getObjectFileType() != MCContext::IsELF)1139return PseudoProbeSection;11401141const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);1142unsigned Flags = ELF::SHF_LINK_ORDER;1143StringRef GroupName;1144if (const MCSymbol *Group = ElfSec.getGroup()) {1145GroupName = Group->getName();1146Flags |= ELF::SHF_GROUP;1147}11481149return Ctx->getELFSection(PseudoProbeSection->getName(), ELF::SHT_PROGBITS,1150Flags, 0, GroupName, true, ElfSec.getUniqueID(),1151cast<MCSymbolELF>(TextSec.getBeginSymbol()));1152}11531154MCSection *1155MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {1156if (Ctx->getObjectFileType() == MCContext::IsELF) {1157// Create a separate comdat group for each function's descriptor in order1158// for the linker to deduplicate. The duplication, must be from different1159// tranlation unit, can come from:1160// 1. Inline functions defined in header files;1161// 2. ThinLTO imported funcions;1162// 3. Weak-linkage definitions.1163// Use a concatenation of the section name and the function name as the1164// group name so that descriptor-only groups won't be folded with groups of1165// code.1166if (Ctx->getTargetTriple().supportsCOMDAT() && !FuncName.empty()) {1167auto *S = static_cast<MCSectionELF *>(PseudoProbeDescSection);1168auto Flags = S->getFlags() | ELF::SHF_GROUP;1169return Ctx->getELFSection(S->getName(), S->getType(), Flags,1170S->getEntrySize(),1171S->getName() + "_" + FuncName,1172/*IsComdat=*/true);1173}1174}1175return PseudoProbeDescSection;1176}11771178MCSection *MCObjectFileInfo::getLLVMStatsSection() const {1179return LLVMStatsSection;1180}11811182MCSection *MCObjectFileInfo::getPCSection(StringRef Name,1183const MCSection *TextSec) const {1184if (Ctx->getObjectFileType() != MCContext::IsELF)1185return nullptr;11861187// SHF_WRITE for relocations, and let user post-process data in-place.1188unsigned Flags = ELF::SHF_WRITE | ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER;11891190if (!TextSec)1191TextSec = getTextSection();11921193StringRef GroupName;1194const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);1195if (const MCSymbol *Group = ElfSec.getGroup()) {1196GroupName = Group->getName();1197Flags |= ELF::SHF_GROUP;1198}1199return Ctx->getELFSection(Name, ELF::SHT_PROGBITS, Flags, 0, GroupName, true,1200ElfSec.getUniqueID(),1201cast<MCSymbolELF>(TextSec->getBeginSymbol()));1202}120312041205