LLVM 20.0.0git
Classes | Public Types | Public Member Functions | Public Attributes | List of all members
llvm::MachObjectWriter Class Referencefinal

#include "llvm/MC/MCMachObjectWriter.h"

Inheritance diagram for llvm::MachObjectWriter:
Inheritance graph
[legend]

Classes

struct  DataRegionData
 

Public Types

using VersionInfoType = { bool EmitBuildVersion
 

Public Member Functions

 MachObjectWriter (std::unique_ptr< MCMachObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian)
 
const MCSymbolfindAliasedSymbol (const MCSymbol &Sym) const
 
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 MCSection &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 (MCAssembler &Asm, const MCFragment *Fragment, 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 (MCAssembler &Asm) override
 Perform any late binding of symbols (for example, to assign symbol indices for use when generating relocations).
 
bool isSymbolRefDifferenceFullyResolvedImpl (const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override
 
void populateAddrSigSection (MCAssembler &Asm)
 
uint64_t writeObject (MCAssembler &Asm) override
 Write the object file and returns the number of bytes written.
 
Lifetime management Methods
void reset () override
 lifetime management
 
Utility Methods
bool isFixupKindPCRel (const MCAssembler &Asm, unsigned Kind)
 
std::vector< IndirectSymbolData > & getIndirectSymbols ()
 
std::vector< DataRegionData > & getDataRegions ()
 
const llvm::SmallVectorImpl< MCSection * > & getSectionOrder () const
 
SectionAddrMapgetSectionAddressMap ()
 
MCLOHContainergetLOHContainer ()
 
uint64_t getSectionAddress (const MCSection *Sec) const
 
uint64_t getSymbolAddress (const MCSymbol &S, const MCAssembler &Asm) 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 ()
 
virtual void reset ()
 lifetime management
 
bool isSymbolRefDifferenceFullyResolved (const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *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 (MCAssembler &Asm, 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

union {
   MCVersionMinType   Type
 Used when EmitBuildVersion==false. More...
 
   MachO::PlatformType   Platform
 Used when EmitBuildVersion==true. More...
 
TypeOrPlatform
 
unsigned Major
 
unsigned Minor
 
unsigned Update
 
VersionTuple SDKVersion
 An optional version of the SDK that was used to build the source.
 
support::endian::Writer W
 

Additional Inherited Members

- Protected Member Functions inherited from llvm::MCObjectWriter
 MCObjectWriter ()=default
 
- Protected Attributes inherited from llvm::MCObjectWriter
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 86 of file MCMachObjectWriter.h.

Member Typedef Documentation

◆ VersionInfoType

using llvm::MachObjectWriter::VersionInfoType = { bool EmitBuildVersion

Definition at line 96 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 175 of file MCMachObjectWriter.h.

Member Function Documentation

◆ addRelocation()

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

Definition at line 325 of file MCMachObjectWriter.h.

References P.

Referenced by populateAddrSigSection().

◆ bindIndirectSymbols()

void MachObjectWriter::bindIndirectSymbols ( MCAssembler Asm)

◆ computeSectionAddresses()

void MachObjectWriter::computeSectionAddresses ( const MCAssembler Asm)

strictly be necessary.

Definition at line 686 of file MachObjectWriter.cpp.

References llvm::alignTo(), getPaddingSize(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().

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 586 of file MachObjectWriter.cpp.

References assert(), llvm::support::endian::Writer::Endian, isSymbolLinkerVisible(), 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 65 of file MachObjectWriter.cpp.

References llvm::MCSymbol::isUndefined().

◆ executePostLayoutBinding()

void MachObjectWriter::executePostLayoutBinding ( MCAssembler Asm)
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 716 of file MachObjectWriter.cpp.

References bindIndirectSymbols(), and computeSectionAddresses().

◆ findAliasedSymbol()

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

◆ getAtom()

const MCSymbol * MachObjectWriter::getAtom ( const MCSymbol S) const

◆ getDataRegions()

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

Definition at line 202 of file MCMachObjectWriter.h.

◆ getFragmentAddress()

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

Definition at line 92 of file MachObjectWriter.cpp.

References llvm::MCFragment::getParent(), and getSectionAddress().

◆ getIndirectSymbols()

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

Definition at line 199 of file MCMachObjectWriter.h.

◆ getLinkerOptions()

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

Definition at line 255 of file MCMachObjectWriter.h.

◆ getLOHContainer()

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

Definition at line 207 of file MCMachObjectWriter.h.

◆ getPaddingSize()

uint64_t MachObjectWriter::getPaddingSize ( const MCAssembler Asm,
const MCSection SD 
) const

◆ getSectionAddress()

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

◆ getSectionAddressMap()

SectionAddrMap & llvm::MachObjectWriter::getSectionAddressMap ( )
inline

Definition at line 206 of file MCMachObjectWriter.h.

◆ getSectionOrder()

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

Definition at line 203 of file MCMachObjectWriter.h.

◆ getSymbolAddress()

uint64_t MachObjectWriter::getSymbolAddress ( const MCSymbol S,
const MCAssembler Asm 
) const

◆ is64Bit()

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

◆ isFixupKindPCRel()

bool MachObjectWriter::isFixupKindPCRel ( const MCAssembler Asm,
unsigned  Kind 
)

◆ isSymbolRefDifferenceFullyResolvedImpl()

bool MachObjectWriter::isSymbolRefDifferenceFullyResolvedImpl ( const MCAssembler Asm,
const MCSymbol SymA,
const MCFragment FB,
bool  InSet,
bool  IsPCRel 
) const
overridevirtual

◆ isX86_64()

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

◆ populateAddrSigSection()

void MachObjectWriter::populateAddrSigSection ( MCAssembler Asm)

◆ recordRelocation()

void MachObjectWriter::recordRelocation ( MCAssembler Asm,
const MCFragment Fragment,
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().

Implements llvm::MCObjectWriter.

Definition at line 515 of file MachObjectWriter.cpp.

References Fixup, and isFixupTargetValid().

◆ reset()

void MachObjectWriter::reset ( )
overridevirtual

◆ setBuildVersion()

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

Definition at line 234 of file MCMachObjectWriter.h.

References Major, Minor, Platform, SDKVersion, and Update.

◆ setTargetVariantBuildVersion()

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

Definition at line 244 of file MCMachObjectWriter.h.

References Major, Minor, Platform, SDKVersion, and Update.

◆ 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 224 of file MCMachObjectWriter.h.

References Major, Minor, SDKVersion, Type, and Update.

◆ 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 
)

◆ writeHeader()

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

◆ writeLinkeditLoadCommand()

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

◆ writeLinkerOptionsLoadCommand()

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

◆ writeNlist()

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

◆ writeObject()

uint64_t MachObjectWriter::writeObject ( MCAssembler Asm)
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 794 of file MachObjectWriter.cpp.

References llvm::Address, llvm::alignTo(), assert(), llvm::MCSection::begin(), llvm::MCObjectWriter::CGProfile, ComputeLinkerOptionsLoadCommandSize(), computeSymbolTable(), llvm::Data, llvm::dbgs(), llvm::MCLOHContainer::emit(), End, llvm::support::endian::Writer::Endian, llvm::MCLOHContainer::getEmitSize(), getLCFromMCVM(), llvm::SectionKind::getMetadata(), getPaddingSize(), getSectionAddress(), getSymbolAddress(), llvm::MachO::INDIRECT_SYMBOL_ABS, llvm::MachO::INDIRECT_SYMBOL_LOCAL, is64Bit(), LLVM_DEBUG, llvm::MachO::MH_OBJECT, Minor, llvm::offsetToAlignment(), llvm::support::endian::Writer::OS, OS, populateAddrSigSection(), llvm::report_fatal_error(), llvm::reverse(), llvm::MachO::S_ATTR_SOME_INSTRUCTIONS, llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS, SDKVersion, Size, llvm::MCObjectWriter::SubsectionsViaSymbols, llvm::raw_ostream::tell(), Update, llvm::MachO::VM_PROT_EXECUTE, llvm::MachO::VM_PROT_READ, llvm::MachO::VM_PROT_WRITE, W, llvm::support::endian::Writer::write(), llvm::support::endian::write(), llvm::raw_ostream::write_zeros(), writeDysymtabLoadCommand(), writeHeader(), writeLinkeditLoadCommand(), writeLinkerOptionsLoadCommand(), writeNlist(), writeSection(), writeSegmentLoadCommand(), and writeSymtabLoadCommand().

◆ writeSection()

void MachObjectWriter::writeSection ( const MCAssembler Asm,
const MCSection Sec,
uint64_t  VMAddr,
uint64_t  FileOffset,
unsigned  Flags,
uint64_t  RelocationsStart,
unsigned  NumRelocations 
)

◆ 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 226 of file MachObjectWriter.cpp.

References assert(), is64Bit(), Name, llvm::support::endian::Writer::OS, llvm::raw_ostream::tell(), W, and llvm::support::endian::Writer::write().

Referenced by writeObject().

◆ writeSymtabLoadCommand()

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

Member Data Documentation

◆ Major

unsigned llvm::MachObjectWriter::Major

◆ Minor

unsigned llvm::MachObjectWriter::Minor

◆ Platform

MachO::PlatformType llvm::MachObjectWriter::Platform

Used when EmitBuildVersion==true.

Definition at line 100 of file MCMachObjectWriter.h.

Referenced by setBuildVersion(), and setTargetVariantBuildVersion().

◆ SDKVersion

VersionTuple llvm::MachObjectWriter::SDKVersion

An optional version of the SDK that was used to build the source.

Definition at line 106 of file MCMachObjectWriter.h.

Referenced by setBuildVersion(), setTargetVariantBuildVersion(), setVersionMin(), and writeObject().

◆ Type

MCVersionMinType llvm::MachObjectWriter::Type

Used when EmitBuildVersion==false.

Definition at line 99 of file MCMachObjectWriter.h.

Referenced by setVersionMin(), writeHeader(), and writeLinkeditLoadCommand().

◆ 

union { ... } llvm::MachObjectWriter::TypeOrPlatform

◆ Update

unsigned llvm::MachObjectWriter::Update

◆ W

support::endian::Writer llvm::MachObjectWriter::W

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