LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Member Functions | List of all members
llvm::MachObjectWriter Class Reference

#include <MCMachObjectWriter.h>

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

Public Member Functions

 MachObjectWriter (MCMachObjectTargetWriter *MOTW, raw_ostream &_OS, bool _IsLittleEndian)
 
void WriteHeader (unsigned NumLoadCommands, unsigned LoadCommandsSize, bool SubsectionsViaSymbols)
 
void WriteSegmentLoadCommand (unsigned NumSections, uint64_t VMSize, uint64_t SectionDataStartOffset, uint64_t SectionDataSize)
 
void WriteSection (const MCAssembler &Asm, const MCAsmLayout &Layout, const MCSectionData &SD, uint64_t FileOffset, 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 MCSectionData *SD, 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 (const MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)
 Record a relocation entry. More...
 
void BindIndirectSymbols (MCAssembler &Asm)
 
void ComputeSymbolTable (MCAssembler &Asm, SmallString< 256 > &StringTable, std::vector< MachSymbolData > &LocalSymbolData, std::vector< MachSymbolData > &ExternalSymbolData, std::vector< MachSymbolData > &UndefinedSymbolData)
 
void computeSectionAddresses (const MCAssembler &Asm, const MCAsmLayout &Layout)
 
void markAbsoluteVariableSymbols (MCAssembler &Asm, const MCAsmLayout &Layout)
 
void ExecutePostLayoutBinding (MCAssembler &Asm, const MCAsmLayout &Layout)
 Perform any late binding of symbols (for example, to assign symbol indices for use when generating relocations). More...
 
virtual bool IsSymbolRefDifferenceFullyResolvedImpl (const MCAssembler &Asm, const MCSymbolData &DataA, const MCFragment &FB, bool InSet, bool IsPCRel) const
 
void WriteObject (MCAssembler &Asm, const MCAsmLayout &Layout)
 Write the object file. More...
 
Lifetime management Methods
virtual void reset ()
 lifetime management More...
 
Target Writer Proxy Accessors
bool is64Bit () const
 
bool isARM () const
 
- Public Member Functions inherited from llvm::MCObjectWriter
virtual ~MCObjectWriter ()
 
bool isLittleEndian () const
 
raw_ostreamgetStream ()
 
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...
 
void Write8 (uint8_t Value)
 
void WriteLE16 (uint16_t Value)
 
void WriteLE32 (uint32_t Value)
 
void WriteLE64 (uint64_t Value)
 
void WriteBE16 (uint16_t Value)
 
void WriteBE32 (uint32_t Value)
 
void WriteBE64 (uint64_t Value)
 
void Write16 (uint16_t Value)
 
void Write32 (uint32_t Value)
 
void Write64 (uint64_t Value)
 
void WriteZeros (unsigned N)
 
void WriteBytes (const SmallVectorImpl< char > &ByteVec, unsigned ZeroFillSize=0)
 
void WriteBytes (StringRef Str, unsigned ZeroFillSize=0)
 

Utility Methods

SectionAddrMap SectionAddress
 
bool isFixupKindPCRel (const MCAssembler &Asm, unsigned Kind)
 
SectionAddrMapgetSectionAddressMap ()
 
uint64_t getSectionAddress (const MCSectionData *SD) const
 
uint64_t getSymbolAddress (const MCSymbolData *SD, const MCAsmLayout &Layout) const
 
uint64_t getFragmentAddress (const MCFragment *Fragment, const MCAsmLayout &Layout) const
 
uint64_t getPaddingSize (const MCSectionData *SD, const MCAsmLayout &Layout) const
 
bool doesSymbolRequireExternRelocation (const MCSymbolData *SD)
 

Additional Inherited Members

- Protected Member Functions inherited from llvm::MCObjectWriter
 MCObjectWriter (raw_ostream &_OS, bool _IsLittleEndian)
 
- Protected Attributes inherited from llvm::MCObjectWriter
raw_ostreamOS
 
unsigned IsLittleEndian: 1
 

Detailed Description

Definition at line 82 of file MCMachObjectWriter.h.

Constructor & Destructor Documentation

llvm::MachObjectWriter::MachObjectWriter ( MCMachObjectTargetWriter MOTW,
raw_ostream _OS,
bool  _IsLittleEndian 
)
inline

Definition at line 116 of file MCMachObjectWriter.h.

Member Function Documentation

void llvm::MachObjectWriter::addRelocation ( const MCSectionData SD,
MachO::any_relocation_info MRE 
)
inline

Definition at line 214 of file MCMachObjectWriter.h.

void MachObjectWriter::BindIndirectSymbols ( MCAssembler Asm)
void MachObjectWriter::computeSectionAddresses ( const MCAssembler Asm,
const MCAsmLayout Layout 
)
void MachObjectWriter::ComputeSymbolTable ( MCAssembler Asm,
SmallString< 256 > &  StringTable,
std::vector< MachSymbolData > &  LocalSymbolData,
std::vector< MachSymbolData > &  ExternalSymbolData,
std::vector< MachSymbolData > &  UndefinedSymbolData 
)

ComputeSymbolTable - Compute the symbol table data

Parameters
StringTable[out] - The string table data.

ComputeSymbolTable - Compute the symbol table data

Parameters
StringTable[out] - The string table data.
StringIndexMap[out] - Map from symbol names to offsets in the string table.

Definition at line 495 of file MachObjectWriter.cpp.

References llvm::MCAssembler::begin(), llvm::MCAssembler::end(), llvm::MCSymbol::getName(), llvm::MCSymbol::getSection(), llvm::MCSymbol::isAbsolute(), llvm::MCAssembler::isSymbolLinkerVisible(), llvm::MCSymbol::isUndefined(), llvm::DenseMapBase< DenseMap< KeyT, ValueT, KeyInfoT >, KeyT, ValueT, KeyInfoT >::lookup(), llvm::SmallVectorTemplateBase< T, isPodLike >::push_back(), llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::ARMBuildAttrs::Symbol, llvm::MCAssembler::symbol_begin(), and llvm::MCAssembler::symbol_end().

Referenced by ExecutePostLayoutBinding().

bool MachObjectWriter::doesSymbolRequireExternRelocation ( const MCSymbolData SD)
void MachObjectWriter::ExecutePostLayoutBinding ( MCAssembler Asm,
const MCAsmLayout Layout 
)
virtual

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(), computeSectionAddresses(), ComputeSymbolTable(), and markAbsoluteVariableSymbols().

uint64_t MachObjectWriter::getFragmentAddress ( const MCFragment Fragment,
const MCAsmLayout Layout 
) const
uint64_t MachObjectWriter::getPaddingSize ( const MCSectionData SD,
const MCAsmLayout Layout 
) const
uint64_t llvm::MachObjectWriter::getSectionAddress ( const MCSectionData SD) const
inline
SectionAddrMap& llvm::MachObjectWriter::getSectionAddressMap ( )
inline

Definition at line 135 of file MCMachObjectWriter.h.

References SectionAddress.

uint64_t MachObjectWriter::getSymbolAddress ( const MCSymbolData SD,
const MCAsmLayout Layout 
) const
bool llvm::MachObjectWriter::is64Bit ( ) const
inline
bool llvm::MachObjectWriter::isARM ( ) const
inline

Definition at line 157 of file MCMachObjectWriter.h.

References llvm::MachO::CPU_TYPE_ARM.

bool MachObjectWriter::isFixupKindPCRel ( const MCAssembler Asm,
unsigned  Kind 
)
bool MachObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl ( const MCAssembler Asm,
const MCSymbolData DataA,
const MCFragment FB,
bool  InSet,
bool  IsPCRel 
) const
virtual
void MachObjectWriter::markAbsoluteVariableSymbols ( MCAssembler Asm,
const MCAsmLayout Layout 
)
void MachObjectWriter::RecordRelocation ( const MCAssembler Asm,
const MCAsmLayout Layout,
const MCFragment Fragment,
const MCFixup Fixup,
MCValue  Target,
uint64_t &  FixedValue 
)
virtual

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 415 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 
)
void MachObjectWriter::reset ( )
virtual

