LLVM API Documentation

llvm::Archive Class Reference

#include <Archive.h>

Collaboration diagram for llvm::Archive:

Collaboration graph
[legend]
List of all members.

Constructors

 ~Archive ()
 Destruct in-memory archive.
static ArchiveCreateEmpty (const sys::Path &Filename)
 Create an empty Archive.
static ArchiveOpenAndLoad (const sys::Path &filePath, std::string *ErrorMessage=0)
 Open and load an archive file.
static ArchiveOpenAndLoadSymbols (const sys::Path &Filename, std::string *ErrorMessage=0)
 Open an existing archive and load its symbols.

Implementation

typedef std::map< unsigned,
std::pair< ModuleProvider *,
ArchiveMember * > > 
ModuleMap
 Module mapping type.
 Archive (const sys::Path &filename, bool map=false)
 Construct an Archive for filename and optionally map it into memory.
void parseSymbolTable (const void *data, unsigned len)
 Parse the symbol table at data.
ArchiveMemberparseMemberHeader (const char *&At, const char *End)
 Parse the header of a member starting at At.
void checkSignature ()
 Check that the archive signature is correct.
void loadArchive ()
 Load the entire archive.
void loadSymbolTable ()
 Load just the symbol table.
void writeSymbolTable (std::ofstream &ARFile)
 Write the symbol table to an ofstream.
void writeMember (const ArchiveMember &member, std::ofstream &ARFile, bool CreateSymbolTable, bool TruncateNames, bool ShouldCompress)
 Write one ArchiveMember to an ofstream.
bool fillHeader (const ArchiveMember &mbr, ArchiveMemberHeader &hdr, int sz, bool TruncateNames) const
 Fill in an ArchiveMemberHeader from ArchiveMember.
void cleanUpMemory ()
 Frees all the members and unmaps the archive file.

Public Types

Types
typedef iplist< ArchiveMemberMembersList
 The ilist type of ArchiveMembers that Archive contains.
typedef MembersList::iterator iterator
 Forward mutable iterator over ArchiveMember.
typedef MembersList::const_iterator const_iterator
 Forward immutable iterator over ArchiveMember.
typedef std::reverse_iterator<
iterator
reverse_iterator
 Reverse mutable iterator over ArchiveMember.
typedef std::reverse_iterator<
const_iterator
const_reverse_iterator
 Reverse immutable iterator over ArchiveMember.
typedef std::map< std::string,
unsigned > 
SymTabType
 The in-memory version of the symbol table.

Public Member Functions

ilist accessor methods
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
reverse_iterator rbegin ()
const_reverse_iterator rbegin () const
reverse_iterator rend ()
const_reverse_iterator rend () const
unsigned size () const
bool empty () const
const ArchiveMemberfront () const
ArchiveMemberfront ()
const ArchiveMemberback () const
ArchiveMemberback ()
ilist mutator methods
void splice (iterator dest, Archive &arch, iterator src)
 Move a member to a new location.
iterator erase (iterator target)
 Erase a member.
Accessors
const sys::PathgetPath ()
 Get the archive path.
MembersListgetMembers ()
 Get the iplist of the members.
const SymTabTypegetSymbolTable ()
 Get the archive's symbol table.
unsigned getFirstFileOffset ()
 Get the offset to the first "real" file member in the archive.
bool getAllModules (std::vector< Module * > &Modules, std::string *ErrMessage)
 Instantiate all the bytecode modules located in the archive.
ModuleProviderfindModuleDefiningSymbol (const std::string &symbol)
 Look up a module by symbol name.
void findModulesDefiningSymbols (std::set< std::string > &symbols, std::set< ModuleProvider * > &modules)
 Look up multiple symbols in the archive.
bool isBytecodeArchive ()
 Determine whether the archive is a proper llvm bytecode archive.
Mutators
void writeToDisk (bool CreateSymbolTable=false, bool TruncateNames=false, bool Compress=false)
 Write (possibly modified) archive contents to disk.
void addFileBefore (const sys::Path &filename, iterator where)
 Add a file to the archive.

Protected Attributes

Data
sys::Path archPath
 Path to the archive file we read/write.
MembersList members
 The ilist of ArchiveMember.
sys::MappedFilemapfile
 Raw Archive contents mapped into memory.
