LLVM 19.0.0git
|
#include "llvm/MC/MCMachObjectWriter.h"
Classes | |
struct | DataRegionData |
Public Member Functions | |
MachObjectWriter (std::unique_ptr< MCMachObjectTargetWriter > MOTW, raw_pwrite_stream &OS, bool IsLittleEndian) | |
const MCSymbol & | findAliasedSymbol (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 |
SectionAddrMap & | getSectionAddressMap () |
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 MCSymbol * | getAtom (const MCSymbol &S) const |
bool | doesSymbolRequireExternRelocation (const MCSymbol &S) |
Target Writer Proxy Accessors | |
bool | is64Bit () const |
bool | isX86_64 () const |
![]() | |
MCObjectWriter (const MCObjectWriter &)=delete | |
MCObjectWriter & | operator= (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. | |
virtual void | markGnuAbi () |
ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN). | |
virtual void | setOverrideABIVersion (uint8_t ABIVersion) |
ELF only, override the default ABIVersion in the ELF header. | |
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 () |
virtual void | addExceptionEntry (const MCSymbol *Symbol, const MCSymbol *Trap, unsigned LanguageCode, unsigned ReasonCode, unsigned FunctionSize, bool hasDebug) |
virtual void | addCInfoSymEntry (StringRef Name, StringRef Metadata) |
Public Attributes | |
support::endian::Writer | W |
Additional Inherited Members | |
![]() | |
MCObjectWriter ()=default | |
![]() | |
std::vector< const MCSymbol * > | AddrsigSyms |
bool | EmitAddrsigSection = false |
Definition at line 83 of file MCMachObjectWriter.h.
|
inline |
Definition at line 148 of file MCMachObjectWriter.h.
|
inline |
Definition at line 261 of file MCMachObjectWriter.h.
References P.
Referenced by populateAddrSigSection().
void MachObjectWriter::bindIndirectSymbols | ( | MCAssembler & | Asm | ) |
Definition at line 511 of file MachObjectWriter.cpp.
References llvm::enumerate(), llvm::report_fatal_error(), llvm::MachO::S_LAZY_SYMBOL_POINTERS, llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS, llvm::MachO::S_SYMBOL_STUBS, and llvm::MachO::S_THREAD_LOCAL_VARIABLE_POINTERS.
Referenced by executePostLayoutBinding().
void MachObjectWriter::computeSectionAddresses | ( | const MCAssembler & | Asm | ) |
strictly be necessary.
Definition at line 668 of file MachObjectWriter.cpp.
References llvm::alignTo(), getPaddingSize(), and llvm::SmallVectorTemplateBase< T, bool >::push_back().
Referenced by executePostLayoutBinding().
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 568 of file MachObjectWriter.cpp.
References llvm::StringTableBuilder::add(), assert(), llvm::support::endian::Writer::Endian, llvm::StringTableBuilder::finalize(), llvm::StringTableBuilder::getOffset(), isSymbolLinkerVisible(), llvm::little, llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::sort(), and W.
Referenced by writeObject().
Definition at line 61 of file MachObjectWriter.cpp.
References llvm::MCSymbol::isUndefined().
|
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 698 of file MachObjectWriter.cpp.
References bindIndirectSymbols(), and computeSectionAddresses().
Definition at line 362 of file MachObjectWriter.cpp.
References llvm::MCSymbol::getVariableValue(), llvm::MCSymbol::isVariable(), llvm::Ref, and Sym.
Referenced by isSymbolRefDifferenceFullyResolvedImpl(), and writeNlist().
Definition at line 151 of file MachObjectWriter.cpp.
References llvm::MCFragment::getAtom(), llvm::MCSymbol::getFragment(), llvm::MCFragment::getParent(), llvm::MCSymbol::isInSection(), llvm::MCAsmInfoDarwin::isSectionAtomizableBySymbols(), and isSymbolLinkerVisible().
|
inline |
Definition at line 175 of file MCMachObjectWriter.h.
uint64_t MachObjectWriter::getFragmentAddress | ( | const MCAssembler & | Asm, |
const MCFragment * | Fragment | ||
) | const |
Definition at line 88 of file MachObjectWriter.cpp.
References llvm::MCFragment::getParent(), and getSectionAddress().
|
inline |
Definition at line 172 of file MCMachObjectWriter.h.
uint64_t MachObjectWriter::getPaddingSize | ( | const MCAssembler & | Asm, |
const MCSection * | SD | ||
) | const |
Definition at line 127 of file MachObjectWriter.cpp.
References llvm::MCSection::getAlign(), getSectionAddress(), llvm::MCSection::isVirtualSection(), llvm::offsetToAlignment(), and llvm::SmallVectorBase< Size_T >::size().
Referenced by computeSectionAddresses(), and writeObject().
Definition at line 181 of file MCMachObjectWriter.h.
Referenced by getFragmentAddress(), getPaddingSize(), getSymbolAddress(), and writeObject().
|
inline |
Definition at line 179 of file MCMachObjectWriter.h.
|
inline |
Definition at line 176 of file MCMachObjectWriter.h.
uint64_t MachObjectWriter::getSymbolAddress | ( | const MCSymbol & | S, |
const MCAssembler & | Asm | ||
) | const |
Definition at line 94 of file MachObjectWriter.cpp.
References llvm::Address, llvm::CallingConv::C, llvm::MCExpr::evaluateAsRelocatable(), llvm::MCSymbol::getFragment(), llvm::MCSymbol::getName(), llvm::Target::getName(), llvm::MCFragment::getParent(), getSectionAddress(), getSymbolAddress(), llvm::MCSymbol::getVariableValue(), llvm::MCSymbol::isVariable(), and llvm::report_fatal_error().
Referenced by getSymbolAddress(), writeNlist(), and writeObject().
|
inline |
Definition at line 200 of file MCMachObjectWriter.h.
Referenced by populateAddrSigSection(), writeHeader(), writeLinkerOptionsLoadCommand(), writeNlist(), writeObject(), writeSection(), and writeSegmentLoadCommand().
bool MachObjectWriter::isFixupKindPCRel | ( | const MCAssembler & | Asm, |
unsigned | Kind | ||
) |
Definition at line 80 of file MachObjectWriter.cpp.
References llvm::MCFixupKindInfo::FKF_IsPCRel, and llvm::MCFixupKindInfo::Flags.
|
overridevirtual |
Reimplemented from llvm::MCObjectWriter.
Definition at line 705 of file MachObjectWriter.cpp.
References findAliasedSymbol(), llvm::MCFragment::getAtom(), llvm::MCSymbol::getFragment(), llvm::MCFragment::getParent(), llvm::MCSymbol::getSection(), llvm::MCSymbol::isInSection(), llvm::MCSymbol::isTemporary(), and isX86_64().
|
inline |
Definition at line 201 of file MCMachObjectWriter.h.
References llvm::MachO::CPU_TYPE_X86_64.
Referenced by isSymbolRefDifferenceFullyResolvedImpl().
void MachObjectWriter::populateAddrSigSection | ( | MCAssembler & | Asm | ) |
Definition at line 762 of file MachObjectWriter.cpp.
References addRelocation(), llvm::MachO::GENERIC_RELOC_VANILLA, llvm::MCObjectWriter::getAddrsigSyms(), is64Bit(), llvm::MachO::any_relocation_info::r_word0, and llvm::MachO::any_relocation_info::r_word1.
Referenced by writeObject().
|
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 497 of file MachObjectWriter.cpp.
References Fixup, and isFixupTargetValid().
|
overridevirtual |
lifetime management
Reimplemented from llvm::MCObjectWriter.
Definition at line 47 of file MachObjectWriter.cpp.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::clear(), llvm::SmallVectorImpl< T >::clear(), llvm::StringTableBuilder::clear(), and llvm::MCObjectWriter::reset().
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 314 of file MachObjectWriter.cpp.
References assert(), llvm::support::endian::Writer::OS, llvm::raw_ostream::tell(), W, and llvm::support::endian::Writer::write().
Referenced by writeObject().
void MachObjectWriter::writeHeader | ( | MachO::HeaderFileType | Type, |
unsigned | NumLoadCommands, | ||
unsigned | LoadCommandsSize, | ||
bool | SubsectionsViaSymbols | ||
) |
Definition at line 170 of file MachObjectWriter.cpp.
References assert(), is64Bit(), llvm::MachO::MH_MAGIC, llvm::MachO::MH_MAGIC_64, llvm::MachO::MH_SUBSECTIONS_VIA_SYMBOLS, llvm::support::endian::Writer::OS, llvm::raw_ostream::tell(), W, and llvm::support::endian::Writer::write().
Referenced by writeObject().
void MachObjectWriter::writeLinkeditLoadCommand | ( | uint32_t | Type, |
uint32_t | DataOffset, | ||
uint32_t | DataSize | ||
) |
Definition at line 442 of file MachObjectWriter.cpp.
References assert(), llvm::support::endian::Writer::OS, llvm::raw_ostream::tell(), W, and llvm::support::endian::Writer::write().
Referenced by writeObject().
void MachObjectWriter::writeLinkerOptionsLoadCommand | ( | const std::vector< std::string > & | Options | ) |
Definition at line 465 of file MachObjectWriter.cpp.
References assert(), ComputeLinkerOptionsLoadCommandSize(), is64Bit(), llvm::offsetToAlignment(), Options, llvm::support::endian::Writer::OS, Size, llvm::raw_ostream::tell(), W, llvm::support::endian::Writer::write(), and llvm::raw_ostream::write_zeros().
Referenced by writeObject().
void MachObjectWriter::writeNlist | ( | MachSymbolData & | MSD, |
const MCAssembler & | Asm | ||
) |
Definition at line 374 of file MachObjectWriter.cpp.
References llvm::Address, llvm::Data, findAliasedSymbol(), getSymbolAddress(), is64Bit(), llvm::MachO::N_ABS, llvm::MachO::N_EXT, llvm::MachO::N_INDR, llvm::MachO::N_PEXT, llvm::MachO::N_SECT, llvm::MachO::N_UNDF, llvm::support::endian::Writer::OS, W, and llvm::support::endian::Writer::write().
Referenced by 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 776 of file MachObjectWriter.cpp.
References llvm::Address, llvm::alignTo(), assert(), llvm::MCSection::begin(), ComputeLinkerOptionsLoadCommandSize(), computeSymbolTable(), llvm::MCAssembler::CGProfileEntry::Count, llvm::Data, llvm::dbgs(), End, llvm::support::endian::Writer::Endian, llvm::MCAssembler::CGProfileEntry::From, llvm::MCSymbol::getIndex(), getLCFromMCVM(), llvm::SectionKind::getMetadata(), getPaddingSize(), getSectionAddress(), llvm::StringTableBuilder::getSize(), llvm::MCSymbolRefExpr::getSymbol(), getSymbolAddress(), llvm::MachO::INDIRECT_SYMBOL_ABS, llvm::MachO::INDIRECT_SYMBOL_LOCAL, is64Bit(), LLVM_DEBUG, llvm::MachO::MH_OBJECT, 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, Size, llvm::raw_ostream::tell(), llvm::MCAssembler::CGProfileEntry::To, llvm::MachO::VM_PROT_EXECUTE, llvm::MachO::VM_PROT_READ, llvm::MachO::VM_PROT_WRITE, W, llvm::support::endian::Writer::write(), llvm::StringTableBuilder::write(), llvm::support::endian::write(), llvm::raw_ostream::write_zeros(), writeDysymtabLoadCommand(), writeHeader(), writeLinkeditLoadCommand(), writeLinkerOptionsLoadCommand(), writeNlist(), writeSection(), writeSegmentLoadCommand(), and writeSymtabLoadCommand().
void MachObjectWriter::writeSection | ( | const MCAssembler & | Asm, |
const MCSection & | Sec, | ||
uint64_t | VMAddr, | ||
uint64_t | FileOffset, | ||
unsigned | Flags, | ||
uint64_t | RelocationsStart, | ||
unsigned | NumRelocations | ||
) |
Definition at line 251 of file MachObjectWriter.cpp.
References assert(), is64Bit(), llvm::Log2(), llvm::support::endian::Writer::OS, llvm::raw_ostream::tell(), W, and llvm::support::endian::Writer::write().
Referenced by writeObject().
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.
NumSections | The number of sections in this segment. |
SectionDataSize | The total size of the sections. |
Definition at line 211 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().
void MachObjectWriter::writeSymtabLoadCommand | ( | uint32_t | SymbolOffset, |
uint32_t | NumSymbols, | ||
uint32_t | StringTableOffset, | ||
uint32_t | StringTableSize | ||
) |
Definition at line 295 of file MachObjectWriter.cpp.
References assert(), llvm::support::endian::Writer::OS, llvm::raw_ostream::tell(), W, and llvm::support::endian::Writer::write().
Referenced by writeObject().
support::endian::Writer llvm::MachObjectWriter::W |
Definition at line 156 of file MCMachObjectWriter.h.
Referenced by computeSymbolTable(), llvm::MCLOHDirective::emit(), writeDysymtabLoadCommand(), writeHeader(), writeLinkeditLoadCommand(), writeLinkerOptionsLoadCommand(), writeNlist(), writeObject(), writeSection(), writeSegmentLoadCommand(), and writeSymtabLoadCommand().