LLVM
8.0.1
|
#include "llvm/MC/MCMachObjectWriter.h"
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. More... | |
void | writeSection (const MCAsmLayout &Layout, 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 MCAsmLayout &Layout) |
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 | recordScatteredRelocation (const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, unsigned Log2Size, uint64_t &FixedValue) |
void | recordTLVPRelocation (const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) |
void | recordRelocation (MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue) override |
Record a relocation entry. More... | |
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. More... | |
void | computeSectionAddresses (const MCAssembler &Asm, const MCAsmLayout &Layout) |
void | executePostLayoutBinding (MCAssembler &Asm, const MCAsmLayout &Layout) override |
Perform any late binding of symbols (for example, to assign symbol indices for use when generating relocations). More... | |
bool | isSymbolRefDifferenceFullyResolvedImpl (const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const override |
bool | isSymbolRefDifferenceFullyResolvedImpl (const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const override |
uint64_t | writeObject (MCAssembler &Asm, const MCAsmLayout &Layout) override |
Write the object file and returns the number of bytes written. More... | |
Lifetime management Methods | |
void | reset () override |
lifetime management More... | |
Utility Methods | |
bool | isFixupKindPCRel (const MCAssembler &Asm, unsigned Kind) |
SectionAddrMap & | getSectionAddressMap () |
uint64_t | getSectionAddress (const MCSection *Sec) const |
uint64_t | getSymbolAddress (const MCSymbol &S, const MCAsmLayout &Layout) const |
uint64_t | getFragmentAddress (const MCFragment *Fragment, const MCAsmLayout &Layout) const |
uint64_t | getPaddingSize (const MCSection *SD, const MCAsmLayout &Layout) const |
bool | doesSymbolRequireExternRelocation (const MCSymbol &S) |
Target Writer Proxy Accessors | |
bool | is64Bit () const |
bool | isX86_64 () const |
Public Member Functions inherited from llvm::MCObjectWriter | |
MCObjectWriter (const MCObjectWriter &)=delete | |
MCObjectWriter & | operator= (const MCObjectWriter &)=delete |
virtual | ~MCObjectWriter () |
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. More... | |
virtual void | emitAddrsigSection () |
Tell the object writer to emit an address-significance table during writeObject(). More... | |
virtual void | addAddrsigSymbol (const MCSymbol *Sym) |
Record the given symbol in the address-significance table to be written diring writeObject(). More... | |
Public Attributes | |
support::endian::Writer | W |
Additional Inherited Members | |
Protected Member Functions inherited from llvm::MCObjectWriter | |
MCObjectWriter ()=default | |
Definition at line 82 of file MCMachObjectWriter.h.
|
inline |
Definition at line 127 of file MCMachObjectWriter.h.
|
inline |
Definition at line 228 of file MCMachObjectWriter.h.
References llvm::HexStyle::Asm, B, llvm::createMachObjectWriter(), Fixup, P, and llvm::MCMachObjectTargetWriter::recordRelocation().
Referenced by canUseLocalRelocation(), getARMFixupKindMachOInfo(), getFixupKindLog2Size(), and getFixupOffset().
void MachObjectWriter::bindIndirectSymbols | ( | MCAssembler & | Asm | ) |
Definition at line 461 of file MachObjectWriter.cpp.
References llvm::MCSymbol::getName(), llvm::MCSectionMachO::getType(), llvm::MCAssembler::indirect_symbol_begin(), llvm::MCAssembler::indirect_symbol_end(), llvm::MCAssembler::registerSymbol(), llvm::report_fatal_error(), llvm::MachO::S_LAZY_SYMBOL_POINTERS, llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS, llvm::MachO::S_SYMBOL_STUBS, llvm::MachO::S_THREAD_LOCAL_VARIABLE_POINTERS, llvm::ARMBuildAttrs::Section, and llvm::ARMBuildAttrs::Symbol.
Referenced by executePostLayoutBinding().
void MachObjectWriter::computeSectionAddresses | ( | const MCAssembler & | Asm, |
const MCAsmLayout & | Layout | ||
) |
strictly be necessary.
Definition at line 626 of file MachObjectWriter.cpp.
References llvm::alignTo(), getPaddingSize(), llvm::MCAsmLayout::getSectionAddressSize(), and llvm::MCAsmLayout::getSectionOrder().
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 525 of file MachObjectWriter.cpp.
References llvm::StringTableBuilder::add(), assert(), llvm::MCAssembler::begin(), llvm::MCAssembler::end(), llvm::support::endian::Writer::Endian, llvm::StringTableBuilder::finalize(), llvm::StringTableBuilder::getOffset(), llvm::MCAssembler::isSymbolLinkerVisible(), llvm::support::little, llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT, BucketT >, KeyT, ValueT, KeyInfoT, BucketT >::lookup(), llvm::ARMBuildAttrs::Section, llvm::sort(), llvm::ARMBuildAttrs::Symbol, llvm::MCAssembler::symbols(), and W.
Referenced by writeObject().
Definition at line 54 of file MachObjectWriter.cpp.
References llvm::MCSymbol::isUndefined(), llvm::operator<(), and llvm::ARMBuildAttrs::Symbol.
Referenced by getARMFixupKindMachOInfo(), getFixupKindLog2Size(), and getFixupOffset().
|
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.
Implements llvm::MCObjectWriter.
Definition at line 641 of file MachObjectWriter.cpp.
References bindIndirectSymbols(), and computeSectionAddresses().
Definition at line 325 of file MachObjectWriter.cpp.
References llvm::dyn_cast(), llvm::MCSymbol::getVariableValue(), llvm::MCSymbol::isVariable(), and llvm::Ref.
Referenced by getFixupKindLog2Size(), isSymbolRefDifferenceFullyResolvedImpl(), and writeNlist().
uint64_t MachObjectWriter::getFragmentAddress | ( | const MCFragment * | Fragment, |
const MCAsmLayout & | Layout | ||
) | const |
Definition at line 80 of file MachObjectWriter.cpp.
References llvm::MCAsmLayout::getFragmentOffset(), llvm::MCFragment::getParent(), and getSectionAddress().
Referenced by canUseLocalRelocation(), and getFixupKindLog2Size().
uint64_t MachObjectWriter::getPaddingSize | ( | const MCSection * | SD, |
const MCAsmLayout & | Layout | ||
) | const |
Definition at line 119 of file MachObjectWriter.cpp.
References llvm::MCSection::getAlignment(), llvm::MCSection::getLayoutOrder(), getSectionAddress(), llvm::MCAsmLayout::getSectionAddressSize(), llvm::MCAsmLayout::getSectionOrder(), llvm::MCSection::isVirtualSection(), and llvm::OffsetToAlignment().
Referenced by computeSectionAddresses(), and writeObject().
Definition at line 150 of file MCMachObjectWriter.h.
References llvm::DenseMapBase< DerivedT, KeyT, ValueT, KeyInfoT, BucketT >::lookup().
Referenced by getARMFixupKindMachOInfo(), getFixupKindLog2Size(), getFixupOffset(), getFragmentAddress(), getPaddingSize(), getSymbolAddress(), and writeObject().
|
inline |
Definition at line 148 of file MCMachObjectWriter.h.
Referenced by getARMFixupKindMachOInfo(), getFixupKindLog2Size(), and getFixupOffset().
uint64_t MachObjectWriter::getSymbolAddress | ( | const MCSymbol & | S, |
const MCAsmLayout & | Layout | ||
) | const |
Definition at line 86 of file MachObjectWriter.cpp.
References llvm::Address, C, llvm::MCExpr::evaluateAsRelocatable(), llvm::MCValue::getConstant(), llvm::MCSymbol::getFragment(), llvm::MCSymbol::getName(), llvm::MCFragment::getParent(), getSectionAddress(), llvm::MCValue::getSymA(), llvm::MCValue::getSymB(), llvm::MCSymbolRefExpr::getSymbol(), llvm::MCAsmLayout::getSymbolOffset(), llvm::MCSymbol::getVariableValue(), llvm::MCSymbol::isUndefined(), llvm::MCSymbol::isVariable(), and llvm::report_fatal_error().
Referenced by canUseLocalRelocation(), getARMFixupKindMachOInfo(), getFixupKindLog2Size(), getFixupOffset(), and writeNlist().
|
inline |
Definition at line 167 of file MCMachObjectWriter.h.
Referenced by writeLinkerOptionsLoadCommand(), writeNlist(), and writeObject().
bool MachObjectWriter::isFixupKindPCRel | ( | const MCAssembler & | Asm, |
unsigned | Kind | ||
) |
Definition at line 73 of file MachObjectWriter.cpp.
References llvm::MCFixupKindInfo::FKF_IsPCRel, llvm::MCFixupKindInfo::Flags, llvm::MCAssembler::getBackend(), and llvm::MCAsmBackend::getFixupKindInfo().
Referenced by canUseLocalRelocation(), getARMFixupKindMachOInfo(), getFixupKindLog2Size(), and getFixupOffset().
|
overridevirtual |
Reimplemented from llvm::MCObjectWriter.
Definition at line 649 of file MachObjectWriter.cpp.
References llvm::MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(), and llvm::MCSymbol::isVariable().
|
overridevirtual |
Reimplemented from llvm::MCObjectWriter.
Definition at line 661 of file MachObjectWriter.cpp.
References findAliasedSymbol(), llvm::MCFragment::getAtom(), llvm::MCSymbol::getFragment(), llvm::MCFragment::getParent(), llvm::MCSymbol::getSection(), llvm::MCAssembler::getSubsectionsViaSymbols(), llvm::MCSymbol::isInSection(), llvm::MCSymbol::isTemporary(), and isX86_64().
|
inline |
Definition at line 168 of file MCMachObjectWriter.h.
References llvm::MachO::CPU_TYPE_X86_64, and Name.
Referenced by isSymbolRefDifferenceFullyResolvedImpl().
|
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 452 of file MachObjectWriter.cpp.
void llvm::MachObjectWriter::recordScatteredRelocation | ( | const MCAssembler & | Asm, |
const MCAsmLayout & | Layout, | ||
const MCFragment * | Fragment, | ||
const MCFixup & | Fixup, | ||
MCValue | Target, | ||
unsigned | Log2Size, | ||
uint64_t & | FixedValue | ||
) |
void llvm::MachObjectWriter::recordTLVPRelocation | ( | const MCAssembler & | Asm, |
const MCAsmLayout & | Layout, | ||
const MCFragment * | Fragment, | ||
const MCFixup & | Fixup, | ||
MCValue | Target, | ||
uint64_t & | FixedValue | ||
) |
|
overridevirtual |
lifetime management
Reimplemented from llvm::MCObjectWriter.
Definition at line 44 of file MachObjectWriter.cpp.
References 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 277 of file MachObjectWriter.cpp.
Referenced by writeObject().
void MachObjectWriter::writeHeader | ( | MachO::HeaderFileType | Type, |
unsigned | NumLoadCommands, | ||
unsigned | LoadCommandsSize, | ||
bool | SubsectionsViaSymbols | ||
) |
Definition at line 132 of file MachObjectWriter.cpp.
References llvm::MachO::MH_SUBSECTIONS_VIA_SYMBOLS.
Referenced by writeObject().
void MachObjectWriter::writeLinkeditLoadCommand | ( | uint32_t | Type, |
uint32_t | DataOffset, | ||
uint32_t | DataSize | ||
) |
Definition at line 406 of file MachObjectWriter.cpp.
Referenced by writeObject().
void MachObjectWriter::writeLinkerOptionsLoadCommand | ( | const std::vector< std::string > & | Options | ) |
Definition at line 429 of file MachObjectWriter.cpp.
References ComputeLinkerOptionsLoadCommandSize(), is64Bit(), and Size.
Referenced by writeObject().
void MachObjectWriter::writeNlist | ( | MachSymbolData & | MSD, |
const MCAsmLayout & | Layout | ||
) |
Definition at line 337 of file MachObjectWriter.cpp.
References llvm::Address, llvm::Data, findAliasedSymbol(), llvm::MCSymbol::getCommonSize(), getSymbolAddress(), if(), is64Bit(), llvm::MCSymbol::isAbsolute(), llvm::MCSymbol::isCommon(), llvm::MCSymbol::isDefined(), llvm::MCSymbol::isExternal(), llvm::MCSymbol::isPrivateExtern(), llvm::MCSymbol::isUndefined(), 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, llvm::ARMBuildAttrs::Symbol, W, and llvm::support::endian::Writer::write().
|
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 738 of file MachObjectWriter.cpp.
References llvm::Address, llvm::alignTo(), assert(), ComputeLinkerOptionsLoadCommandSize(), computeSymbolTable(), llvm::Data, llvm::MCAsmLayout::getAssembler(), llvm::MCAssembler::getDataRegions(), llvm::MCLOHContainer::getEmitSize(), getLCFromMCVM(), llvm::MCAssembler::getLinkerOptions(), llvm::MCAssembler::getLOHContainer(), getPaddingSize(), getSectionAddress(), llvm::MCAsmLayout::getSectionAddressSize(), llvm::MCAsmLayout::getSectionFileSize(), llvm::StringTableBuilder::getSize(), llvm::MCAssembler::getVersionInfo(), is64Bit(), llvm::make_range(), llvm::max(), llvm::MachO::MH_OBJECT, llvm::OffsetToAlignment(), llvm::support::endian::Writer::OS, llvm::MachO::S_ATTR_SOME_INSTRUCTIONS, llvm::ARMBuildAttrs::Section, Size, llvm::MCAssembler::size(), llvm::raw_ostream::tell(), llvm::MachO::VM_PROT_EXECUTE, llvm::MachO::VM_PROT_READ, llvm::MachO::VM_PROT_WRITE, W, llvm::support::endian::Writer::write(), llvm::raw_ostream::write_zeros(), writeDysymtabLoadCommand(), writeHeader(), writeLinkeditLoadCommand(), writeLinkerOptionsLoadCommand(), writeSection(), writeSegmentLoadCommand(), and writeSymtabLoadCommand().
void MachObjectWriter::writeSection | ( | const MCAsmLayout & | Layout, |
const MCSection & | Sec, | ||
uint64_t | VMAddr, | ||
uint64_t | FileOffset, | ||
unsigned | Flags, | ||
uint64_t | RelocationsStart, | ||
unsigned | NumRelocations | ||
) |
Definition at line 213 of file MachObjectWriter.cpp.
References assert(), llvm::MCAsmLayout::getSectionAddressSize(), llvm::MCAsmLayout::getSectionFileSize(), llvm::MCSectionMachO::isVirtualSection(), llvm::ARMBuildAttrs::Section, and llvm::COFF::SectionSize.
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 173 of file MachObjectWriter.cpp.
Referenced by writeObject().
void MachObjectWriter::writeSymtabLoadCommand | ( | uint32_t | SymbolOffset, |
uint32_t | NumSymbols, | ||
uint32_t | StringTableOffset, | ||
uint32_t | StringTableSize | ||
) |
Definition at line 258 of file MachObjectWriter.cpp.
Referenced by writeObject().
support::endian::Writer llvm::MachObjectWriter::W |
Definition at line 132 of file MCMachObjectWriter.h.
Referenced by computeSymbolTable(), llvm::MCLOHDirective::emit(), writeNlist(), and writeObject().