const char * base
 Base of the memory mapped file data.
SymTabType symTab
 The symbol table.
std::string strtab
 The string table for long file names.
unsigned symTabSize
 Size in bytes of symbol table.
unsigned firstFileOffset
 Offset to first normal file.
ModuleMap modules
 The modules loaded via symbol lookup.
ArchiveMemberforeignST
 This holds the foreign symbol table.

Detailed Description

This class defines the interface to LLVM Archive files. The Archive class presents the archive file as an ilist of ArchiveMember objects. The members can be rearranged in any fashion either by directly editing the ilist or by using editing methods on the Archive class (recommended). The Archive class also provides several ways of accessing the archive file for various purposes such as editing and linking. Full symbol table support is provided for loading only those files that resolve symbols. Note that read performance of this library is _crucial_ for performance of JIT type applications and the linkers. Consequently, the implementation of the class is optimized for reading.

Definition at line 225 of file Archive.h.


Member Typedef Documentation

typedef MembersList::const_iterator llvm::Archive::const_iterator

Forward immutable iterator over ArchiveMember.

Definition at line 239 of file Archive.h.

typedef std::reverse_iterator<const_iterator> llvm::Archive::const_reverse_iterator

Reverse immutable iterator over ArchiveMember.

Definition at line 245 of file Archive.h.

typedef MembersList::iterator llvm::Archive::iterator

Forward mutable iterator over ArchiveMember.

Definition at line 236 of file Archive.h.

typedef iplist<ArchiveMember> llvm::Archive::MembersList

The ilist type of ArchiveMembers that Archive contains.

This is the ilist type over which users may iterate to examine the contents of the archive

Definition at line 233 of file Archive.h.

typedef std::map<unsigned,std::pair<ModuleProvider*,ArchiveMember*> > llvm::Archive::ModuleMap [protected]

Module mapping type.

This type is used to keep track of bytecode modules loaded from the symbol table. It maps the file offset to a pair that consists of the associated ArchiveMember and the ModuleProvider.

Definition at line 500 of file Archive.h.

typedef std::reverse_iterator<iterator> llvm::Archive::reverse_iterator

Reverse mutable iterator over ArchiveMember.

Definition at line 242 of file Archive.h.

typedef std::map<std::string,unsigned> llvm::Archive::SymTabType

The in-memory version of the symbol table.

Definition at line 248 of file Archive.h.


Constructor & Destructor Documentation

Archive::~Archive (  ) 

Destruct in-memory archive.

This destructor cleans up the Archive object, releases all memory, and closes files. It does nothing with the archive file on disk. If you haven't used the writeToDisk method by the time the destructor is called, all changes to the archive will be lost.

Exceptions:
std::string if an error occurs

Definition at line 174 of file Archive.cpp.

References cleanUpMemory().

Archive::Archive ( const sys::Path filename,
bool  map = false 
) [protected]

Construct an Archive for filename and optionally map it into memory.

Definition at line 133 of file Archive.cpp.

References base, llvm::sys::MappedFile::map(), and mapfile.


Member Function Documentation

void Archive::addFileBefore ( const sys::Path filename,
iterator  where 
)

Add a file to the archive.

This method adds a new file to the archive. The filename is examined to determine just enough information to create an ArchiveMember object which is then inserted into the Archive object's ilist at the location given by where.

Exceptions:
std::string if an error occurs reading the filename.
Returns:
nothing

Definition at line 155 of file ArchiveWriter.cpp.

References llvm::sys::BytecodeFileType, llvm::ArchiveMember::BytecodeFlag, llvm::sys::CompressedBytecodeFileType, llvm::ArchiveMember::CompressedBytecodeFlag, llvm::sys::Path::exists(), llvm::ArchiveMember::HasLongFilenameFlag, llvm::ArchiveMember::HasPathFlag, llvm::sys::IdentifyFileType(), magic(), members, llvm::sys::Path::path, and llvm::sys::Path::toString().

ArchiveMember& llvm::Archive::back (  )  [inline]

Definition at line 269 of file Archive.h.

References members.

const ArchiveMember& llvm::Archive::back (  )  const [inline]

Definition at line 268 of file Archive.h.

References members.

const_iterator llvm::Archive::begin (  )  const [inline]

Definition at line 255 of file Archive.h.

References members.

