1//===-- MCObjectFileInfo.cpp - Object File Information --------------------===//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//===----------------------------------------------------------------------===//
36 // aarch64 always has it.
40 // armv7k always has it.
44 // Use it on newer version of OS X.
45 if (
T.isMacOSX() && !
T.isMacOSXVersionLT(10, 6))
48 // And the iOS simulator.
49 if (
T.isiOS() &&
T.isX86())
52 // The rest of the simulators always have it.
53 if (
T.isSimulatorEnvironment())
56 // XROS always has it.
63void MCObjectFileInfo::initMachOMCObjectFileInfo(
const Triple &
T) {
68 "__TEXT",
"__eh_frame",
75 T.isSimulatorEnvironment()))
78 switch (Ctx->emitDwarfUnwindInfo()) {
94 = Ctx->getMachOSection(
"__TEXT",
"__text",
100 // BSSSection might not be expected initialized on msvc.
104 = Ctx->getMachOSection(
"__DATA",
"__thread_data",
108 = Ctx->getMachOSection(
"__DATA",
"__thread_bss",
112 // TODO: Verify datarel below.
114 = Ctx->getMachOSection(
"__DATA",
"__thread_vars",
123 = Ctx->getMachOSection(
"__TEXT",
"__cstring",
127 = Ctx->getMachOSection(
"__TEXT",
"__ustring", 0,
130 = Ctx->getMachOSection(
"__TEXT",
"__literal4",
134 = Ctx->getMachOSection(
"__TEXT",
"__literal8",
139 = Ctx->getMachOSection(
"__TEXT",
"__literal16",
144 = Ctx->getMachOSection(
"__TEXT",
"__const", 0,
147 // If the target is not powerpc, map the coal sections to the non-coal
150 // "__TEXT/__textcoal_nt" => section "__TEXT/__text"
151 // "__TEXT/__const_coal" => section "__TEXT/__const"
152 // "__DATA/__datacoal_nt" => section "__DATA/__data"
156 = Ctx->getMachOSection(
"__DATA",
"__const", 0,
161 = Ctx->getMachOSection(
"__TEXT",
"__textcoal_nt",
166 = Ctx->getMachOSection(
"__TEXT",
"__const_coal",
180 = Ctx->getMachOSection(
"__DATA",
"__common",
189 = Ctx->getMachOSection(
"__DATA",
"__la_symbol_ptr",
193 = Ctx->getMachOSection(
"__DATA",
"__nl_symbol_ptr",
198 = Ctx->getMachOSection(
"__DATA",
"__thread_ptr",
202 AddrSigSection = Ctx->getMachOSection(
"__DATA",
"__llvm_addrsig", 0,
205 // Exception Handling.
206 LSDASection = Ctx->getMachOSection(
"__TEXT",
"__gcc_except_tab", 0,
226 // Debug Information.
236 // 16 character section limit...
315 StackMapSection = Ctx->getMachOSection(
"__LLVM_STACKMAPS",
"__llvm_stackmaps",
318 FaultMapSection = Ctx->getMachOSection(
"__LLVM_FAULTMAPS",
"__llvm_faultmaps",
324 // The architecture of dsymutil makes it very difficult to copy the Swift
325 // reflection metadata sections into the __TEXT segment, so dsymutil creates
326 // these sections in the __DWARF segment instead.
327 if (!Ctx->getSwift5ReflectionSegmentName().empty()) {
328#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \
329 Swift5ReflectionSections \
330 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \
331 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \
332 MACHO, 0, SectionKind::getMetadata());
333#include "llvm/BinaryFormat/Swift.def"
339void MCObjectFileInfo::initELFMCObjectFileInfo(
const Triple &
T,
bool Large) {
340 switch (
T.getArch()) {
345 // We cannot use DW_EH_PE_sdata8 for the large PositionIndependent case
346 // since there is no R_MIPS_PC64 relocation (only a 32-bit version).
347 // In fact DW_EH_PE_sdata4 is enough for us now, and GNU ld doesn't
348 // support pcrel|sdata8 well. Let's use sdata4 for now.
349 if (PositionIndependent)
383 switch (
T.getArch()) {
397 // Solaris requires different flags for .eh_frame to seemingly every other
442 // Exception Handling Sections.
444 // FIXME: We're emitting LSDA info into a readonly section on ELF, even though
445 // it contains relocatable pointers. In PIC mode, this is probably a big
446 // runtime hit for C++ apps. Either the contents of the LSDA need to be
447 // adjusted or this should be a data section.
456 // MIPS .debug_* sections should have SHT_MIPS_DWARF section type
457 // to distinguish among sections contain DWARF and ECOFF debug formats.
458 // Sections with ECOFF debug format are obsoleted and marked by SHT_PROGBITS.
462 // Debug Info Sections.
464 Ctx->getELFSection(
".debug_abbrev", DebugSecType, 0);
468 Ctx->getELFSection(
".debug_line_str", DebugSecType,
472 Ctx->getELFSection(
".debug_pubnames", DebugSecType, 0);
474 Ctx->getELFSection(
".debug_pubtypes", DebugSecType, 0);
476 Ctx->getELFSection(
".debug_gnu_pubnames", DebugSecType, 0);
478 Ctx->getELFSection(
".debug_gnu_pubtypes", DebugSecType, 0);
480 Ctx->getELFSection(
".debug_str", DebugSecType,
484 Ctx->getELFSection(
".debug_aranges", DebugSecType, 0);
486 Ctx->getELFSection(
".debug_ranges", DebugSecType, 0);
488 Ctx->getELFSection(
".debug_macinfo", DebugSecType, 0);
491 // DWARF5 Experimental Debug Info
493 // Accelerator Tables
505 // String Offset and Address Sections
507 Ctx->getELFSection(
".debug_str_offsets", DebugSecType, 0);
520 ".debug_str.dwo", DebugSecType,
540 Ctx->getELFSection(
".debug_cu_index", DebugSecType, 0);
542 Ctx->getELFSection(
".debug_tu_index", DebugSecType, 0);
551 Ctx->getELFSection(
".eh_frame", EHSectionType, EHSectionFlags);
563 Ctx->getELFSection(
".pseudo_probe_desc", DebugSecType, 0);
568void MCObjectFileInfo::initGOFFMCObjectFileInfo(
const Triple &
T) {
569 MCSectionGOFF *RootSDSection = Ctx->getGOFFSection(
573 MCSectionGOFF *ADAEDSection = Ctx->getGOFFSection(
594 MCSectionGOFF *PPA2ListEDSection = Ctx->getGOFFSection(
616void MCObjectFileInfo::initCOFFMCObjectFileInfo(
const Triple &
T) {
621 // Set the `IMAGE_SCN_MEM_16BIT` flag when compiling for thumb mode. This is
622 // used to indicate to the linker that the text segment contains thumb instructions
623 // and to set the ISA selection bit for calls accordingly.
644 // On Windows with SEH, the LSDA is emitted into the .xdata section
647 LSDASection = Ctx->getCOFFSection(
".gcc_except_table",
656 // Import Call Optimization on x64 leverages the same metadata as the
657 // retpoline mitigation, hence the unusual section name.
862 // Set IMAGE_SCN_MEM_DISCARDABLE so that lld will not truncate section name.
873void MCObjectFileInfo::initSPIRVMCObjectFileInfo(
const Triple &
T) {
874 // Put everything in a single binary section.
878void MCObjectFileInfo::initWasmMCObjectFileInfo(
const Triple &
T) {
955 // Wasm use data section for LSDA.
956 // TODO Consider putting each function's exception table in a separate
957 // section, as in -function-sections, to facilitate lld's --gc-section.
958 LSDASection = Ctx->getWasmSection(
".rodata.gcc_except_table",
961 // TODO: Define more sections.
964void MCObjectFileInfo::initXCOFFMCObjectFileInfo(
const Triple &
T) {
965 // The default csect for program code. Functions without a specified section
966 // get placed into this csect. The choice of csect name is not a property of
967 // the ABI or object file format, but various tools rely on the section
968 // name being empty (considering named symbols to be "user symbol names").
970 "..text..",
// Use a non-null name to work around an AIX assembler bug...
973 /* MultiSymbolsAllowed*/ true);
975 // ... but use a null name when generating the symbol table.
976 MCSectionXCOFF *TS =
static_cast<MCSectionXCOFF *
>(
TextSection);
983 /* MultiSymbolsAllowed*/ true);
988 /* MultiSymbolsAllowed*/ true);
994 /* MultiSymbolsAllowed*/ true);
1000 /* MultiSymbolsAllowed*/ true);
1006 /* MultiSymbolsAllowed*/ true);
1013 // The TOC-base always has 0 size, but 4 byte alignment.
1026 // DWARF sections for XCOFF are not csects. They are special STYP_DWARF
1027 // sections, and the individual DWARF sections are distinguished by their
1031 /* CsectProperties */ std::nullopt,
1044 /* CsectProperties */ std::nullopt,
1049 /* CsectProperties */ std::nullopt,
1054 /* CsectProperties */ std::nullopt,
1067 /* CsectProperties */ std::nullopt,
1072 /* CsectProperties */ std::nullopt,
1080void MCObjectFileInfo::initDXContainerObjectFileInfo(
const Triple &
T) {
1081 // At the moment the DXBC section should end up empty.
1088 bool LargeCodeModel) {
1089 PositionIndependent =
PIC;
1109 const Triple &TheTriple = Ctx->getTargetTriple();
1110 switch (Ctx->getObjectFileType()) {
1112 initMachOMCObjectFileInfo(TheTriple);
1115 initCOFFMCObjectFileInfo(TheTriple);
1118 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);
1121 initGOFFMCObjectFileInfo(TheTriple);
1124 initSPIRVMCObjectFileInfo(TheTriple);
1127 initWasmMCObjectFileInfo(TheTriple);
1130 initXCOFFMCObjectFileInfo(TheTriple);
1133 initDXContainerObjectFileInfo(TheTriple);
1138MCSection *MCObjectFileInfo::getDwarfComdatSection(
const char *Name,
1140 switch (Ctx->getTargetTriple().getObjectFormat()) {
1143 utostr(Hash),
/*IsComdat=*/true);
1155 "format: not implemented.");
1170 GroupName = Group->getName();
1174 return Ctx->getELFSection(
1183 Ctx->getTargetTriple().isPS4())
1190 GroupName = Group->getName();
1194 return Ctx->getELFSection(
1209 GroupName = Group->getName();
1213 // Use the text section's begin symbol and unique ID to create a separate
1214 // .llvm_bb_addr_map section associated with every unique text section.
1215 return Ctx->getELFSection(
1230 GroupName = Group->getName();
1234 return Ctx->getELFSection(
1242 auto ObjFileType = Ctx->getObjectFileType();
1244 const auto &ElfSec =
static_cast<const MCSectionELF &
>(TextSec);
1247 if (
const MCSymbol *Group = ElfSec.getGroup()) {
1248 GroupName = Group->getName();
1251 return Ctx->getELFSection(
1253 true, ElfSec.getUniqueID(),
1258 unsigned Characteristics =
1260 const auto &COFFSec =
static_cast<const MCSectionCOFF &
>(TextSec);
1261 if (
const MCSymbol *COMDATSym = COFFSec.getCOMDATSymbol()) {
1262 // Associate .pseudo_probe to its function section.
1263 COMDATSymName = COMDATSym->getName();
1268 COMDATSymName,
Selection, COFFSec.getUniqueID());
1276 if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.
empty())
1279 // Create a separate comdat group for each function's descriptor in order
1280 // for the linker to deduplicate. The duplication, must be from different
1281 // tranlation unit, can come from:
1282 // 1. Inline functions defined in header files;
1283 // 2. ThinLTO imported funcions;
1284 // 3. Weak-linkage definitions.
1285 // Use a concatenation of the section name and the function name as the
1286 // group name so that descriptor-only groups won't be folded with groups of
1288 auto ObjFileType = Ctx->getObjectFileType();
1292 return Ctx->getELFSection(S->getName(), S->getType(), Flags,
1293 S->getEntrySize(), S->getName() +
"_" + FuncName,
1297 unsigned Characteristics =
1299 std::string COMDATSymName = (S->getName() +
"_" + FuncName).str();
1300 return Ctx->getCOFFSection(S->getName(), Characteristics, COMDATSymName,
1316 // SHF_WRITE for relocations, and let user post-process data in-place.
1323 const auto &ElfSec =
static_cast<const MCSectionELF &
>(*TextSec);
1324 if (
const MCSymbol *Group = ElfSec.getGroup()) {
1325 GroupName = Group->getName();
1328 return Ctx->getELFSection(
amdgpu AMDGPU DAG DAG Pattern Instruction Selection
static bool useCompactUnwind(const Triple &T)
This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...
PassInstrumentationCallbacks PIC
This file contains data-structure definitions and constants to support unwinding based on ....
Context object for machine code objects.
MCSection * NonLazySymbolPointerSection
MCSection * TLSBSSSection
Section directive for Thread Local uninitialized data.
MCSection * CallGraphSection
Section containing call graph metadata.
MCSection * DwarfDebugNamesSection
Accelerator table sections.
MCSection * DwarfAddrSection
const MCSection * TLSThreadInitSection
Section for thread local data initialization functions.
MCSection * GEHContSection
MCSection * DwarfStrOffSection
The DWARF v5 string offset and address table sections.
MCSection * DwarfARangesSection
MCSection * DwarfStrSection
MCSection * MergeableConst16Section
MCSection * COFFGlobalTypeHashesSection
MCSection * SFrameSection
SFrame section.
MCSection * DwarfLocDWOSection
MCSection * MergeableConst4Section
MCSection * DwarfMacinfoSection
MCSection * DwarfPubNamesSection
MCSection * DwarfGnuPubTypesSection
Section for newer gnu pubtypes.
MCSection * getLLVMStatsSection() const
MCSection * DwarfCUIndexSection
MCSection * TextSection
Section directive for standard text.
MCSection * ConstDataCoalSection
MCSection * LLVMStatsSection
MCSection * ConstTextCoalSection
MCSection * TLSDataSection
Section directive for Thread Local data. ELF, MachO, COFF, and Wasm.
MCSection * MergeableConst8Section
MCSection * AddrSigSection
MCSection * DwarfInfoSection
MCSection * ThreadLocalPointerSection
MCSection * LSDASection
If exception handling is supported by the target, this is the section the Language Specific Data Area...
MCSection * CompactUnwindSection
If exception handling is supported by the target and the target can support a compact representation ...
MCSection * COFFDebugSymbolsSection
MCSection * DwarfStrDWOSection
MCSection * getPseudoProbeDescSection(StringRef FuncName) const
MCSection * DwarfLoclistsSection
The DWARF v5 locations list section.
MCSection * ReadOnly16Section
MCSection * DwarfLocSection
MCSection * PseudoProbeSection
Section for pseudo probe information used by AutoFDO.
MCSection * FourByteConstantSection
MCSection * DwarfAccelNamesSection
MCSection * ReadOnly8Section
MCSection * getStackSizesSection(const MCSection &TextSec) const
MCSection * DwarfRnglistsSection
The DWARF v5 range list section.
const MCSection * DwarfDebugInlineSection
MCSection * DataBSSSection
MCSection * DwarfAbbrevDWOSection
MCSection * getBBAddrMapSection(const MCSection &TextSec) const
MCSection * COFFDebugTypesSection
MCSection * LazySymbolPointerSection
MCSection * RemarksSection
Remarks section.
MCSection * getPseudoProbeSection(const MCSection &TextSec) const
MCSection * TextCoalSection
MCSection * PseudoProbeDescSection
MCSection * DwarfPubTypesSection
MCSection * DwarfRangesSection
MCSection * DwarfStrOffDWOSection
MCSection * TLSExtraDataSection
Extra TLS Variable Data section.
MCSection * DataRelROSection
MCSection * EHFrameSection
EH frame section.
bool OmitDwarfIfHaveCompactUnwind
OmitDwarfIfHaveCompactUnwind - True if the target object file supports having some functions with com...
MCSection * CStringSection
MCSection * DrectveSection
COFF specific sections.
MCSection * FaultMapSection
FaultMap section.
MCSection * getKCFITrapSection(const MCSection &TextSec) const
MCSection * DwarfAccelObjCSection
MCSection * TLSTLVSection
Section for thread local structure information.
MCSection * DwarfSwiftASTSection
MCSection * DwarfMacroSection
void initMCObjectFileInfo(MCContext &MCCtx, bool PIC, bool LargeCodeModel=false)
MCSection * DataCoalSection
MCSection * DwarfFrameSection
MCSection * SXDataSection
MCSection * UStringSection
MCSection * DwarfRnglistsDWOSection
The DWARF v5 range and location list sections for fission.
MCSection * ImportCallSection
If import call optimization is supported by the target, this is the section to emit import call data ...
MCSection * MergeableConst32Section
MCSection * SixteenByteConstantSection
virtual ~MCObjectFileInfo()
MCSection * DataCommonSection
MCSection * getPCSection(StringRef Name, const MCSection *TextSec) const
std::optional< sframe::ABI > SFrameABIArch
SFrame ABI architecture byte.
MCSection * DwarfLineStrSection
bool SupportsCompactUnwindWithoutEHFrame
True if the target object file supports emitting a compact unwind section without an associated EH fr...
MCSection * ReadOnlySection
Section that is readonly and can contain arbitrary initialized data.
MCSection * DwarfLineDWOSection
MCSection * DwarfAbbrevSection
MCSection * DwarfLineSection
MCSection * TOCBaseSection
unsigned FDECFIEncoding
FDE CFI encoding.
MCSection * DwarfTUIndexSection
bool SupportsWeakOmittedEHFrame
True if target object file supports a weak_definition of constant 0 for an omitted EH frame.
MCSection * DwarfLoclistsDWOSection
MCSection * getCallGraphSection(const MCSection &TextSec) const
MCSection * DwarfInfoDWOSection
MCSection * BSSSection
Section that is default initialized to zero.
MCSection * PPA2ListSection
MCSection * EightByteConstantSection
MCSection * StackSizesSection
Section containing metadata on function stack sizes.
unsigned CompactUnwindDwarfEHFrameOnly
Compact unwind encoding indicating that we should emit only an EH frame.
MCSection * getTextSection() const
MCSection * DwarfTypesDWOSection
MCSection * DwarfGnuPubNamesSection
Section for newer gnu pubnames.
MCSection * ConstDataSection
MCSection * StackMapSection
StackMap section.
MCSection * DwarfMacroDWOSection
MCSection * DwarfMacinfoDWOSection
MCSection * DwarfAccelNamespaceSection
MCSection * DwarfAccelTypesSection
MCSection * DataSection
Section directive for standard data.
This represents a section on Windows.
This represents a section on linux, lots of unix variants and some bare metal systems.
unsigned getFlags() const
unsigned getUniqueID() const
const MCSymbolELF * getGroup() const
void setSymbolTableName(StringRef STN)
MCSymbolXCOFF * getQualNameSymbol() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
static constexpr unsigned NonUniqueID
MCSymbol * getBeginSymbol()
void setSymbolTableName(StringRef STN)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
static SectionKind getThreadData()
static SectionKind getMetadata()
static SectionKind getMergeable2ByteCString()
static SectionKind getMergeableConst4()
static SectionKind getText()
static SectionKind getReadOnlyWithRel()
static SectionKind getData()
static SectionKind getMergeableConst8()
static SectionKind getBSS()
static SectionKind getThreadBSS()
static SectionKind getMergeableConst16()
static SectionKind getMergeable1ByteCString()
static SectionKind getReadOnly()
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
Triple - Helper class for working with autoconf configuration names.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ IMAGE_SCN_CNT_UNINITIALIZED_DATA
@ IMAGE_SCN_MEM_DISCARDABLE
@ IMAGE_SCN_CNT_INITIALIZED_DATA
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
@ IMAGE_COMDAT_SELECT_EXACT_MATCH
constexpr StringLiteral CLASS_WSA
constexpr StringLiteral CLASS_PPA2
constexpr StringLiteral CLASS_CODE
@ S_THREAD_LOCAL_VARIABLE_POINTERS
S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.
@ S_16BYTE_LITERALS
S_16BYTE_LITERALS - Section with only 16 byte literals.
@ S_THREAD_LOCAL_INIT_FUNCTION_POINTERS
S_THREAD_LOCAL_INIT_FUNCTION_POINTERS - Section with thread local variable initialization pointers to...
@ S_COALESCED
S_COALESCED - Section contains symbols that are to be coalesced.
@ S_THREAD_LOCAL_ZEROFILL
S_THREAD_LOCAL_ZEROFILL - Thread local zerofill section.
@ S_LAZY_SYMBOL_POINTERS
S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.
@ S_CSTRING_LITERALS
S_CSTRING_LITERALS - Section with literal C strings.
@ S_THREAD_LOCAL_REGULAR
S_THREAD_LOCAL_REGULAR - Thread local data section.
@ S_ZEROFILL
S_ZEROFILL - Zero fill on demand section.
@ S_NON_LAZY_SYMBOL_POINTERS
S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.
@ S_4BYTE_LITERALS
S_4BYTE_LITERALS - Section with 4 byte literals.
@ S_8BYTE_LITERALS
S_8BYTE_LITERALS - Section with 8 byte literals.
@ S_THREAD_LOCAL_VARIABLES
S_THREAD_LOCAL_VARIABLES - Section with thread local variable structure data.
@ S_ATTR_DEBUG
S_ATTR_DEBUG - A debug section.
@ S_ATTR_NO_TOC
S_ATTR_NO_TOC - Section contains coalesced symbols that are not to be in a ranlib table of contents.
@ S_ATTR_LIVE_SUPPORT
S_ATTR_LIVE_SUPPORT - Blocks are live if they reference live blocks.
@ S_ATTR_PURE_INSTRUCTIONS
S_ATTR_PURE_INSTRUCTIONS - Section contains only true machine instructions.
@ S_ATTR_STRIP_STATIC_SYMS
S_ATTR_STRIP_STATIC_SYMS - Ok to strip static symbols in this section in files with the MY_DYLDLINK f...
@ SSUBTYP_DWARNGE
DWARF aranges section.
@ SSUBTYP_DWFRAME
DWARF frame section.
@ SSUBTYP_DWABREV
DWARF abbrev section.
@ SSUBTYP_DWINFO
DWARF info section.
@ SSUBTYP_DWRNGES
DWARF ranges section.
@ SSUBTYP_DWLOC
DWARF loc section.
@ SSUBTYP_DWMAC
DWARF macinfo section.
@ SSUBTYP_DWPBNMS
DWARF pubnames section.
@ SSUBTYP_DWPBTYP
DWARF pubtypes section.
@ SSUBTYP_DWLINE
DWARF line section.
@ SSUBTYP_DWSTR
DWARF str section.
@ XMC_TC0
TOC Anchor for TOC Addressability.
@ XMC_TL
Initialized thread-local variable.
@ XMC_RO
Read Only Constant.
@ XTY_SD
Csect definition for initialized storage.
This is an optimization pass for GlobalISel generic memory operations.
std::string utostr(uint64_t X, bool isNeg=false)
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)