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

1

2

3

4

5

6

7

8

33#include

34#include

35#include

36#include

37#include

38

39using namespace llvm;

40

41#define DEBUG_TYPE "mc"

42

44 Relocations.clear();

45 IndirectSymBase.clear();

46 IndirectSymbols.clear();

47 DataRegions.clear();

48 SectionAddress.clear();

49 SectionOrder.clear();

50 StringTable.clear();

51 LocalSymbolData.clear();

52 ExternalSymbolData.clear();

53 UndefinedSymbolData.clear();

54 LOHContainer.reset();

55 VersionInfo.Major = 0;

57 TargetVariantVersionInfo.Major = 0;

58 TargetVariantVersionInfo.SDKVersion = VersionTuple();

59 LinkerOptions.clear();

61}

62

65 TargetObjectWriter->setAssembler(Asm);

66}

67

69

71 return true;

72

73

74

75 if (static_cast<const MCSymbolMachO &>(S).isWeakDefinition())

76 return true;

77

78

79 return false;

80}

81

82bool MachObjectWriter::

83MachSymbolData::operator<(const MachSymbolData &RHS) const {

84 return Symbol->getName() < RHS.Symbol->getName();

85}

86

91 Asm.getFragmentOffset(*Fragment);

92}

93

95

99 return C->getValue();

100

105

106

107 if (Target.getAddSym() && Target.getAddSym()->isUndefined())

108 report_fatal_error("unable to evaluate offset to undefined symbol '" +

110 if (Target.getSubSym() && Target.getSubSym()->isUndefined())

111 report_fatal_error("unable to evaluate offset to undefined symbol '" +

113

115 if (Target.getAddSym())

117 if (Target.getSubSym())

120 }

121

123 Asm->getSymbolOffset(S);

124}

125

129 unsigned Next =

130 static_cast<const MCSectionMachO *>(Sec)->getLayoutOrder() + 1;

131 if (Next >= SectionOrder.size())

132 return 0;

133

136 return 0;

138}

139

141

142 if (!Symbol.isTemporary())

143 return true;

144

145 if (Symbol.isUsedInReloc())

146 return true;

147

148 return false;

149}

150

152

154 return &S;

155

156

158 return nullptr;

159

160

161

164 return nullptr;

165

166

168}

169

171 unsigned NumLoadCommands,

172 unsigned LoadCommandsSize,

175

178

179

180

181

183 (void) Start;

184

186

187 W.write<uint32_t>(TargetObjectWriter->getCPUType());

188

189 uint32_t Cpusubtype = TargetObjectWriter->getCPUSubtype();

190

191

192

193

197 0, false);

198

200

202 W.write<uint32_t>(NumLoadCommands);

203 W.write<uint32_t>(LoadCommandsSize);

206 W.write<uint32_t>(0);

207

210}

211

214 W.OS << Str;

216}

217

218

219

220

221

226

227

228

230 (void) Start;

231

232 unsigned SegmentLoadCommandSize =

235 W.write<uint32_t>(is64Bit() ? MachO::LC_SEGMENT_64 : MachO::LC_SEGMENT);

236 W.write<uint32_t>(SegmentLoadCommandSize +

239

240 writeWithPadding(Name, 16);

242 W.write<uint64_t>(VMAddr);

243 W.write<uint64_t>(VMSize);

244 W.write<uint64_t>(SectionDataStartOffset);

245 W.write<uint64_t>(SectionDataSize);

246 } else {

247 W.write<uint32_t>(VMAddr);

248 W.write<uint32_t>(VMSize);

249 W.write<uint32_t>(SectionDataStartOffset);

250 W.write<uint32_t>(SectionDataSize);

251 }

252

254

258

259 assert(W.OS.tell() - Start == SegmentLoadCommandSize);

260}

261

264 uint64_t FileOffset, unsigned Flags,

266 unsigned NumRelocations) {

267

269 assert(Asm.getSectionFileSize(Sec) == 0 && "Invalid file size!");

270 FileOffset = 0;

271 }