iterator llvm::Archive::begin (  )  [inline]

Definition at line 254 of file Archive.h.

References members.

Referenced by getAllModules(), isBytecodeArchive(), and writeToDisk().

void Archive::checkSignature (  )  [protected]

Check that the archive signature is correct.

Definition at line 206 of file ArchiveReader.cpp.

References ARFILE_MAGIC, base, mapfile, and llvm::sys::MappedFile::size().

Referenced by loadArchive(), and loadSymbolTable().

void Archive::cleanUpMemory (  )  [protected]

Frees all the members and unmaps the archive file.

Definition at line 143 of file Archive.cpp.

References base, llvm::sys::MappedFile::close(), E, firstFileOffset, foreignST, I, mapfile, modules, symTab, and symTabSize.

Referenced by writeToDisk(), and ~Archive().

Archive * Archive::CreateEmpty ( const sys::Path Filename  )  [static]

Create an empty Archive.

Create an empty archive file and associate it with the Filename. This method does not actually create the archive disk file. It creates an empty Archive object. If the writeToDisk method is called, the archive file Filename will be created at that point, with whatever content the returned Archive object has at that time.

Returns:
An Archive* that represents the new archive file.
Parameters:
Filename  Name of the archive to (eventually) create.

Definition at line 66 of file ArchiveWriter.cpp.

bool llvm::Archive::empty (  )  const [inline]

Definition at line 265 of file Archive.h.

References members.

const_iterator llvm::Archive::end (  )  const [inline]

Definition at line 257 of file Archive.h.

References members.

iterator llvm::Archive::end (  )  [inline]

Definition at line 256 of file Archive.h.

References members.

Referenced by getAllModules(), isBytecodeArchive(), and writeToDisk().

iterator llvm::Archive::erase ( iterator  target  )  [inline]

Erase a member.

This method erases a target member from the archive. When the archive is written, it will no longer contain target. The associated ArchiveMember is deleted.

Definition at line 286 of file Archive.h.

References members.

bool Archive::fillHeader ( const ArchiveMember mbr,
ArchiveMemberHeader hdr,
int  sz,
bool  TruncateNames 
) const [protected]

Fill in an ArchiveMemberHeader from ArchiveMember.

Definition at line 78 of file ArchiveWriter.cpp.

References ARFILE_BSD4_SYMTAB_NAME, ARFILE_LLVM_SYMTAB_NAME, ARFILE_STRTAB_NAME, ARFILE_SVR4_SYMTAB_NAME, llvm::ArchiveMemberHeader::date, llvm::ArchiveMember::getGroup(), llvm::ArchiveMember::getMode(), llvm::ArchiveMember::getModTime(), llvm::ArchiveMember::getPath(), llvm::ArchiveMember::getUser(), llvm::ArchiveMemberHeader::gid, llvm::ArchiveMemberHeader::init(), llvm::ArchiveMember::isBSD4SymbolTable(), llvm::ArchiveMember::isLLVMSymbolTable(), llvm::ArchiveMember::isStringTable(), llvm::ArchiveMember::isSVR4SymbolTable(), llvm::ArchiveMemberHeader::mode, llvm::ArchiveMemberHeader::name, llvm::ArchiveMemberHeader::size, llvm::sys::TimeValue::toEpochTime(), llvm::sys::Path::toString(), llvm::ArchiveMemberHeader::uid, and llvm::utostr().

Referenced by writeMember().

ModuleProvider * Archive::findModuleDefiningSymbol ( const std::string &  symbol  ) 

Look up a module by symbol name.

This accessor looks up the symbol in the archive's symbol table and returns the associated module that defines that symbol. This method can be called as many times as necessary. This is handy for linking the archive into another module based on unresolved symbols. Note that the ModuleProvider returned by this accessor should not be deleted by the caller. It is managed internally by the Archive class. It is possible that multiple calls to this accessor will return the same ModuleProvider instance because the associated module defines multiple symbols.

Returns:
The ModuleProvider* found or null if the archive does not contain a module that defines the symbol.
Parameters:
symbol  Symbol to be sought

Definition at line 396 of file ArchiveReader.cpp.

References archPath, base, firstFileOffset, llvm::getBytecodeBufferModuleProvider(), mapfile, MI, modules, parseMemberHeader(), llvm::sys::MappedFile::size(), symTab, and llvm::sys::Path::toString().

