LLVM: lib/MC/MCObjectFileInfo.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

27

28using namespace llvm;

29

31

32 if (T.isOSDarwin())

33 return false;

34

35

37 return true;

38

39

40 if (T.isWatchABI())

41 return true;

42

43

44 if (T.isMacOSX() && T.isMacOSXVersionLT(10, 6))

45 return true;

46

47

48 if (T.isiOS() && T.isX86())

49 return true;

50

51

52 if (T.isSimulatorEnvironment())

53 return true;

54

55

56 if (T.isXROS())

57 return true;

58

59 return false;

60}

61

62void MCObjectFileInfo::initMachOMCObjectFileInfo(const Triple &T) {

63

65

67 "__TEXT", "__eh_frame",

71

72 if (T.isOSDarwin() &&

74 T.isSimulatorEnvironment()))

76

80 break;

83 break;

87 break;

88 }

89

91

98

99

101

110

111

116

120

136

141

145

146

147

148

149

150

151

153

157

171 } else {

176 }

177

185

186

195

200

203

204

207

211

216

217 if (T.isX86())

223 }

224

225

235

242

246

289

316

319

322

323

324

325

327#define HANDLE_SWIFT_SECTION(KIND, MACHO, ELF, COFF) \

328 Swift5ReflectionSections \

329 [llvm::binaryformat::Swift5ReflectionSectionKind::KIND] = \

330 Ctx->getMachOSection(Ctx->getSwift5ReflectionSegmentName().data(), \

331 MACHO, 0, SectionKind::getMetadata());

332#include "llvm/BinaryFormat/Swift.def"

333 }

334

336}

337

338void MCObjectFileInfo::initELFMCObjectFileInfo(const Triple &T, bool Large) {

339 switch (T.getArch()) {

344

345

346

347

348 if (PositionIndependent)

350 else

354 break;

362 break;

366 break;

370 break;

373 break;

374 default:

376 break;

377 }

378

382

383

384

388

389

392

395

398

401

405

408

411

415

419

423

427

428

429

430

431

432

433

436

439

441

442

443

444

445 if (T.isMIPS())

447

448

450 Ctx->getELFSection(".debug_abbrev", DebugSecType, 0);

454 Ctx->getELFSection(".debug_line_str", DebugSecType,

458 Ctx->getELFSection(".debug_pubnames", DebugSecType, 0);

460 Ctx->getELFSection(".debug_pubtypes", DebugSecType, 0);

462 Ctx->getELFSection(".debug_gnu_pubnames", DebugSecType, 0);

464 Ctx->getELFSection(".debug_gnu_pubtypes", DebugSecType, 0);

470 Ctx->getELFSection(".debug_aranges", DebugSecType, 0);

472 Ctx->getELFSection(".debug_ranges", DebugSecType, 0);

474 Ctx->getELFSection(".debug_macinfo", DebugSecType, 0);

476

477

478

479

490

491

493 Ctx->getELFSection(".debug_str_offsets", DebugSecType, 0);

497

498

506 ".debug_str.dwo", DebugSecType,

520

523

524

526 Ctx->getELFSection(".debug_cu_index", DebugSecType, 0);

528 Ctx->getELFSection(".debug_tu_index", DebugSecType, 0);

529

532

535

537 Ctx->getELFSection(".eh_frame", EHSectionType, EHSectionFlags);

538

540

543 Ctx->getELFSection(".pseudo_probe_desc", DebugSecType, 0);

544

546}

547

548void MCObjectFileInfo::initGOFFMCObjectFileInfo(const Triple &T) {

555

558

561}

562

563void MCObjectFileInfo::initCOFFMCObjectFileInfo(const Triple &T) {

567

568

569

570

572

573

578 ".text",

588

591

593 } else {

597 }

598

602 }

603

604

617

758

761

765

769

771

775

779

783

787

791

795}

796

797void MCObjectFileInfo::initSPIRVMCObjectFileInfo(const Triple &T) {

798

800}

801

802void MCObjectFileInfo::initWasmMCObjectFileInfo(const Triple &T) {

805

835

846

847

869

872

873

878

879

880

881

884

885

886}

887

888void MCObjectFileInfo::initXCOFFMCObjectFileInfo(const Triple &T) {

889

890

891

892

894 "..text..",

897 true);

898

899

903

907 true);

908

912 true);

914

918 true);

920

924 true);

926

930 true);

931

936

937

939

944

949

950

951

952

955 std::nullopt,

957

961

965

968 std::nullopt,

970

973 std::nullopt,

975

978 std::nullopt,

980

984

988

991 std::nullopt,

993

996 std::nullopt,

998

1002}

1003

1004void MCObjectFileInfo::initDXContainerObjectFileInfo(const Triple &T) {

1005

1007}

1008

1010