272

273

274

275

276 uint64_t SectionSize = Asm.getSectionAddressSize(Sec);

278 (void) Start;

279 writeWithPadding(Sec.getName(), 16);

282 W.write<uint64_t>(VMAddr);

283 W.write<uint64_t>(SectionSize);

284 } else {

285 W.write<uint32_t>(VMAddr);

286 W.write<uint32_t>(SectionSize);

287 }

288 assert(isUInt<32>(FileOffset) && "Cannot encode offset of section");

290

293 "Cannot encode offset of relocations");

294 W.write<uint32_t>(NumRelocations ? RelocationsStart : 0);

295 W.write<uint32_t>(NumRelocations);

297 W.write<uint32_t>(IndirectSymBase.lookup(&Sec));

300 W.write<uint32_t>(0);

301

302 assert(W.OS.tell() - Start ==

304}

305

310

311

313 (void) Start;

314

315 W.write<uint32_t>(MachO::LC_SYMTAB);

319 W.write<uint32_t>(StringTableOffset);

320 W.write<uint32_t>(StringTableSize);

321

323}

324

361

362MachObjectWriter::MachSymbolData *

363MachObjectWriter::findSymbolData(const MCSymbol &Sym) {

364 for (auto *SymbolData :

365 {&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})

366 for (MachSymbolData &Entry : *SymbolData)

367 if (Entry.Symbol == &Sym)

368 return &Entry;

369

370 return nullptr;

371}

372

378 if (Ref)

379 return *S;

380 S = &Ref->getSymbol();

381 }

382 return *S;

383}

384

386 auto *Symbol = MSD.Symbol;

388 auto *AliasedSymbol =

390 uint8_t SectionIndex = MSD.SectionIndex;

393 bool IsAlias = Symbol != AliasedSymbol;

394

396 MachSymbolData *AliaseeInfo;

397 if (IsAlias) {

398 AliaseeInfo = findSymbolData(*AliasedSymbol);

399 if (AliaseeInfo)

400 SectionIndex = AliaseeInfo->SectionIndex;

401 Symbol = AliasedSymbol;

402

403 }

404

405

406

407

408 if (IsAlias && Symbol->isUndefined())

410 else if (Symbol->isUndefined())

412 else if (Symbol->isAbsolute())

414 else

416

417

418

419 if (Data.isPrivateExtern())

421

422

423 if (Data.isExternal() || (!IsAlias && Symbol->isUndefined()))

425

426

427 if (IsAlias && Symbol->isUndefined())

428 Address = AliaseeInfo->StringIndex;

429 else if (Symbol->isDefined())

431 else if (Symbol->isCommon()) {

432

433

434 Address = Symbol->getCommonSize();

435 }

436

437

438

439 W.write<uint32_t>(MSD.StringIndex);

441 W.OS << char(SectionIndex);

442

443

444

445 bool EncodeAsAltEntry = IsAlias && OrigSymbol.isAltEntry();

446 W.write<uint16_t>(Symbol->getEncodedFlags(EncodeAsAltEntry));

449 else

451}

452

457 (void) Start;

458

463

465}

466

468 const std::vectorstd::string &Options, bool is64Bit)

469{

471 for (const std::string &Option : Options)

472 Size += Option.size() + 1;

474}

475

477 const std::vectorstd::string &Options)

478{

481 (void) Start;

482

483 W.write<uint32_t>(MachO::LC_LINKER_OPTION);

487 for (const std::string &Option : Options) {

488

489 W.OS << Option << '\0';

490 BytesWritten += Option.size() + 1;

491 }

492

493

494 W.OS.write_zeros(

496

498}

499

501

502

503 if (Target.getAddSym() && Target.getSubSym())

504 return false;

505 return true;

506}

507

513 "unsupported relocation expression");

514 return;

515 }

516

517 TargetObjectWriter->recordRelocation(this, *Asm, &F, Fixup, Target,

518 FixedValue);

519}

520

522

523

524

525

526

527

528

529

530