Referenced by findModulesDefiningSymbols().

void Archive::findModulesDefiningSymbols ( std::set< std::string > &  symbols,
std::set< ModuleProvider * > &  modules 
)

Look up multiple symbols in the archive.

This method is similar to findModuleDefiningSymbol but allows lookup of more than one symbol at a time. If symbols contains a list of undefined symbols in some module, then calling this method is like making one complete pass through the archive to resolve symbols but is more efficient than looking at the individual members. Note that on exit, the symbols resolved by this method will be removed from symbols to ensure they are not re-searched on a subsequent call. If you need to retain the list of symbols, make a copy.

Parameters:
symbols  Symbols to be sought
modules  The modules matching symbols

Definition at line 435 of file ArchiveReader.cpp.

References archPath, base, E, findModuleDefiningSymbol(), firstFileOffset, llvm::GetBytecodeSymbols(), llvm::ArchiveMember::getPath(), llvm::ArchiveMember::getSize(), I, llvm::ArchiveMember::isBytecode(), llvm::ArchiveMember::isCompressedBytecode(), mapfile, modules, parseMemberHeader(), llvm::sys::MappedFile::size(), symTab, and llvm::sys::Path::toString().

Referenced by llvm::Linker::LinkInArchive().

ArchiveMember& llvm::Archive::front (  )  [inline]

Definition at line 267 of file Archive.h.

References members.

const ArchiveMember& llvm::Archive::front (  )  const [inline]

Definition at line 266 of file Archive.h.

References members.

bool Archive::getAllModules ( std::vector< Module * > &  Modules,
std::string *  ErrMessage 
)

Instantiate all the bytecode modules located in the archive.

This method will scan the archive for bytecode modules, interpret them and return a vector of the instantiated modules in Modules. If an error occurs, this method will return true. If ErrMessage is not null and an error occurs, *ErrMessage will be set to a string explaining the error that occurred.

Returns:
true if an error occurred

Definition at line 300 of file ArchiveReader.cpp.

References archPath, begin(), E, end(), I, M, llvm::ParseBytecodeBuffer(), and llvm::sys::Path::toString().

unsigned llvm::Archive::getFirstFileOffset (  )  [inline]

Get the offset to the first "real" file member in the archive.

This method returns the offset in the archive file to the first "real" file member. Archive files, on disk, have a signature and might have a symbol table that precedes the first actual file member. This method allows you to determine what the size of those fields are.

Returns:
the offset to the first "real" file member in the archive.

Definition at line 378 of file Archive.h.

References firstFileOffset.

MembersList& llvm::Archive::getMembers (  )  [inline]

Get the iplist of the members.

This method is provided so that editing methods can be invoked directly on the Archive's iplist of ArchiveMember. However, it is recommended that the usual STL style iterator interface be used instead.

Returns:
the iplist of ArchiveMember

Definition at line 356 of file Archive.h.

References members.

const sys::Path& llvm::Archive::getPath (  )  [inline]

Get the archive path.

Returns:
the path to the archive file.

Definition at line 349 of file Archive.h.

References archPath.

const SymTabType& llvm::Archive::getSymbolTable (  )  [inline]

Get the archive's symbol table.

This method allows direct query of the Archive's symbol table. The symbol table is a std::map of std::string (the symbol) to unsigned (the file offset). Note that for efficiency reasons, the offset stored in the symbol table is not the actual offset. It is the offset from the beginning of the first "real" file member (after the symbol table). Use the getFirstFileOffset() to obtain that offset and add this value to the offset in the symbol table to obtain the real file offset. Note that there is purposefully no interface provided by Archive to look up members by their offset. Use the findModulesDefiningSymbols and findModuleDefiningSymbol methods instead.

Returns:
the Archive's symbol table.

Definition at line 370 of file Archive.h.

References symTab.

bool Archive::isBytecodeArchive (  ) 

Determine whether the archive is a proper llvm bytecode archive.

This method determines whether the archive is a properly formed llvm bytecode archive. It first makes sure the symbol table has been loaded and has a non-zero size. If it does, then it is an archive. If not, then it tries to load all the bytecode modules of the archive. Finally, it returns whether it was successfull.

Returns:
true if the archive is a proper llvm bytecode archive