lifetime management

Reimplemented from llvm::MCObjectWriter.

Definition at line 29 of file MachObjectWriter.cpp.

References llvm::SmallVectorImpl< T >::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 
)
void MachObjectWriter::WriteHeader ( unsigned  NumLoadCommands,
unsigned  LoadCommandsSize,
bool  SubsectionsViaSymbols 
)
void MachObjectWriter::WriteLinkeditLoadCommand ( uint32_t  Type,
uint32_t  DataOffset,
uint32_t  DataSize 
)
void MachObjectWriter::WriteLinkerOptionsLoadCommand ( const std::vector< std::string > &  Options)
void MachObjectWriter::WriteNlist ( MachSymbolData &  MSD,
const MCAsmLayout Layout 
)
void MachObjectWriter::WriteObject ( MCAssembler Asm,
const MCAsmLayout Layout 
)
virtual

Write the object file.

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

References llvm::MCAssembler::begin(), ComputeLinkerOptionsLoadCommandSize(), llvm::MCAssembler::data_region_begin(), llvm::MCAssembler::data_region_end(), llvm::dbgs(), DEBUG, llvm::DataRegionData::End, llvm::MCAssembler::end(), llvm::MCAsmLayout::getAssembler(), llvm::MCAssembler::getDataRegions(), llvm::MCSymbolData::getIndex(), llvm::MCAssembler::getLinkerOptions(), llvm::MCSymbol::getName(), getPaddingSize(), llvm::MCSectionData::getSection(), getSectionAddress(), llvm::MCAsmLayout::getSectionAddressSize(), llvm::MCAsmLayout::getSectionFileSize(), llvm::MCAssembler::getSubsectionsViaSymbols(), getSymbolAddress(), llvm::MCAssembler::getSymbolData(), llvm::MCSectionMachO::getType(), llvm::MCAssembler::indirect_symbol_begin(), llvm::MCAssembler::indirect_symbol_end(), llvm::MCAssembler::indirect_symbol_size(), is64Bit(), llvm::MCSymbolData::isExternal(), llvm::MCSection::isVirtualSection(), llvm::DataRegionData::Kind, llvm::OffsetToAlignment(), llvm::MCObjectWriter::OS, llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS, llvm::ARMBuildAttrs::Section, llvm::SmallVectorTemplateCommon< T, typename >::size(), llvm::MCAssembler::size(), llvm::DataRegionData::Start, llvm::SmallString< InternalLen >::str(), llvm::MCObjectWriter::Write16(), llvm::MCObjectWriter::Write32(), llvm::MCObjectWriter::Write8(), WriteDysymtabLoadCommand(), WriteHeader(), WriteLinkeditLoadCommand(), WriteLinkerOptionsLoadCommand(), WriteNlist(), WriteSection(), llvm::MCAssembler::writeSectionData(), WriteSegmentLoadCommand(), WriteSymtabLoadCommand(), and llvm::MCObjectWriter::WriteZeros().

void MachObjectWriter::WriteSection ( const MCAssembler Asm,
const MCAsmLayout Layout,
const MCSectionData SD,
uint64_t  FileOffset,
uint64_t  RelocationsStart,
unsigned  NumRelocations 
)
void MachObjectWriter::WriteSegmentLoadCommand ( unsigned  NumSections,
uint64_t  VMSize,
uint64_t  SectionDataStartOffset,
uint64_t  SectionDataSize 
)

WriteSegmentLoadCommand - Write a segment load command.

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

Definition at line 158 of file MachObjectWriter.cpp.

References is64Bit(), llvm::MCObjectWriter::OS, llvm::raw_ostream::tell(), llvm::MachO::VM_PROT_EXECUTE, llvm::MachO::VM_PROT_READ, llvm::MachO::VM_PROT_WRITE, llvm::MCObjectWriter::Write32(), llvm::MCObjectWriter::Write64(), and llvm::MCObjectWriter::WriteBytes().

Referenced by WriteObject().

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

Member Data Documentation

SectionAddrMap llvm::MachObjectWriter::SectionAddress

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