531 for (IndirectSymbolData &ISD : IndirectSymbols) {

533

540 "' not in a symbol pointer or stub section");

541 }

542 }

543

544

545 for (auto [IndirectIndex, ISD] : enumerate(IndirectSymbols)) {

546 const auto &Section = static_cast<MCSectionMachO &>(*ISD.Section);

547

550 continue;

551

552

553 IndirectSymBase.insert(std::make_pair(ISD.Section, IndirectIndex));

554

555 Asm.registerSymbol(*ISD.Symbol);

556 }

557

558

559 for (auto [IndirectIndex, ISD] : enumerate(IndirectSymbols)) {

560 const auto &Section = static_cast<MCSectionMachO &>(*ISD.Section);

561

564 continue;

565

566

567 IndirectSymBase.insert(std::make_pair(ISD.Section, IndirectIndex));

568

569

570

571

572 if (Asm.registerSymbol(*ISD.Symbol))

573 ISD.Symbol->setReferenceTypeUndefinedLazy(true);

574 }

575}

576

577

579 MCAssembler &Asm, std::vector &LocalSymbolData,

580 std::vector &ExternalSymbolData,

581 std::vector &UndefinedSymbolData) {

582

584 unsigned Index = 1;

586 SectionIndexMap[&Sec] = Index++;

587

588

589

590

591 if (Index > 255)

593

594

595 for (const MCSymbol &Symbol : Asm.symbols()) {

597 continue;

598

599 StringTable.add(Symbol.getName());

600 }

601 StringTable.finalize();

602

603

604

605

606

607

608 for (const MCSymbol &Symbol : Asm.symbols()) {

609 auto &Sym = static_cast<const MCSymbolMachO &>(Symbol);

610

611 if (!Sym.isSymbolLinkerVisible())

612 continue;

613

614 if (!Sym.isExternal() && !Sym.isUndefined())

615 continue;

616

617 MachSymbolData MSD;

618 MSD.Symbol = &Sym;

619 MSD.StringIndex = StringTable.getOffset(Symbol.getName());

620

621 if (Symbol.isUndefined()) {

622 MSD.SectionIndex = 0;

623 UndefinedSymbolData.push_back(MSD);

624 } else if (Symbol.isAbsolute()) {

625 MSD.SectionIndex = 0;

626 ExternalSymbolData.push_back(MSD);

627 } else {

628 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());

629 if (!MSD.SectionIndex)

631 ExternalSymbolData.push_back(MSD);

632 }

633 }

634

635

636 for (const MCSymbol &Symbol : Asm.symbols()) {

637 auto &Sym = static_cast<const MCSymbolMachO &>(Symbol);

638

639 if (!Sym.isSymbolLinkerVisible())

640 continue;

641

642 if (Sym.isExternal() || Sym.isUndefined())

643 continue;

644

645 MachSymbolData MSD;

646 MSD.Symbol = &Sym;

647 MSD.StringIndex = StringTable.getOffset(Symbol.getName());

648

649 if (Symbol.isAbsolute()) {

650 MSD.SectionIndex = 0;

651 LocalSymbolData.push_back(MSD);

652 } else {

653 MSD.SectionIndex = SectionIndexMap.lookup(&Symbol.getSection());

654 if (!MSD.SectionIndex)

656 LocalSymbolData.push_back(MSD);

657 }

658 }

659

660

663

664

665 Index = 0;

666 for (auto *SymbolData :

667 {&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})

668 for (MachSymbolData &Entry : *SymbolData)

669 Entry.Symbol->setIndex(Index++);

670

672 for (RelAndSymbol &Rel : Relocations[&Section]) {

673 if (!Rel.Sym)

674 continue;

675

676

677 unsigned Index = Rel.Sym->getIndex();

680 Rel.MRE.r_word1 = (Rel.MRE.r_word1 & (~0U << 24)) | Index | (1 << 27);

681 else

682 Rel.MRE.r_word1 = (Rel.MRE.r_word1 & 0xff) | Index << 8 | (1 << 4);

683 }

684 }

