LLVM 22.0.0git
llvm::MachObjectWriter Class Referencefinal

#include "llvm/MC/MCMachObjectWriter.h"

Inheritance diagram for llvm::MachObjectWriter:
[legend]

Classes

struct  DataRegionData

Public Types

using VersionInfoType

Public Member Functions

 MachObjectWriter (std::unique_ptr< MCMachObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
const MCSymbolfindAliasedSymbol (const MCSymbol &Sym) const
void reset () override
 lifetime management
void setAssembler (MCAssembler *Asm) override
void writeHeader (MachO::HeaderFileType Type, unsigned NumLoadCommands, unsigned LoadCommandsSize, bool SubsectionsViaSymbols)
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.
void writeSection (const MCAssembler &Asm, const MCSectionMachO &Sec, uint64_t VMAddr, uint64_t FileOffset, unsigned Flags, uint64_t RelocationsStart, unsigned NumRelocations)
void writeSymtabLoadCommand (uint32_t SymbolOffset, uint32_t NumSymbols, uint32_t StringTableOffset, uint32_t StringTableSize)
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)
void writeNlist (MachSymbolData &MSD, const MCAssembler &Asm)
void writeLinkeditLoadCommand (uint32_t Type, uint32_t DataOffset, uint32_t DataSize)
void writeLinkerOptionsLoadCommand (const std::vector< std::string > &Options)
void addRelocation (const MCSymbol *RelSymbol, const MCSection *Sec, MachO::any_relocation_info &MRE)
void recordRelocation (const MCFragment &F, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override
 Record a relocation entry.
void bindIndirectSymbols (MCAssembler &Asm)
void computeSymbolTable (MCAssembler &Asm, std::vector< MachSymbolData > &LocalSymbolData, std::vector< MachSymbolData > &ExternalSymbolData, std::vector< MachSymbolData > &UndefinedSymbolData)
 Compute the symbol table data.
void computeSectionAddresses (const MCAssembler &Asm)
void executePostLayoutBinding () override
 Perform any late binding of symbols (for example, to assign symbol indices for use when generating relocations).
bool isSymbolRefDifferenceFullyResolvedImpl (const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override
void populateAddrSigSection (MCAssembler &Asm)
uint64_t writeObject () override
 Write the object file and returns the number of bytes written.
Utility Methods
std::vector< IndirectSymbolData > & getIndirectSymbols ()
std::vector< DataRegionData > & getDataRegions ()
const llvm::SmallVectorImpl< MCSection * > & getSectionOrder () const
MCLOHContainergetLOHContainer ()
uint64_t getSectionAddress (const MCSection *Sec) const
uint64_t getSymbolAddress (const MCSymbol &S) const
uint64_t getFragmentAddress (const MCAssembler &Asm, const MCFragment *Fragment) const
uint64_t getPaddingSize (const MCAssembler &Asm, const MCSection *SD) const
const MCSymbolgetAtom (const MCSymbol &S) const
bool doesSymbolRequireExternRelocation (const MCSymbol &S)
void setVersionMin (MCVersionMinType Type, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion=VersionTuple())
 Mach-O deployment target version information.
void setBuildVersion (MachO::PlatformType Platform, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion=VersionTuple())
void setTargetVariantBuildVersion (MachO::PlatformType Platform, unsigned Major, unsigned Minor, unsigned Update, VersionTuple SDKVersion)
std::vector< std::vector< std::string > > & getLinkerOptions ()
Target Writer Proxy Accessors
bool is64Bit () const
bool isX86_64 () const
Public Member Functions inherited from llvm::MCObjectWriter
 MCObjectWriter (const MCObjectWriter &)=delete
MCObjectWriteroperator= (const MCObjectWriter &)=delete
virtual ~MCObjectWriter ()
MCContextgetContext () const
bool isSymbolRefDifferenceFullyResolved (const MCSymbol &A, const MCSymbol &B, bool InSet) const
 Check whether the difference (A - B) between two symbol references is fully resolved.
MutableArrayRef< std::pair< std::string, size_t > > getFileNames ()
void addFileName (StringRef FileName)
void setCompilerVersion (StringRef CompilerVers)
void emitAddrsigSection ()
 Tell the object writer to emit an address-significance table during writeObject().
bool getEmitAddrsigSection ()
void addAddrsigSymbol (const MCSymbol *Sym)
 Record the given symbol in the address-significance table to be written diring writeObject().
std::vector< const MCSymbol * > & getAddrsigSyms ()
SmallVector< CGProfileEntry, 0 > & getCGProfile ()
bool getSubsectionsViaSymbols () const
void setSubsectionsViaSymbols (bool Value)

Public Attributes

support::endian::Writer W

Additional Inherited Members

Protected Member Functions inherited from llvm::MCObjectWriter
 MCObjectWriter ()=default
Protected Attributes inherited from llvm::MCObjectWriter
MCAssemblerAsm = nullptr
SmallVector< std::pair< std::string, size_t >, 0 > FileNames
 List of declared file names.
std::string CompilerVersion
std::vector< const MCSymbol * > AddrsigSyms
bool EmitAddrsigSection = false
bool SubsectionsViaSymbols = false
SmallVector< CGProfileEntry, 0 > CGProfile

Detailed Description

Definition at line 88 of file MCMachObjectWriter.h.

Member Typedef Documentation

◆ VersionInfoType

Initial value:
struct {
bool EmitBuildVersion;
union {
} TypeOrPlatform;
unsigned Major;
unsigned Minor;
unsigned Update;
VersionTuple SDKVersion;
}
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
Represents a version number in the form major[.minor[.subminor[.build]]].
MCVersionMinType

Definition at line 98 of file MCMachObjectWriter.h.

Constructor & Destructor Documentation

◆ MachObjectWriter()

llvm::MachObjectWriter::MachObjectWriter ( std::unique_ptr< MCMachObjectTargetWriter > MOTW,
raw_pwrite_stream & OS,
bool IsLittleEndian )
inline

Definition at line 177 of file MCMachObjectWriter.h.

References llvm::big, is64Bit(), llvm::little, llvm::move(), and W.

Member Function Documentation

◆ addRelocation()

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

Definition at line 320 of file MCMachObjectWriter.h.

References P.

Referenced by populateAddrSigSection().

◆ bindIndirectSymbols()

◆ computeSectionAddresses()

void MachObjectWriter::computeSectionAddresses ( const MCAssembler & Asm)

strictly be necessary.

Definition at line 681 of file MachObjectWriter.cpp.

References llvm::alignTo(), llvm::MCObjectWriter::Asm, and getPaddingSize().

Referenced by executePostLayoutBinding().

◆ computeSymbolTable()

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

Compute the symbol table data.

computeSymbolTable - Compute the symbol table data

Definition at line 579 of file MachObjectWriter.cpp.

References llvm::MCObjectWriter::Asm, assert(), llvm::isInt(), isSymbolLinkerVisible(), llvm::MCSymbol::isUndefined(), llvm::little, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::sort(), and W.

Referenced by writeObject().

◆ doesSymbolRequireExternRelocation()

bool MachObjectWriter::doesSymbolRequireExternRelocation ( const MCSymbol & S)

Definition at line 68 of file MachObjectWriter.cpp.

References llvm::MCSymbol::isUndefined().

◆ executePostLayoutBinding()

void MachObjectWriter::executePostLayoutBinding ( )
overridevirtual

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

This routine is called by the assembler after layout and relaxation is complete.

Reimplemented from llvm::MCObjectWriter.

Definition at line 711 of file MachObjectWriter.cpp.

References llvm::MCObjectWriter::Asm, bindIndirectSymbols(), and computeSectionAddresses().

◆ findAliasedSymbol()

const MCSymbol & MachObjectWriter::findAliasedSymbol ( const MCSymbol & Sym) const

◆ getAtom()

◆ getDataRegions()

std::vector< DataRegionData > & llvm::MachObjectWriter::getDataRegions ( )
inline

Definition at line 198 of file MCMachObjectWriter.h.

◆ getFragmentAddress()

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

Definition at line 88 of file MachObjectWriter.cpp.

References llvm::MCObjectWriter::Asm, and getSectionAddress().

◆ getIndirectSymbols()

std::vector< IndirectSymbolData > & llvm::MachObjectWriter::getIndirectSymbols ( )
inline

Definition at line 195 of file MCMachObjectWriter.h.

◆ getLinkerOptions()

std::vector< std::vector< std::string > > & llvm::MachObjectWriter::getLinkerOptions ( )
inline

Definition at line 250 of file MCMachObjectWriter.h.

◆ getLOHContainer()

MCLOHContainer & llvm::MachObjectWriter::getLOHContainer ( )
inline

Definition at line 202 of file MCMachObjectWriter.h.

◆ getPaddingSize()

◆ getSectionAddress()

uint64_t llvm::MachObjectWriter::getSectionAddress ( const MCSection * Sec) const
inline

◆ getSectionOrder()

const llvm::SmallVectorImpl< MCSection * > & llvm::MachObjectWriter::getSectionOrder ( ) const
inline

Definition at line 199 of file MCMachObjectWriter.h.

◆ getSymbolAddress()

◆ is64Bit()

◆ isSymbolRefDifferenceFullyResolvedImpl()

◆ isX86_64()

bool llvm::MachObjectWriter::isX86_64 ( ) const
inline

◆ populateAddrSigSection()

◆ recordRelocation()

void MachObjectWriter::recordRelocation ( const MCFragment & F,
const MCFixup & Fixup,
MCValue Target,
uint64_t & FixedValue )
overridevirtual

Record a relocation entry.

This routine is called by the assembler after layout and relaxation, and post layout binding. The implementation is responsible for storing information about the relocation so that it can be emitted during writeObject().

Reimplemented from llvm::MCObjectWriter.

Definition at line 508 of file MachObjectWriter.cpp.

References llvm::MCObjectWriter::Asm, F, Fixup, llvm::MCObjectWriter::getContext(), isFixupTargetValid(), and llvm::MCContext::reportError().

◆ reset()

void MachObjectWriter::reset ( )
overridevirtual

lifetime management

Reimplemented from llvm::MCObjectWriter.

Definition at line 43 of file MachObjectWriter.cpp.

References llvm::MCObjectWriter::reset().

◆ setAssembler()

void MachObjectWriter::setAssembler ( MCAssembler * Asm)
overridevirtual

Reimplemented from llvm::MCObjectWriter.

Definition at line 63 of file MachObjectWriter.cpp.

References llvm::MCObjectWriter::Asm, and llvm::MCObjectWriter::setAssembler().

◆ setBuildVersion()

void llvm::MachObjectWriter::setBuildVersion ( MachO::PlatformType Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
VersionTuple SDKVersion = VersionTuple() )
inline

Definition at line 229 of file MCMachObjectWriter.h.

◆ setTargetVariantBuildVersion()

void llvm::MachObjectWriter::setTargetVariantBuildVersion ( MachO::PlatformType Platform,
unsigned Major,
unsigned Minor,
unsigned Update,
VersionTuple SDKVersion )
inline

Definition at line 239 of file MCMachObjectWriter.h.

◆ setVersionMin()

void llvm::MachObjectWriter::setVersionMin ( MCVersionMinType Type,
unsigned Major,
unsigned Minor,
unsigned Update,
VersionTuple SDKVersion = VersionTuple() )
inline

Mach-O deployment target version information.

Definition at line 219 of file MCMachObjectWriter.h.

◆ writeDysymtabLoadCommand()

void MachObjectWriter::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 at line 325 of file MachObjectWriter.cpp.

References assert(), and W.

Referenced by writeObject().

◆ writeHeader()

◆ writeLinkeditLoadCommand()

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

Definition at line 453 of file MachObjectWriter.cpp.

References assert(), llvm::DataSize, and W.

Referenced by writeObject().

◆ writeLinkerOptionsLoadCommand()

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

◆ writeNlist()

◆ writeObject()

uint64_t MachObjectWriter::writeObject ( )
overridevirtual

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

This routine is called by the assembler after layout and relaxation is complete, fixups have been evaluated and applied, and relocations generated.

Implements llvm::MCObjectWriter.

Definition at line 789 of file MachObjectWriter.cpp.

References llvm::Address, llvm::alignTo(), llvm::MCObjectWriter::Asm, assert(), llvm::cast(), llvm::MCObjectWriter::CGProfile, ComputeLinkerOptionsLoadCommandSize(), computeSymbolTable(), llvm::copy(), llvm::MCSection::curFragList(), llvm::Data, llvm::MutableArrayRef< T >::data(), llvm::dbgs(), llvm::MCObjectWriter::getContext(), getLCFromMCVM(), llvm::MCContext::getMachOSection(), llvm::SectionKind::getMetadata(), getPaddingSize(), getSectionAddress(), getSymbolAddress(), llvm::MCFragment::getVarContents(), llvm::MCSection::FragList::Head, llvm::MachO::INDIRECT_SYMBOL_ABS, llvm::MachO::INDIRECT_SYMBOL_LOCAL, is64Bit(), llvm::isUInt(), LLVM_DEBUG, llvm::MachO::MH_OBJECT, llvm::offsetToAlignment(), populateAddrSigSection(), llvm::report_fatal_error(), llvm::MCContext::reportError(), llvm::reverse(), llvm::MachO::S_ATTR_SOME_INSTRUCTIONS, llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS, Size, llvm::raw_svector_ostream::str(), llvm::MCObjectWriter::SubsectionsViaSymbols, llvm::MachO::VM_PROT_EXECUTE, llvm::MachO::VM_PROT_READ, llvm::MachO::VM_PROT_WRITE, W, llvm::support::endian::write(), writeDysymtabLoadCommand(), writeHeader(), writeLinkeditLoadCommand(), writeLinkerOptionsLoadCommand(), writeNlist(), writeSection(), writeSegmentLoadCommand(), and writeSymtabLoadCommand().

◆ writeSection()

◆ writeSegmentLoadCommand()

void MachObjectWriter::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.

writeSegmentLoadCommand - Write a segment load command.

Parameters
NumSectionsThe number of sections in this segment.
SectionDataSizeThe total size of the sections.

Definition at line 222 of file MachObjectWriter.cpp.

References assert(), is64Bit(), and W.

Referenced by writeObject().

◆ writeSymtabLoadCommand()

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

Definition at line 306 of file MachObjectWriter.cpp.

References assert(), and W.

Referenced by writeObject().

Member Data Documentation

◆ W


The documentation for this class was generated from the following files: