1//===- lib/MC/MachObjectWriter.cpp - Mach-O File Writer -------------------===//
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//===----------------------------------------------------------------------===//
41 #define DEBUG_TYPE "mc"
45 IndirectSymBase.clear();
46 IndirectSymbols.clear();
48 SectionAddress.clear();
51 LocalSymbolData.clear();
52 ExternalSymbolData.clear();
53 UndefinedSymbolData.clear();
55 VersionInfo.Major = 0;
57 TargetVariantVersionInfo.Major = 0;
59 LinkerOptions.clear();
65 TargetObjectWriter->setAssembler(
Asm);
69 // Undefined symbols are always extern.
73 // References to weak definitions require external relocation entries; the
74 // definition may not always be the one in the same object file.
78 // Otherwise, we can use an internal relocation.
82bool MachObjectWriter::
83MachSymbolData::operator<(
const MachSymbolData &RHS)
const {
84 return Symbol->getName() < RHS.Symbol->getName();
91 Asm.getFragmentOffset(*Fragment);
95 // If this is a variable, then recursively evaluate now.
106 // Verify that any used symbols are defined.
107 if (
Target.getAddSym() &&
Target.getAddSym()->isUndefined())
110 if (
Target.getSubSym() &&
Target.getSubSym()->isUndefined())
123 Asm->getSymbolOffset(S);
131 if (
Next >= SectionOrder.size())
141 // Non-temporary labels should always be visible to the linker.
142 if (!Symbol.isTemporary())
145 if (Symbol.isUsedInReloc())
152 // Linker visible symbols define atoms.
156 // Absolute and undefined symbols have no defining atom.
160 // Non-linker visible symbols in sections which can't be atomized have no
166 // Otherwise, return the atom for the containing fragment.
171 unsigned NumLoadCommands,
172 unsigned LoadCommandsSize,
179 // struct mach_header (28 bytes) or
180 // struct mach_header_64 (32 bytes)
187 W.write<
uint32_t>(TargetObjectWriter->getCPUType());
189 uint32_t Cpusubtype = TargetObjectWriter->getCPUSubtype();
191 // Promote arm64e subtypes to always be ptrauth-ABI-versioned, at version 0.
192 // We never need to emit unversioned binaries.
193 // And we don't support arbitrary ABI versions (or the kernel flag) yet.
197 /*PtrAuthABIVersion=*/0,
/*PtrAuthKernelABIVersion=*/false);
218/// writeSegmentLoadCommand - Write a segment load command.
220/// \param NumSections The number of sections in this segment.
221/// \param SectionDataSize The total size of the sections.
226 // struct segment_command (56 bytes) or
227 // struct segment_command_64 (72 bytes)
232 unsigned SegmentLoadCommandSize =
236 W.write<
uint32_t>(SegmentLoadCommandSize +
240 writeWithPadding(Name, 16);
244 W.write<
uint64_t>(SectionDataStartOffset);
// file offset
245 W.write<
uint64_t>(SectionDataSize);
// file size
249 W.write<
uint32_t>(SectionDataStartOffset);
// file offset
250 W.write<
uint32_t>(SectionDataSize);
// file size
259 assert(
W.OS.tell() - Start == SegmentLoadCommandSize);
264 uint64_t FileOffset,
unsigned Flags,
266 unsigned NumRelocations) {
267 // The offset is unused for virtual sections.
269 assert(
Asm.getSectionFileSize(Sec) == 0 &&
"Invalid file size!");
273 // struct section (68 bytes) or
274 // struct section_64 (80 bytes)
276 uint64_t SectionSize =
Asm.getSectionAddressSize(Sec);
279 writeWithPadding(Sec.
getName(), 16);
293 "Cannot encode offset of relocations");
294 W.write<
uint32_t>(NumRelocations ? RelocationsStart : 0);
297 W.write<
uint32_t>(IndirectSymBase.lookup(&Sec));
// reserved1
310 // struct symtab_command (24 bytes)
333 // struct dysymtab_command (80 bytes)
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)
380 S = &
Ref->getSymbol();
386 auto *Symbol = MSD.Symbol;
388 auto *AliasedSymbol =
390 uint8_t SectionIndex = MSD.SectionIndex;
393 bool IsAlias = Symbol != AliasedSymbol;
396 MachSymbolData *AliaseeInfo;
398 AliaseeInfo = findSymbolData(*AliasedSymbol);
400 SectionIndex = AliaseeInfo->SectionIndex;
401 Symbol = AliasedSymbol;
402 // FIXME: Should this update Data as well?
405 // Set the N_TYPE bits. See <mach-o/nlist.h>.
407 // FIXME: Are the prebound or indirect fields possible here?
408 if (IsAlias && Symbol->isUndefined())
410 else if (Symbol->isUndefined())
412 else if (Symbol->isAbsolute())
417 // FIXME: Set STAB bits.
419 if (
Data.isPrivateExtern())
423 if (
Data.isExternal() || (!IsAlias && Symbol->isUndefined()))
426 // Compute the symbol address.
427 if (IsAlias && Symbol->isUndefined())
428 Address = AliaseeInfo->StringIndex;
429 else if (Symbol->isDefined())
431 else if (Symbol->isCommon()) {
432 // Common symbols are encoded with the size in the address
433 // field, and their alignment in the flags.
434 Address = Symbol->getCommonSize();
437 // struct nlist (12 bytes)
441 W.OS <<
char(SectionIndex);
443 // The Mach-O streamer uses the lowest 16-bits of the flags for the 'desc'
445 bool EncodeAsAltEntry = IsAlias && OrigSymbol.
isAltEntry();
446 W.write<
uint16_t>(Symbol->getEncodedFlags(EncodeAsAltEntry));
471 for (
const std::string &Option :
Options)
472 Size += Option.size() + 1;
477 const std::vector<std::string> &
Options)
483 W.write<
uint32_t>(MachO::LC_LINKER_OPTION);
487 for (
const std::string &Option :
Options) {
488 // Write each string, including the null byte.
489 W.OS << Option <<
'0円';
490 BytesWritten += Option.size() + 1;
493 // Pad to a multiple of the pointer size.
501 // Target is (LHS - RHS + cst).
502 // We don't support the form where LHS is null: -RHS + cst
513 "unsupported relocation expression");
522 // This is the point where 'as' creates actual symbols for indirect symbols
523 // (in the following two passes). It would be easier for us to do this sooner
524 // when we see the attribute, but that makes getting the order in the symbol
525 // table much more complicated than it is worth.
527 // FIXME: Revisit this when the dust settles.
529 // Report errors for use of .indirect_symbol not in a symbol pointer section
531 for (IndirectSymbolData &
ISD : IndirectSymbols) {
540 "' not in a symbol pointer or stub section");
544 // Bind non-lazy symbol pointers first.
545 for (
auto [IndirectIndex,
ISD] :
enumerate(IndirectSymbols)) {
552 // Initialize the section indirect symbol base, if necessary.
553 IndirectSymBase.insert(std::make_pair(
ISD.Section, IndirectIndex));
555 Asm.registerSymbol(*
ISD.Symbol);
558 // Then lazy symbol pointers and symbol stubs.
559 for (
auto [IndirectIndex,
ISD] :
enumerate(IndirectSymbols)) {
566 // Initialize the section indirect symbol base, if necessary.
567 IndirectSymBase.insert(std::make_pair(
ISD.Section, IndirectIndex));
569 // Set the symbol type to undefined lazy, but only on construction.
571 // FIXME: Do not hardcode.
572 if (
Asm.registerSymbol(*
ISD.Symbol))
574 ->setReferenceTypeUndefinedLazy(
true);
578/// computeSymbolTable - Compute the symbol table data
581 std::vector<MachSymbolData> &ExternalSymbolData,
582 std::vector<MachSymbolData> &UndefinedSymbolData) {
583 // Build section lookup table.
587 SectionIndexMap[&Sec] = Index++;
588 assert(Index <= 256 &&
"Too many sections!");
590 // Build the string table.
595 StringTable.add(Symbol.getName());
597 StringTable.finalize();
599 // Build the symbol arrays but only for non-local symbols.
601 // The particular order that we collect and then sort the symbols is chosen to
602 // match 'as'. Even though it doesn't matter for correctness, this is
603 // important for letting us diff .o files.
606 // Ignore non-linker visible symbols.
607 if (!Sym.isSymbolLinkerVisible())
615 MSD.StringIndex = StringTable.getOffset(Symbol.getName());
617 if (Symbol.isUndefined()) {
618 MSD.SectionIndex = 0;
619 UndefinedSymbolData.push_back(MSD);
620 }
else if (Symbol.isAbsolute()) {
621 MSD.SectionIndex = 0;
622 ExternalSymbolData.push_back(MSD);
624 MSD.SectionIndex = SectionIndexMap.
lookup(&Symbol.getSection());
625 assert(MSD.SectionIndex &&
"Invalid section index!");
626 ExternalSymbolData.push_back(MSD);
630 // Now add the data for local symbols.
633 // Ignore non-linker visible symbols.
634 if (!Sym.isSymbolLinkerVisible())
642 MSD.StringIndex = StringTable.getOffset(Symbol.getName());
644 if (Symbol.isAbsolute()) {
645 MSD.SectionIndex = 0;
646 LocalSymbolData.push_back(MSD);
648 MSD.SectionIndex = SectionIndexMap.
lookup(&Symbol.getSection());
649 assert(MSD.SectionIndex &&
"Invalid section index!");
650 LocalSymbolData.push_back(MSD);
654 // External and undefined symbols are required to be in lexicographic order.
658 // Set the symbol indices.
660 for (
auto *SymbolData :
661 {&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})
662 for (MachSymbolData &Entry : *SymbolData)
663 Entry.Symbol->setIndex(Index++);
666 for (RelAndSymbol &Rel : Relocations[&Section]) {
670 // Set the Index and the IsExtern bit.
671 unsigned Index = Rel.Sym->getIndex();
674 Rel.MRE.r_word1 = (Rel.MRE.r_word1 & (~0U << 24)) | Index | (1 << 27);
676 Rel.MRE.r_word1 = (Rel.MRE.r_word1 & 0xff) | Index << 8 | (1 << 4);
682 // Assign layout order indices to sections.
684 // Compute the section layout order. Virtual sections must go last.
686 if (!Sec.isBssSection()) {
687 SectionOrder.push_back(&Sec);
692 if (Sec.isBssSection()) {
693 SectionOrder.push_back(&Sec);
699 for (
const MCSection *Sec : SectionOrder) {
700 StartAddress =
alignTo(StartAddress, Sec->getAlign());
701 SectionAddress[Sec] = StartAddress;
702 StartAddress +=
Asm.getSectionAddressSize(*Sec);
704 // Explicitly pad the section to match the alignment requirements of the
705 // following one. This is for 'gas' compatibility, it shouldn't
706 /// strictly be necessary.
714 // Create symbol data for any indirect symbols.
720 bool IsPCRel)
const {
724 // The effective address is
725 // addr(atom(A)) + offset(A)
726 // - addr(atom(B)) - offset(B)
727 // and the offsets are not relocatable, so the fixup is fully resolved when
728 // addr(atom(A)) - addr(atom(B)) == 0.
734 // The simple (Darwin, except on x86_64) way of dealing with this was to
735 // assume that any reference to a temporary symbol *must* be a temporary
736 // symbol in the same atom, unless the sections differ. Therefore, any PCrel
737 // relocation to a temporary symbol (in the same section) is fully
738 // resolved. This also works in conjunction with absolutized .set, which
739 // requires the compiler to use .set to absolutize the differences between
740 // symbols which the compiler knows to be assembly time constants, so we
741 // don't need to worry about considering symbol differences fully resolved.
743 // If the file isn't using sub-sections-via-symbols, we can make the
744 // same assumptions about any symbol that we normally make about
747 bool hasReliableSymbolDifference =
isX86_64();
748 if (!hasReliableSymbolDifference) {
757 // If they are not in the same section, we can't compute the diff.
761 // If the atoms are the same, they are guaranteed to have the same address.
778 unsigned Log2Size =
is64Bit() ? 3 : 2;
780 if (!S->isRegistered())
792 auto NumBytesWritten = [&] {
return W.OS.tell() - StartOffset; };
796 // Compute symbol table information and bind symbol indices.
798 UndefinedSymbolData);
804 uint32_t FromIndex = CGPE.From->getSymbol().getIndex();
805 uint32_t ToIndex = CGPE.To->getSymbol().getIndex();
815 unsigned NumSections =
Asm.end() -
Asm.begin();
817 // The section data starts after the header, the segment load command (and
818 // section headers) and the symbol table.
819 unsigned NumLoadCommands = 1;
824 // Add the deployment target version info load command size, if used.
825 if (VersionInfo.Major != 0) {
827 if (VersionInfo.EmitBuildVersion)
833 // Add the target variant version info load command size, if used.
834 if (TargetVariantVersionInfo.Major != 0) {
836 assert(TargetVariantVersionInfo.EmitBuildVersion &&
837 "target variant should use build version");
841 // Add the data-in-code load command size, if used.
842 unsigned NumDataRegions = DataRegions.size();
843 if (NumDataRegions) {
848 // Add the loh load command size, if used.
849 uint64_t LOHRawSize = LOHContainer.getEmitSize(
Asm, *
this);
856 // Add the symbol table load command sizes, if used.
857 unsigned NumSymbols = LocalSymbolData.size() + ExternalSymbolData.size() +
858 UndefinedSymbolData.size();
860 NumLoadCommands += 2;
865 // Add the linker option load commands sizes.
866 for (
const auto &Option : LinkerOptions) {
871 // Compute the total size of the section data, as well as its file size and vm
886 if (Sec.isBssSection())
889 SectionDataSize = std::max(SectionDataSize,
Address +
Size);
890 SectionDataFileSize = std::max(SectionDataFileSize,
Address + FileSize);
893 // The section data is padded to pointer size bytes.
895 // FIXME: Is this machine dependent?
896 unsigned SectionDataPadding =
898 SectionDataFileSize += SectionDataPadding;
900 // Write the prolog, starting with the header and load command...
906 SectionDataSize, Prot, Prot);
908 // ... and then the section headers.
909 uint64_t RelocTableEnd = SectionDataStart + SectionDataFileSize;
912 std::vector<RelAndSymbol> &Relocs = Relocations[&Sec];
913 unsigned NumRelocs = Relocs.size();
915 unsigned Flags = Sec.getTypeAndAttributes();
916 if (Sec.hasInstructions())
921 SMLoc(),
"cannot encode offset of section; object file too large");
922 return NumBytesWritten();
924 if (NumRelocs && !
isUInt<32>(RelocTableEnd)) {
927 "cannot encode offset of relocations; object file too large");
928 return NumBytesWritten();
931 RelocTableEnd, NumRelocs);
935 // Write out the deployment target information, if it's available.
936 auto EmitDeploymentTargetVersion =
939 assert(!V.empty() &&
"empty version");
940 unsigned Update = V.getSubminor().value_or(0);
941 unsigned Minor = V.getMinor().value_or(0);
942 assert(Update < 256 &&
"unencodable update target version");
943 assert(Minor < 256 &&
"unencodable minor target version");
944 assert(V.getMajor() < 65536 &&
"unencodable major target version");
945 return Update | (Minor << 8) | (V.getMajor() << 16);
948 VersionInfo.Major, VersionInfo.Minor, VersionInfo.Update));
949 uint32_t SDKVersion = !VersionInfo.SDKVersion.empty()
950 ? EncodeVersion(VersionInfo.SDKVersion)
952 if (VersionInfo.EmitBuildVersion) {
953 // FIXME: Currently empty tools. Add clang version in the future.
954 W.write<
uint32_t>(MachO::LC_BUILD_VERSION);
956 W.write<
uint32_t>(VersionInfo.TypeOrPlatform.Platform);
959 W.write<
uint32_t>(0);
// Empty tools list.
969 if (VersionInfo.Major != 0)
970 EmitDeploymentTargetVersion(VersionInfo);
971 if (TargetVariantVersionInfo.Major != 0)
972 EmitDeploymentTargetVersion(TargetVariantVersionInfo);
974 // Write the data-in-code load command, if used.
975 uint64_t DataInCodeTableEnd = RelocTableEnd + NumDataRegions * 8;
976 if (NumDataRegions) {
977 uint64_t DataRegionsOffset = RelocTableEnd;
978 uint64_t DataRegionsSize = NumDataRegions * 8;
983 // Write the loh load command, if used.
984 uint64_t LOHTableEnd = DataInCodeTableEnd + LOHSize;
987 DataInCodeTableEnd, LOHSize);
989 // Write the symbol table load command, if used.
991 unsigned FirstLocalSymbol = 0;
992 unsigned NumLocalSymbols = LocalSymbolData.size();
993 unsigned FirstExternalSymbol = FirstLocalSymbol + NumLocalSymbols;
994 unsigned NumExternalSymbols = ExternalSymbolData.size();
995 unsigned FirstUndefinedSymbol = FirstExternalSymbol + NumExternalSymbols;
996 unsigned NumUndefinedSymbols = UndefinedSymbolData.size();
997 unsigned NumIndirectSymbols = IndirectSymbols.size();
998 unsigned NumSymTabSymbols =
999 NumLocalSymbols + NumExternalSymbols + NumUndefinedSymbols;
1000 uint64_t IndirectSymbolSize = NumIndirectSymbols * 4;
1003 // If used, the indirect symbols are written after the section data.
1004 if (NumIndirectSymbols)
1005 IndirectSymbolOffset = LOHTableEnd;
1007 // The symbol table is written after the indirect symbol data.
1008 uint64_t SymbolTableOffset = LOHTableEnd + IndirectSymbolSize;
1010 // The string table is written after symbol table.
1012 SymbolTableOffset + NumSymTabSymbols * (
is64Bit() ?
1016 StringTableOffset, StringTable.getSize());
1019 FirstExternalSymbol, NumExternalSymbols,
1020 FirstUndefinedSymbol, NumUndefinedSymbols,
1021 IndirectSymbolOffset, NumIndirectSymbols);
1024 // Write the linker options load commands.
1025 for (
const auto &Option : LinkerOptions)
1028 // Write the actual section data.
1030 Asm.writeSectionData(
W.OS, &Sec);
1033 W.OS.write_zeros(Pad);
1036 // Write the extra padding.
1037 W.OS.write_zeros(SectionDataPadding);
1039 // Write the relocation entries.
1041 // Write the section relocation entries, in reverse order to match 'as'
1042 // (approximately, the exact algorithm is more complicated than this).
1043 std::vector<RelAndSymbol> &Relocs = Relocations[&Sec];
1050 // Write out the data-in-code region payload, if there is one.
1060 <<
" start: " << Start <<
"(" <<
Data.Start->getName()
1061 <<
")" <<
" end: " << End <<
"(" <<
Data.End->getName()
1062 <<
")" <<
" size: " << End - Start <<
"\n");
1068 // Write out the loh commands, if there is one.
1071 unsigned Start =
W.OS.tell();
1073 LOHContainer.emit(
Asm, *
this);
1074 // Pad to a multiple of the pointer size.
1077 assert(
W.OS.tell() - Start == LOHSize);
1080 // Write the symbol table data, if used.
1082 // Write the indirect symbol entries.
1083 for (
auto &
ISD : IndirectSymbols) {
1084 // Indirect symbols in the non-lazy symbol pointer section have some
1085 // special handling.
1089 // If this symbol is defined and internal, mark it as such.
1090 if (
ISD.Symbol->isDefined() && !
ISD.Symbol->isExternal()) {
1092 if (
ISD.Symbol->isAbsolute())
1102 // FIXME: Check that offsets match computed ones.
1104 // Write the symbol table entries.
1105 for (
auto *SymbolData :
1106 {&LocalSymbolData, &ExternalSymbolData, &UndefinedSymbolData})
1107 for (MachSymbolData &Entry : *SymbolData)
1110 // Write the string table.
1111 StringTable.write(
W.OS);
1114 return NumBytesWritten();
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)
static bool isFixupTargetValid(const MCValue &Target)
static MachO::LoadCommandType getLCFromMCVM(MCVersionMinType Type)
static bool isSymbolLinkerVisible(const MCSymbol &Symbol)
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
void computeSectionAddresses(const MCAssembler &Asm)
bool doesSymbolRequireExternRelocation(const MCSymbol &S)
void recordRelocation(const MCFragment &F, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override
Record a relocation entry.
void computeSymbolTable(MCAssembler &Asm, std::vector< MachSymbolData > &LocalSymbolData, std::vector< MachSymbolData > &ExternalSymbolData, std::vector< MachSymbolData > &UndefinedSymbolData)
Compute the symbol table data.
uint64_t writeObject() override
Write the object file and returns the number of bytes written.
uint64_t getFragmentAddress(const MCAssembler &Asm, const MCFragment *Fragment) const
bool isSymbolRefDifferenceFullyResolvedImpl(const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override
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)
void populateAddrSigSection(MCAssembler &Asm)
support::endian::Writer W
void writeLinkerOptionsLoadCommand(const std::vector< std::string > &Options)
void executePostLayoutBinding() override
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
void writeNlist(MachSymbolData &MSD, const MCAssembler &Asm)
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)
const MCSymbol & findAliasedSymbol(const MCSymbol &Sym) const
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.
const MCSymbol * getAtom(const MCSymbol &S) const
void writeLinkeditLoadCommand(uint32_t Type, uint32_t DataOffset, uint32_t DataSize)
void writeHeader(MachO::HeaderFileType Type, unsigned NumLoadCommands, unsigned LoadCommandsSize, bool SubsectionsViaSymbols)
void setAssembler(MCAssembler *Asm) override
void reset() override
lifetime management
void writeSymtabLoadCommand(uint32_t SymbolOffset, uint32_t NumSymbols, uint32_t StringTableOffset, uint32_t StringTableSize)
void bindIndirectSymbols(MCAssembler &Asm)
uint64_t getSymbolAddress(const MCSymbol &S) const
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<X> - 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<X> - 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.