685}

686

688

689 unsigned i = 0;

690

692 if (!Sec.isBssSection()) {

693 SectionOrder.push_back(&Sec);

694 static_cast<MCSectionMachO &>(Sec).setLayoutOrder(i++);

695 }

696 }

698 if (Sec.isBssSection()) {

699 SectionOrder.push_back(&Sec);

700 static_cast<MCSectionMachO &>(Sec).setLayoutOrder(i++);

701 }

702 }

703

705 for (const MCSection *Sec : SectionOrder) {

706 StartAddress = alignTo(StartAddress, Sec->getAlign());

707 SectionAddress[Sec] = StartAddress;

708 StartAddress += Asm.getSectionAddressSize(*Sec);

709

710

711

712

714 }

715}

716

723

726 bool IsPCRel) const {

727 if (InSet)

728 return true;

729

730

731

732

733

734

738

739 if (IsPCRel) {

740

741

742

743

744

745

746

747

748

749

750

751

752

753 bool hasReliableSymbolDifference = isX86_64();

754 if (!hasReliableSymbolDifference) {

755 if (!SA.isInSection() || &SecA != &SecB ||

758 return false;

759 return true;

760 }

761 }

762

763

764 if (&SecA != &SecB)

765 return false;

766

767

769}

770

772 switch (Type) {

777 }

779}

780

784 unsigned Log2Size = is64Bit() ? 3 : 2;

786 if (!S->isRegistered())

787 continue;

792 }

793}

794

796 auto &Asm = *this->Asm;

797 uint64_t StartOffset = W.OS.tell();

798 auto NumBytesWritten = [&] { return W.OS.tell() - StartOffset; };

799

801

802

804 UndefinedSymbolData);

805

810 uint32_t FromIndex = CGPE.From->getSymbol().getIndex();

811 uint32_t ToIndex = CGPE.To->getSymbol().getIndex();

815 }

819 }

820

821 unsigned NumSections = Asm.end() - Asm.begin();

822

823

824

825 unsigned NumLoadCommands = 1;

829

830

831 if (VersionInfo.Major != 0) {

832 ++NumLoadCommands;

833 if (VersionInfo.EmitBuildVersion)

835 else

837 }

838

839

840 if (TargetVariantVersionInfo.Major != 0) {

841 ++NumLoadCommands;

842 assert(TargetVariantVersionInfo.EmitBuildVersion &&

843 "target variant should use build version");

845 }

846

847

848 unsigned NumDataRegions = DataRegions.size();

849 if (NumDataRegions) {

850 ++NumLoadCommands;

852 }

853

854

855 uint64_t LOHRawSize = LOHContainer.getEmitSize(Asm, *this);

857 if (LOHSize) {

858 ++NumLoadCommands;

860 }

861

862

863 unsigned NumSymbols = LocalSymbolData.size() + ExternalSymbolData.size() +

864 UndefinedSymbolData.size();

865 if (NumSymbols) {

866 NumLoadCommands += 2;

869 }

870

871

872 for (const auto &Option : LinkerOptions) {

873 ++NumLoadCommands;

875 }

876

877

878

881 uint64_t SectionDataSize = 0;

882 uint64_t SectionDataFileSize = 0;

887 uint64_t FileSize = Asm.getSectionFileSize(Sec);

889

890 VMSize = std::max(VMSize, Address + Size);

891

892 if (Sec.isBssSection())

893 continue;

894

895 SectionDataSize = std::max(SectionDataSize, Address + Size);

896 SectionDataFileSize = std::max(SectionDataFileSize, Address + FileSize);

897 }

898

899

900

901

902 unsigned SectionDataPadding =

904 SectionDataFileSize += SectionDataPadding;

905

906

912 SectionDataSize, Prot, Prot);

913

914

915 uint64_t RelocTableEnd = SectionDataStart + SectionDataFileSize;

917 const auto &Sec = static_cast<const MCSectionMachO &>(Section);

918 std::vector &Relocs = Relocations[&Sec];