Definition at line 508 of file ArchiveReader.cpp.

References archPath, begin(), E, end(), I, loadArchive(), loadSymbolTable(), M, llvm::ParseBytecodeBuffer(), symTab, and llvm::sys::Path::toString().

void Archive::loadArchive (  )  [protected]

Load the entire archive.

Definition at line 216 of file ArchiveReader.cpp.

References base, checkSignature(), firstFileOffset, foreignST, llvm::ArchiveMember::getData(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBSD4SymbolTable(), llvm::ArchiveMember::isLLVMSymbolTable(), llvm::ArchiveMember::isStringTable(), llvm::ArchiveMember::isSVR4SymbolTable(), mapfile, members, parseMemberHeader(), parseSymbolTable(), llvm::sys::MappedFile::size(), strtab, and symTab.

Referenced by isBytecodeArchive().

void Archive::loadSymbolTable (  )  [protected]

Load just the symbol table.

Definition at line 319 of file ArchiveReader.cpp.

References base, checkSignature(), firstFileOffset, llvm::ArchiveMember::getData(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBSD4SymbolTable(), llvm::ArchiveMember::isLLVMSymbolTable(), llvm::ArchiveMember::isStringTable(), llvm::ArchiveMember::isSVR4SymbolTable(), mapfile, members, parseMemberHeader(), parseSymbolTable(), llvm::sys::MappedFile::size(), strtab, and symTab.

Referenced by isBytecodeArchive().

Archive * Archive::OpenAndLoad ( const sys::Path filePath,
std::string *  ErrorMessage = 0 
) [static]

Open and load an archive file.

Open an existing archive and load its contents in preparation for editing. After this call, the member ilist is completely populated based on the contents of the archive file. You should use this form of open if you intend to modify the archive or traverse its contents (e.g. for printing).

Parameters:
filePath  The file path to open and load
ErrorMessage  An optional error string

Definition at line 285 of file ArchiveReader.cpp.

Archive * Archive::OpenAndLoadSymbols ( const sys::Path Filename,
std::string *  ErrorMessage = 0 
) [static]

Open an existing archive and load its symbols.

This method opens an existing archive file from Filename and reads in its symbol table without reading in any of the archive's members. This reduces both I/O and cpu time in opening the archive if it is to be used solely for symbol lookup (e.g. during linking). The Filename must exist and be an archive file or an exception will be thrown. This form of opening the archive is intended for read-only operations that need to locate members via the symbol table for link editing. Since the archve members are not read by this method, the archive will appear empty upon return. If editing operations are performed on the archive, they will completely replace the contents of the archive! It is recommended that if this form of opening the archive is used that only the symbol table lookup methods (getSymbolTable, findModuleDefiningSymbol, and findModulesDefiningSymbols) be used.

Exceptions:
std::string if an error occurs opening the file
Returns:
an Archive* that represents the archive file.
Parameters:
Filename  Name of the archive file to open
ErrorMessage  An optional error string

Definition at line 380 of file ArchiveReader.cpp.

Referenced by llvm::Linker::LinkInArchive().

ArchiveMember * Archive::parseMemberHeader ( const char *&  At,
const char *  End 
) [protected]

Parse the header of a member starting at At.

Definition at line 55 of file ArchiveReader.cpp.

References ARFILE_BSD4_SYMTAB_NAME, ARFILE_LLVM_SYMTAB_NAME, ARFILE_STRTAB_NAME, ARFILE_SVR4_SYMTAB_NAME, llvm::ArchiveMember::BSD4SymbolTableFlag, llvm::sys::BytecodeFileType, llvm::ArchiveMember::BytecodeFlag, llvm::ArchiveMemberHeader::checkSignature(), llvm::sys::CompressedBytecodeFileType, llvm::ArchiveMember::CompressedBytecodeFlag, llvm::ArchiveMember::CompressedFlag, llvm::ArchiveMember::data, llvm::ArchiveMemberHeader::date, llvm::sys::Path::StatusInfo::fileSize, llvm::ArchiveMember::flags, llvm::sys::TimeValue::fromEpochTime(), llvm::ArchiveMemberHeader::gid, llvm::sys::Path::StatusInfo::group, llvm::ArchiveMember::HasLongFilenameFlag, llvm::sys::IdentifyFileType(), index, llvm::ArchiveMember::info, llvm::ArchiveMember::LLVMSymbolTableFlag, llvm::sys::Path::StatusInfo::mode, llvm::ArchiveMemberHeader::mode, llvm::sys::Path::StatusInfo::modTime, llvm::ArchiveMemberHeader::name, llvm::ArchiveMember::next, llvm::ArchiveMember::parent, llvm::ArchiveMember::path, llvm::ArchiveMember::prev, llvm::sys::Path::set(), llvm::ArchiveMemberHeader::size, llvm::ArchiveMember::StringTableFlag, strtab, llvm::ArchiveMember::SVR4SymbolTableFlag, llvm::ArchiveMemberHeader::uid, and llvm::sys::Path::StatusInfo::user.

Referenced by findModuleDefiningSymbol(), findModulesDefiningSymbols(), loadArchive(), and loadSymbolTable().

void Archive::parseSymbolTable ( const void *  data,
unsigned  len 
) [protected]

Parse the symbol table at data.

Definition at line 36 of file ArchiveReader.cpp.

References readInteger(), symTab, and symTabSize.

Referenced by loadArchive(), and loadSymbolTable().

const_reverse_iterator llvm::Archive::rbegin (  )  const [inline]

Definition at line 260 of file Archive.h.

References members.

reverse_iterator llvm::Archive::rbegin (  )  [inline]

Definition at line 259 of file Archive.h.

References members.

const_reverse_iterator llvm::Archive::rend (  )  const [inline]

Definition at line 262 of file Archive.h.

References members.

reverse_iterator llvm::Archive::rend (  )  [inline]

Definition at line 261 of file Archive.h.

References members.

unsigned llvm::Archive::size (  )  const [inline]

Definition at line 264 of file Archive.h.

References members.

void llvm::Archive::splice ( iterator  dest,
Archive arch,
iterator  src 
) [inline]

Move a member to a new location.

This method splices a src member from an archive (possibly this), to a position just before the member given by dest in this. When the archive is written, src will be written in its new location.

Definition at line 279 of file Archive.h.

References members.

void Archive::writeMember ( const ArchiveMember member,
std::ofstream &  ARFile,
bool  CreateSymbolTable,
bool  TruncateNames,
bool  ShouldCompress 
) [protected]

Write one ArchiveMember to an ofstream.

Definition at line 188 of file ArchiveWriter.cpp.

References archPath, ARFILE_PAD, llvm::sys::MappedFile::close(), llvm::Compressor::compressToNewBuffer(), fillHeader(), llvm::GetBytecodeSymbols(), llvm::ArchiveMember::getData(), llvm::ArchiveMember::getPath(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBSD4SymbolTable(), llvm::ArchiveMember::isBytecode(), llvm::ArchiveMember::isCompressed(), llvm::ArchiveMember::isCompressedBytecode(), llvm::ArchiveMember::isLLVMSymbolTable(), llvm::ArchiveMember::isSVR4SymbolTable(), llvm::sys::MappedFile::map(), numVbrBytes(), SE, llvm::sys::MappedFile::size(), symTab, symTabSize, and llvm::sys::Path::toString().

Referenced by writeToDisk().

void Archive::writeSymbolTable ( std::ofstream &  ARFile  )  [protected]

Write the symbol table to an ofstream.

Definition at line 314 of file ArchiveWriter.cpp.

References ARFILE_LLVM_SYMTAB_NAME, ARFILE_PAD, llvm::ArchiveMemberHeader::date, E, llvm::sys::Process::GetCurrentGroupId(), llvm::sys::Process::GetCurrentUserId(), llvm::ArchiveMemberHeader::gid, I, llvm::ArchiveMemberHeader::init(), llvm::ArchiveMemberHeader::mode, llvm::ArchiveMemberHeader::name, llvm::sys::TimeValue::now(), llvm::ArchiveMemberHeader::size, symTab, symTabSize, llvm::sys::TimeValue::toEpochTime(), llvm::ArchiveMemberHeader::uid, and writeInteger().

Referenced by writeToDisk().

void Archive::writeToDisk ( bool  CreateSymbolTable = false,
bool  TruncateNames = false,
bool  Compress = false 
)

Write (possibly modified) archive contents to disk.

This method is the only way to get the archive written to disk. It creates or overwrites the file specified when this was created or opened. The arguments provide options for writing the archive. If CreateSymbolTable is true, the archive is scanned for bytecode files and a symbol table of the externally visible function and global variable names is created. If TruncateNames is true, the names of the archive members will have their path component stripped and the file name will be truncated at 15 characters. If Compress is specified, all archive members will be compressed before being written. If PrintSymTab is true, the symbol table will be printed to std::cout.

Exceptions:
std::string if an error occurs
Parameters:
CreateSymbolTable  Create Symbol table
TruncateNames  Truncate the filename to 15 chars
Compress  Compress files

Definition at line 368 of file ArchiveWriter.cpp.

References archPath, ARFILE_MAGIC, base, begin(), llvm::sys::Path::c_str(), cleanUpMemory(), llvm::sys::MappedFile::close(), llvm::sys::Path::createTemporaryFileOnDisk(), E, end(), llvm::sys::Path::eraseFromDisk(), llvm::sys::Path::exists(), foreignST, I, llvm::sys::MappedFile::map(), mapfile, members, llvm::sys::RemoveFileOnSignal(), llvm::sys::Path::renamePathOnDisk(), llvm::sys::MappedFile::size(), symTab, symTabSize, llvm::sys::Path::toString(), writeMember(), and writeSymbolTable().


Member Data Documentation

sys::Path llvm::Archive::archPath [protected]

Path to the archive file we read/write.

Definition at line 506 of file Archive.h.

Referenced by findModuleDefiningSymbol(), findModulesDefiningSymbols(), getAllModules(), getPath(), isBytecodeArchive(), writeMember(), and writeToDisk().

const char* llvm::Archive::base [protected]

Base of the memory mapped file data.

Definition at line 509 of file Archive.h.

Referenced by Archive(), checkSignature(), cleanUpMemory(), findModuleDefiningSymbol(), findModulesDefiningSymbols(), loadArchive(), loadSymbolTable(), and writeToDisk().

unsigned llvm::Archive::firstFileOffset [protected]

Offset to first normal file.

Definition at line 513 of file Archive.h.

Referenced by cleanUpMemory(), findModuleDefiningSymbol(), findModulesDefiningSymbols(), getFirstFileOffset(), loadArchive(), and loadSymbolTable().

ArchiveMember* llvm::Archive::foreignST [protected]

This holds the foreign symbol table.

Definition at line 515 of file Archive.h.

Referenced by cleanUpMemory(), loadArchive(), and writeToDisk().

sys::MappedFile* llvm::Archive::mapfile [protected]

Raw Archive contents mapped into memory.

Definition at line 508 of file Archive.h.

Referenced by Archive(), checkSignature(), cleanUpMemory(), findModuleDefiningSymbol(), findModulesDefiningSymbols(), loadArchive(), loadSymbolTable(), and writeToDisk().

MembersList llvm::Archive::members [protected]

The ilist of ArchiveMember.

Definition at line 507 of file Archive.h.

Referenced by addFileBefore(), back(), begin(), empty(), end(), erase(), front(), getMembers(), loadArchive(), loadSymbolTable(), rbegin(), rend(), size(), splice(), and writeToDisk().

ModuleMap llvm::Archive::modules [protected]

The modules loaded via symbol lookup.

Definition at line 514 of file Archive.h.

Referenced by cleanUpMemory(), findModuleDefiningSymbol(), and findModulesDefiningSymbols().

std::string llvm::Archive::strtab [protected]

The string table for long file names.

Definition at line 511 of file Archive.h.

Referenced by loadArchive(), loadSymbolTable(), and parseMemberHeader().

SymTabType llvm::Archive::symTab [protected]

The symbol table.

Definition at line 510 of file Archive.h.

Referenced by cleanUpMemory(), findModuleDefiningSymbol(), findModulesDefiningSymbols(), getSymbolTable(), isBytecodeArchive(), loadArchive(), loadSymbolTable(), parseSymbolTable(), writeMember(), writeSymbolTable(), and writeToDisk().

unsigned llvm::Archive::symTabSize [protected]

Size in bytes of symbol table.

Definition at line 512 of file Archive.h.

Referenced by cleanUpMemory(), parseSymbolTable(), writeMember(), writeSymbolTable(), and writeToDisk().


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