1012 bool LargeCodeModel) {

1013 PositionIndependent = PIC;

1014 Ctx = &MCCtx;

1015

1016

1020

1022

1024

1031

1035 initMachOMCObjectFileInfo(TheTriple);

1036 break;

1038 initCOFFMCObjectFileInfo(TheTriple);

1039 break;

1041 initELFMCObjectFileInfo(TheTriple, LargeCodeModel);

1042 break;

1044 initGOFFMCObjectFileInfo(TheTriple);

1045 break;

1047 initSPIRVMCObjectFileInfo(TheTriple);

1048 break;

1050 initWasmMCObjectFileInfo(TheTriple);

1051 break;

1053 initXCOFFMCObjectFileInfo(TheTriple);

1054 break;

1056 initDXContainerObjectFileInfo(TheTriple);

1057 break;

1058 }

1059}

1060

1061MCSection *MCObjectFileInfo::getDwarfComdatSection(const char *Name,

1066 utostr(Hash), true);

1077 report_fatal_error("Cannot get DWARF comdat section for this object file "

1078 "format: not implemented.");

1079 break;

1080 }

1082}

1083

1089

1094 GroupName = Group->getName();

1096 }

1097

1101}

1102

1106 return nullptr;

1107

1112 GroupName = Group->getName();

1114 }

1115

1116

1117

1119 Flags, 0, GroupName, true, ElfSec.getUniqueID(),

1121}

1122

1126 return nullptr;

1127

1132 GroupName = Group->getName();

1134 }

1135

1137 GroupName,

1138 true, ElfSec.getUniqueID(),

1140}

1141

1146

1147 const auto &ElfSec = static_cast<const MCSectionELF &>(TextSec);

1150 if (const MCSymbol *Group = ElfSec.getGroup()) {

1151 GroupName = Group->getName();

1153 }

1154

1156 Flags, 0, GroupName, true, ElfSec.getUniqueID(),

1158}

1159

1163

1164

1165

1166

1167

1168

1169

1170

1171

1175 return Ctx->getELFSection(S->getName(), S->getType(), Flags,

1176 S->getEntrySize(),

1177 S->getName() + "_" + FuncName,

1178 true);

1179 }

1180 }

1182}

1183

1186}

1187

1189 const MCSection *TextSec) const {

1191 return nullptr;

1192

1193

1195

1196 if (!TextSec)

1198

1200 const auto &ElfSec = static_cast<const MCSectionELF &>(*TextSec);

1201 if (const MCSymbol *Group = ElfSec.getGroup()) {

1202 GroupName = Group->getName();

1204 }

1206 ElfSec.getUniqueID(),

1208}

static bool useCompactUnwind(const Triple &T)

This file declares the MCSectionGOFF class, which contains all of the necessary machine code sections...

PassInstrumentationCallbacks PIC

unsigned getCodePointerSize() const

Get the code pointer size in bytes.

Context object for machine code objects.

MCSectionMachO * getMachOSection(StringRef Segment, StringRef Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind K, const char *BeginSymName=nullptr)

Return the MCSection for the specified mach-o section.

Environment getObjectFileType() const

MCSectionWasm * getWasmSection(const Twine &Section, SectionKind K, unsigned Flags=0)

MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)

MCSectionXCOFF * getXCOFFSection(StringRef Section, SectionKind K, std::optional< XCOFF::CsectProperties > CsectProp=std::nullopt, bool MultiSymbolsAllowed=false, std::optional< XCOFF::DwarfSectionSubtypeFlags > DwarfSubtypeFlags=std::nullopt)

const StringRef & getSwift5ReflectionSegmentName() const

MCSectionCOFF * getCOFFSection(StringRef Section, unsigned Characteristics, StringRef COMDATSymName, int Selection, unsigned UniqueID=GenericSectionID)

MCSectionGOFF * getGOFFSection(StringRef Section, SectionKind Kind, MCSection *Parent, uint32_t Subsection=0)

const MCAsmInfo * getAsmInfo() const

MCSectionDXContainer * getDXContainerSection(StringRef Section, SectionKind K)

Get the section for the provided Section name.

MCSectionSPIRV * getSPIRVSection()

EmitDwarfUnwindType emitDwarfUnwindInfo() const

@ GenericSectionID

Pass this value as the UniqueID during section creation to get the generic section with the given nam...

const Triple & getTargetTriple() const

MCSection * NonLazySymbolPointerSection

MCSection * TLSBSSSection

Section directive for Thread Local uninitialized data.

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 * 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

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 * 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 linux, lots of unix variants and some bare metal systems.

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.

void setAlignment(Align Value)

StringRef getName() const

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.

bool isPS4() const

Tests whether the target is the PS4 platform.

ObjectFormatType getObjectFormat() const

Get the object format for this triple.

bool supportsCOMDAT() const

Tests whether the target supports comdat.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ IMAGE_SCN_CNT_UNINITIALIZED_DATA

@ IMAGE_SCN_MEM_DISCARDABLE

@ IMAGE_SCN_CNT_INITIALIZED_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...

@ 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.

@ 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.

void report_fatal_error(Error Err, bool gen_crash_diag=true)

Report a serious error, calling any installed error handler.

This struct is a compact representation of a valid (non-zero power of two) alignment.