919 unsigned NumRelocs = Relocs.size();

921 unsigned Flags = Sec.getTypeAndAttributes();

922 if (Sec.hasInstructions())

927 SMLoc(), "cannot encode offset of section; object file too large");

928 return NumBytesWritten();

929 }

930 if (NumRelocs && isUInt<32>(RelocTableEnd)) {

933 "cannot encode offset of relocations; object file too large");

934 return NumBytesWritten();

935 }

937 RelocTableEnd, NumRelocs);

939 }

940

941

942 auto EmitDeploymentTargetVersion =

945 assert(!V.empty() && "empty version");

946 unsigned Update = V.getSubminor().value_or(0);

947 unsigned Minor = V.getMinor().value_or(0);

948 assert(Update < 256 && "unencodable update target version");

949 assert(Minor < 256 && "unencodable minor target version");

950 assert(V.getMajor() < 65536 && "unencodable major target version");

951 return Update | (Minor << 8) | (V.getMajor() << 16);

952 };

954 VersionInfo.Major, VersionInfo.Minor, VersionInfo.Update));

955 uint32_t SDKVersion = !VersionInfo.SDKVersion.empty()

956 ? EncodeVersion(VersionInfo.SDKVersion)

957 : 0;

958 if (VersionInfo.EmitBuildVersion) {

959

960 W.write<uint32_t>(MachO::LC_BUILD_VERSION);

962 W.write<uint32_t>(VersionInfo.TypeOrPlatform.Platform);

963 W.write<uint32_t>(EncodedVersion);

965 W.write<uint32_t>(0);

966 } else {

971 W.write<uint32_t>(EncodedVersion);

973 }

974 };

975 if (VersionInfo.Major != 0)

976 EmitDeploymentTargetVersion(VersionInfo);

977 if (TargetVariantVersionInfo.Major != 0)

978 EmitDeploymentTargetVersion(TargetVariantVersionInfo);

979

980

981 uint64_t DataInCodeTableEnd = RelocTableEnd + NumDataRegions * 8;

982 if (NumDataRegions) {

983 uint64_t DataRegionsOffset = RelocTableEnd;

984 uint64_t DataRegionsSize = NumDataRegions * 8;

986 DataRegionsSize);

987 }

988

989

990 uint64_t LOHTableEnd = DataInCodeTableEnd + LOHSize;

991 if (LOHSize)

993 DataInCodeTableEnd, LOHSize);

994

995

996 if (NumSymbols) {

997 unsigned FirstLocalSymbol = 0;

998 unsigned NumLocalSymbols = LocalSymbolData.size();

999 unsigned FirstExternalSymbol = FirstLocalSymbol + NumLocalSymbols;

1000 unsigned NumExternalSymbols = ExternalSymbolData.size();

1001 unsigned FirstUndefinedSymbol = FirstExternalSymbol + NumExternalSymbols;

1002 unsigned NumUndefinedSymbols = UndefinedSymbolData.size();

1003 unsigned NumIndirectSymbols = IndirectSymbols.size();

1004 unsigned NumSymTabSymbols =

1005 NumLocalSymbols + NumExternalSymbols + NumUndefinedSymbols;

1006 uint64_t IndirectSymbolSize = NumIndirectSymbols * 4;

1007 uint64_t IndirectSymbolOffset = 0;

1008

1009

1010 if (NumIndirectSymbols)

1011 IndirectSymbolOffset = LOHTableEnd;

1012

1013

1014 uint64_t SymbolTableOffset = LOHTableEnd + IndirectSymbolSize;

1015

1016

1017 uint64_t StringTableOffset =

1018 SymbolTableOffset + NumSymTabSymbols * (is64Bit() ?

1022 StringTableOffset, StringTable.getSize());

1023

1025 FirstExternalSymbol, NumExternalSymbols,

1026 FirstUndefinedSymbol, NumUndefinedSymbols,

1027 IndirectSymbolOffset, NumIndirectSymbols);

1028 }

1029

1030

1031 for (const auto &Option : LinkerOptions)

1033

1034

1036 Asm.writeSectionData(W.OS, &Sec);

1037

1039 W.OS.write_zeros(Pad);

1040 }

1041

1042

1043 W.OS.write_zeros(SectionDataPadding);

1044

1045

1047

1048

1049 std::vector &Relocs = Relocations[&Sec];

1050 for (const RelAndSymbol &Rel : llvm::reverse(Relocs)) {

1051 W.write<uint32_t>(Rel.MRE.r_word0);

1052 W.write<uint32_t>(Rel.MRE.r_word1);

1053 }

1054 }

1055

1056

1060 if (Data.End)

1062 else

1064

1066 << " start: " << Start << "(" << Data.Start->getName()

1067 << ")" << " end: " << End << "(" << Data.End->getName()

1068 << ")" << " size: " << End - Start << "\n");

1072 }

1073

1074

1075 if (LOHSize) {

1076#ifndef NDEBUG

1077 unsigned Start = W.OS.tell();

1078#endif

1079 LOHContainer.emit(Asm, *this);

1080

1081 W.OS.write_zeros(

1083 assert(W.OS.tell() - Start == LOHSize);

1084 }

1085

1086

1087 if (NumSymbols) {

1088

1089 for (auto &ISD : IndirectSymbols) {

1090

1091

1095

1096 if (ISD.Symbol->isDefined() && ISD.Symbol->isExternal()) {

1098 if (ISD.Symbol->isAbsolute())

1101 continue;

1102 }

1103 }

1104

1106 }

1107

1108

1109

1110

1111 for (auto *SymbolData :

1112 {&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})

1113 for (MachSymbolData &Entry : *SymbolData)

1115

1116

1117 StringTable.write(W.OS);

1118 }

1119

1120 return NumBytesWritten();

1121}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file defines the DenseMap class.

static unsigned ComputeLinkerOptionsLoadCommandSize(const std::vector< std::string > &Options, bool is64Bit)

Definition MachObjectWriter.cpp:467

static bool isFixupTargetValid(const MCValue &Target)

Definition MachObjectWriter.cpp:500

static MachO::LoadCommandType getLCFromMCVM(MCVersionMinType Type)

Definition MachObjectWriter.cpp:771

static bool isSymbolLinkerVisible(const MCSymbol &Symbol)

Definition MachObjectWriter.cpp:140

PowerPC TLS Dynamic Call Fixup

static bool is64Bit(const char *name)

ValueT lookup(const_arg_type_t< KeyT > Val) const

lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...

static bool isSectionAtomizableBySymbols(const MCSection &Section)

True if the section is atomized using the symbols in it.

const MCObjectFileInfo * getObjectFileInfo() const

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

LLVM_ABI void reportError(SMLoc L, const Twine &Msg)

Base class for the full range of assembler expressions which are needed for parsing.

LLVM_ABI bool evaluateAsRelocatable(MCValue &Res, const MCAssembler *Asm) const

Try to evaluate the expression to a relocatable value, i.e.

Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...

LLVM_ABI const MCSymbol * getAtom() const

MCSection * getParent() const

MutableArrayRef< char > getVarContents()

MCSection * getAddrSigSection() const

SmallVector< CGProfileEntry, 0 > CGProfile

virtual void setAssembler(MCAssembler *A)

bool SubsectionsViaSymbols

std::vector< const MCSymbol * > & getAddrsigSyms()

virtual void reset()

lifetime management

MCContext & getContext() const

This represents a section on a Mach-O system (used by Mac OS X).

StringRef getSegmentName() const

unsigned getStubSize() const

Instances of this class represent a uniqued identifier for a section in the current translation unit.

bool isBssSection() const

Check whether this section is "virtual", that is has no actual object file contents.

StringRef getName() const

FragList * curFragList() const

MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...

bool isInSection() const

isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute).

bool isUndefined() const

isUndefined - Check if this symbol undefined (i.e., implicitly defined).

StringRef getName() const

getName - Get the symbol name.

bool isVariable() const

isVariable - Check if this is a variable symbol.

MCSection & getSection() const

Get the section associated with a defined, non-absolute symbol.

const MCExpr * getVariableValue() const

Get the expression of the variable symbol.

bool isTemporary() const

isTemporary - Check if this is an assembler temporary symbol.

MCFragment * getFragment() const

uint64_t getPaddingSize(const MCAssembler &Asm, const MCSection *SD) const

Definition MachObjectWriter.cpp:126

void computeSectionAddresses(const MCAssembler &Asm)

Definition MachObjectWriter.cpp:687

bool doesSymbolRequireExternRelocation(const MCSymbol &S)

Definition MachObjectWriter.cpp:68

void recordRelocation(const MCFragment &F, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override

Record a relocation entry.

Definition MachObjectWriter.cpp:508

void computeSymbolTable(MCAssembler &Asm, std::vector< MachSymbolData > &LocalSymbolData, std::vector< MachSymbolData > &ExternalSymbolData, std::vector< MachSymbolData > &UndefinedSymbolData)

Compute the symbol table data.

Definition MachObjectWriter.cpp:578

uint64_t writeObject() override

Write the object file and returns the number of bytes written.

Definition MachObjectWriter.cpp:795

uint64_t getFragmentAddress(const MCAssembler &Asm, const MCFragment *Fragment) const

Definition MachObjectWriter.cpp:88

bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override

Definition MachObjectWriter.cpp:724

uint64_t getSectionAddress(const MCSection *Sec) const

void addRelocation(const MCSymbol *RelSymbol, const MCSection *Sec, MachO::any_relocation_info &MRE)

void writeSection(const MCAssembler &Asm, const MCSectionMachO &Sec, uint64_t VMAddr, uint64_t FileOffset, unsigned Flags, uint64_t RelocationsStart, unsigned NumRelocations)

Definition MachObjectWriter.cpp:262

void populateAddrSigSection(MCAssembler &Asm)

Definition MachObjectWriter.cpp:781

support::endian::Writer W

void writeLinkerOptionsLoadCommand(const std::vector< std::string > &Options)

Definition MachObjectWriter.cpp:476

void executePostLayoutBinding() override

Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...

Definition MachObjectWriter.cpp:717

void writeNlist(MachSymbolData &MSD, const MCAssembler &Asm)

Definition MachObjectWriter.cpp:385

void writeDysymtabLoadCommand(uint32_t FirstLocalSymbol, uint32_t NumLocalSymbols, uint32_t FirstExternalSymbol, uint32_t NumExternalSymbols, uint32_t FirstUndefinedSymbol, uint32_t NumUndefinedSymbols, uint32_t IndirectSymbolOffset, uint32_t NumIndirectSymbols)

Definition MachObjectWriter.cpp:325

const MCSymbol & findAliasedSymbol(const MCSymbol &Sym) const

Definition MachObjectWriter.cpp:373

void writeSegmentLoadCommand(StringRef Name, unsigned NumSections, uint64_t VMAddr, uint64_t VMSize, uint64_t SectionDataStartOffset, uint64_t SectionDataSize, uint32_t MaxProt, uint32_t InitProt)

Write a segment load command.

Definition MachObjectWriter.cpp:222

const MCSymbol * getAtom(const MCSymbol &S) const

Definition MachObjectWriter.cpp:151

void writeLinkeditLoadCommand(uint32_t Type, uint32_t DataOffset, uint32_t DataSize)

Definition MachObjectWriter.cpp:453

void writeHeader(MachO::HeaderFileType Type, unsigned NumLoadCommands, unsigned LoadCommandsSize, bool SubsectionsViaSymbols)

Definition MachObjectWriter.cpp:170

void setAssembler(MCAssembler *Asm) override

Definition MachObjectWriter.cpp:63

void reset() override

lifetime management

Definition MachObjectWriter.cpp:43

void writeSymtabLoadCommand(uint32_t SymbolOffset, uint32_t NumSymbols, uint32_t StringTableOffset, uint32_t StringTableSize)

Definition MachObjectWriter.cpp:306

void bindIndirectSymbols(MCAssembler &Asm)

Definition MachObjectWriter.cpp:521

uint64_t getSymbolAddress(const MCSymbol &S) const

Definition MachObjectWriter.cpp:94

struct { bool EmitBuildVersion; union { MCVersionMinType Type; MachO::PlatformType Platform; } TypeOrPlatform; unsigned Major; unsigned Minor; unsigned Update; VersionTuple SDKVersion; } VersionInfoType

Represents a location in source code.

static SectionKind getMetadata()

SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...

StringRef - Represent a constant reference to a string, i.e.

Target - Wrapper for Target specific information.

const char * getName() const

getName - Get the target name.

The instances of the Type class are immutable: once they are created, they are never changed.

LLVM Value Representation.

Represents a version number in the form major[.minor[.subminor[.build]]].

raw_ostream & write_zeros(unsigned NumZeros)

write_zeros - Insert 'NumZeros' nulls.

A raw_ostream that writes to an SmallVector or SmallString.

StringRef str() const

Return a StringRef for the vector contents.

#define llvm_unreachable(msg)

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

@ C

The default llvm calling convention, compatible with C.

ISD namespace - This namespace contains an enum which represents all of the SelectionDAG node types a...

@ S_THREAD_LOCAL_VARIABLE_POINTERS

S_THREAD_LOCAL_VARIABLE_POINTERS - Section with pointers to thread local structures.

@ S_LAZY_SYMBOL_POINTERS

S_LAZY_SYMBOL_POINTERS - Section with lazy symbol pointers.

@ S_NON_LAZY_SYMBOL_POINTERS

S_NON_LAZY_SYMBOL_POINTERS - Section with non-lazy symbol pointers.

@ S_SYMBOL_STUBS

S_SYMBOL_STUBS - Section with symbol stubs, byte size of stub in the Reserved2 field.

@ MH_SUBSECTIONS_VIA_SYMBOLS

uint32_t CPU_SUBTYPE_ARM64E_WITH_PTRAUTH_VERSION(unsigned PtrAuthABIVersion, bool PtrAuthKernelABIVersion)

@ S_ATTR_SOME_INSTRUCTIONS

S_ATTR_SOME_INSTRUCTIONS - Section contains some machine instructions.

void write(void *memory, value_type value, endianness endian)

Write a value to memory with a particular endianness.

This is an optimization pass for GlobalISel generic memory operations.

constexpr bool isInt(int64_t x)

Checks if an integer fits into the given bit width.

auto enumerate(FirstRange &&First, RestRanges &&...Rest)

Given two or more input ranges, returns a new range whose values are tuples (A, B,...

decltype(auto) dyn_cast(const From &Val)

dyn_cast - Return the argument parameter cast to the specified type.

FunctionAddr VTableAddr uintptr_t uintptr_t DataSize

auto reverse(ContainerTy &&C)

void sort(IteratorTy Start, IteratorTy End)

@ MCVM_WatchOSVersionMin

.watchos_version_min

@ MCVM_OSXVersionMin

.macosx_version_min

@ MCVM_TvOSVersionMin

.tvos_version_min

@ MCVM_IOSVersionMin

.ios_version_min

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)

constexpr bool isUInt(uint64_t x)

Checks if an unsigned integer fits into the given bit width.

uint64_t offsetToAlignment(uint64_t Value, Align Alignment)

Returns the offset to the next integer (mod 2**64) that is greater than or equal to Value and is a mu...

@ Ref

The access may reference the value stored in memory.

FunctionAddr VTableAddr uintptr_t uintptr_t Data

uint64_t alignTo(uint64_t Size, Align A)

Returns a multiple of A needed to store Size bytes.

FunctionAddr VTableAddr Next

OutputIt copy(R &&Range, OutputIt Out)

decltype(auto) cast(const From &Val)

cast - Return the argument parameter cast to the specified type.

unsigned Log2(Align A)

Returns the log2 of the alignment.

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