LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

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.
ArchiveCreateEmpty (const sys::Path &Filename)
 Create an empty Archive.
ArchiveOpenAndLoad (const sys::Path &filePath, std::string *ErrorMessage)
 Open and load an archive file.
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)
 Construct an Archive for filename and optionally map it into memory.
bool parseSymbolTable (const void *data, unsigned len, std::string *error)
 Parse the symbol table at data.
ArchiveMemberparseMemberHeader (const char *&At, const char *End, std::string *error)
 Parse the header of a member starting at At.
bool checkSignature (std::string *ErrMessage)
 Check that the archive signature is correct.
bool loadArchive (std::string *ErrMessage)
 Load the entire archive.
bool loadSymbolTable (std::string *ErrMessage)
 Load just the symbol table.
void writeSymbolTable (std::ofstream &ARFile)
 Write the symbol table to an ofstream.
bool writeMember (const ArchiveMember &member, std::ofstream &ARFile, bool CreateSymbolTable, bool TruncateNames, bool ShouldCompress, std::string *ErrMessage)
bool fillHeader (const ArchiveMember &mbr, ArchiveMemberHeader &hdr, int sz, bool TruncateNames) const
 Fill in an ArchiveMemberHeader from ArchiveMember.
bool mapToMemory (std::string *ErrMsg)
 Maps archive into memory.
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
size_t 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 bitcode modules located in the archive.
ModuleProviderfindModuleDefiningSymbol (const std::string &symbol, std::string *ErrMessage)
 Look up a module by symbol name.
bool findModulesDefiningSymbols (std::set< std::string > &symbols, std::set< ModuleProvider * > &modules, std::string *ErrMessage)
 Look up multiple symbols in the archive.
bool isBitcodeArchive ()
 Determine whether the archive is a proper llvm bitcode archive.
Mutators
bool writeToDisk (bool CreateSymbolTable=false, bool TruncateNames=false, bool Compress=false, std::string *ErrMessage=0)
 Write (possibly modified) archive contents to disk.
bool addFileBefore (const sys::Path &filename, iterator where, std::string *ErrMsg)
 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.
MemoryBuffermapfile
 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

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 206 of file Archive.h.


Member Typedef Documentation

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

Forward immutable iterator over ArchiveMember.

Definition at line 220 of file Archive.h.

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

Reverse immutable iterator over ArchiveMember.

Definition at line 226 of file Archive.h.

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

Forward mutable iterator over ArchiveMember.

Definition at line 217 of file Archive.h.

Referenced by getAllModules(), and isBitcodeArchive().

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 214 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 bitcode 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 516 of file Archive.h.

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

Reverse mutable iterator over ArchiveMember.

Definition at line 223 of file Archive.h.

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

The in-memory version of the symbol table.

Definition at line 229 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 182 of file Archive.cpp.

References cleanUpMemory().

Archive::Archive const sys::Path filename  )  [explicit, protected]
 

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

Definition at line 141 of file Archive.cpp.

Referenced by CreateEmpty(), OpenAndLoad(), and OpenAndLoadSymbols().


Member Function Documentation

bool Archive::addFileBefore const sys::Path filename,
iterator  where,
std::string *  ErrMsg
 

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.

Returns:
true if an error occured, false otherwise
Parameters:
filePath  The file to be added
where  Insertion point
ErrMsg  Optional error message location

Definition at line 157 of file ArchiveWriter.cpp.

References llvm::ArchiveMember::data, llvm::sys::Path::exists(), llvm::ArchiveMember::flags, llvm::sys::PathWithStatus::getFileStatus(), llvm::sys::Path::getMagicNumber(), llvm::sys::IdentifyFileType(), llvm::ArchiveMember::info, llvm::iplist< NodeTy, Traits >::insert(), members, llvm::ArchiveMember::path, and llvm::sys::Path::toString().

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

Definition at line 250 of file Archive.h.

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

Definition at line 249 of file Archive.h.

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

Definition at line 236 of file Archive.h.

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

Definition at line 235 of file Archive.h.

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

bool Archive::checkSignature std::string *  ErrMessage  )  [protected]
 

Check that the archive signature is correct.

Parameters:
ErrMessage Set to address of a std::string to get error messages
Returns:
false on error

Definition at line 237 of file ArchiveReader.cpp.

References ARFILE_MAGIC, base, llvm::MemoryBuffer::getBufferSize(), and mapfile.

Referenced by loadArchive(), and loadSymbolTable().

void Archive::cleanUpMemory  )  [protected]
 

Frees all the members and unmaps the archive file.

Definition at line 155 of file Archive.cpp.

References base, firstFileOffset, foreignST, 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:
FilePath  Name of the archive to (eventually) create.

Definition at line 68 of file ArchiveWriter.cpp.

References Archive().

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

Definition at line 246 of file Archive.h.

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

Definition at line 238 of file Archive.h.

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

Definition at line 237 of file Archive.h.

Referenced by getAllModules(), isBitcodeArchive(), 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 267 of file Archive.h.

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

Fill in an ArchiveMemberHeader from ArchiveMember.

Definition at line 80 of file ArchiveWriter.cpp.

References ARFILE_BSD4_SYMTAB_NAME, ARFILE_LLVM_SYMTAB_NAME, ARFILE_STRTAB_NAME, ARFILE_SVR4_SYMTAB_NAME, llvm::sys::Path::c_str(), 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,
std::string *  ErrMessage
 

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
ErrMsg  Error message storage, if non-zero

Definition at line 455 of file ArchiveReader.cpp.

References archPath, base, llvm::getBitcodeModuleProvider(), llvm::MemoryBuffer::getBufferEnd(), llvm::MemoryBuffer::getBufferStart(), llvm::ArchiveMember::getData(), llvm::MemoryBuffer::getNewMemBuffer(), llvm::ArchiveMember::getPath(), llvm::ArchiveMember::getSize(), mapfile, modules, parseMemberHeader(), symTab, and llvm::sys::Path::toString().

Referenced by findModulesDefiningSymbols().

bool Archive::findModulesDefiningSymbols std::set< std::string > &  symbols,
std::set< ModuleProvider * > &  modules,
std::string *  ErrMessage
 

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
result  The modules matching symbols
error  Error msg storage, if non-zero

Definition at line 502 of file ArchiveReader.cpp.

References archPath, base, findModuleDefiningSymbol(), llvm::GetBitcodeSymbols(), llvm::MemoryBuffer::getBufferEnd(), llvm::ArchiveMember::getPath(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBitcode(), mapfile, modules, parseMemberHeader(), symTab, and llvm::sys::Path::toString().

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

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

Definition at line 248 of file Archive.h.

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

Definition at line 247 of file Archive.h.

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

Instantiate all the bitcode modules located in the archive.

This method will scan the archive for bitcode 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 341 of file ArchiveReader.cpp.

References archPath, begin(), end(), llvm::MemoryBuffer::getBufferStart(), llvm::MemoryBuffer::getNewMemBuffer(), iterator, llvm::ParseBitcodeFile(), 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 359 of file Archive.h.

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 337 of file Archive.h.

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

Get the archive path.

Returns:
the path to the archive file.

Definition at line 330 of file Archive.h.

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 351 of file Archive.h.

bool Archive::isBitcodeArchive  ) 
 

Determine whether the archive is a proper llvm bitcode archive.

This method determines whether the archive is a properly formed llvm bitcode 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 bitcode modules of the archive. Finally, it returns whether it was successfull.

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

Definition at line 587 of file ArchiveReader.cpp.

References archPath, begin(), end(), llvm::MemoryBuffer::getBufferStart(), llvm::MemoryBuffer::getNewMemBuffer(), iterator, loadArchive(), loadSymbolTable(), llvm::ParseBitcodeFile(), symTab, and llvm::sys::Path::toString().

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

bool Archive::loadArchive std::string *  ErrMessage  )  [protected]
 

Load the entire archive.

Parameters:
ErrMessage Set to address of a std::string to get error messages
Returns:
false on error

Definition at line 251 of file ArchiveReader.cpp.

References checkSignature(), llvm::iplist< NodeTy, Traits >::clear(), firstFileOffset, foreignST, llvm::MemoryBuffer::getBufferEnd(), llvm::ArchiveMember::getData(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBSD4SymbolTable(), llvm::ArchiveMember::isLLVMSymbolTable(), llvm::ArchiveMember::isStringTable(), llvm::ArchiveMember::isSVR4SymbolTable(), mapfile, members, parseMemberHeader(), parseSymbolTable(), llvm::iplist< NodeTy, Traits >::push_back(), strtab, and symTab.

Referenced by isBitcodeArchive().

bool Archive::loadSymbolTable std::string *  ErrMessage  )  [protected]
 

Load just the symbol table.

Parameters:
ErrMessage Set to address of a std::string to get error messages
Returns:
false on error

Definition at line 364 of file ArchiveReader.cpp.

References checkSignature(), llvm::iplist< NodeTy, Traits >::clear(), firstFileOffset, llvm::MemoryBuffer::getBufferEnd(), llvm::ArchiveMember::getData(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBSD4SymbolTable(), llvm::ArchiveMember::isLLVMSymbolTable(), llvm::ArchiveMember::isStringTable(), llvm::ArchiveMember::isSVR4SymbolTable(), mapfile, members, parseMemberHeader(), parseSymbolTable(), llvm::iplist< NodeTy, Traits >::push_back(), strtab, and symTab.

Referenced by isBitcodeArchive().

bool Archive::mapToMemory std::string *  ErrMsg  )  [protected]
 

Maps archive into memory.

Definition at line 147 of file Archive.cpp.

References archPath, base, llvm::sys::Path::c_str(), llvm::MemoryBuffer::getBufferStart(), llvm::MemoryBuffer::getFile(), and mapfile.

Archive * Archive::OpenAndLoad const sys::Path filePath,
std::string *  ErrorMessage
[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:
file  The file path to open and load
ErrorMessage  An optional error string

Definition at line 329 of file ArchiveReader.cpp.

References Archive().

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:
file  Name of the archive file to open
ErrorMessage  An optional error string

Definition at line 443 of file ArchiveReader.cpp.

References Archive().

ArchiveMember * Archive::parseMemberHeader const char *&  At,
const char *  End,
std::string *  error
[protected]
 

Parse the header of a member starting at At.

Returns:
A fully populated ArchiveMember or 0 if an error occurred.
Parameters:
At  The pointer to the location we're parsing
End  The pointer to the end of the archive
error  Optional error message catcher

Definition at line 70 of file ArchiveReader.cpp.

References ARFILE_BSD4_SYMTAB_NAME, ARFILE_LLVM_SYMTAB_NAME, ARFILE_STRTAB_NAME, ARFILE_SVR4_SYMTAB_NAME, llvm::ArchiveMemberHeader::checkSignature(), llvm::ArchiveMember::data, llvm::ArchiveMemberHeader::date, llvm::sys::FileStatus::fileSize, llvm::ArchiveMember::flags, llvm::sys::TimeValue::fromEpochTime(), llvm::ArchiveMemberHeader::gid, llvm::sys::FileStatus::group, llvm::sys::IdentifyFileType(), llvm::ArchiveMember::info, llvm::sys::FileStatus::mode, llvm::ArchiveMemberHeader::mode, llvm::sys::FileStatus::modTime, llvm::ArchiveMemberHeader::name, llvm::ArchiveMember::parent, llvm::ArchiveMember::path, llvm::sys::Path::set(), llvm::ArchiveMemberHeader::size, strtab, llvm::ArchiveMemberHeader::uid, and llvm::sys::FileStatus::user.

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

bool Archive::parseSymbolTable const void *  data,
unsigned  len,
std::string *  error
[protected]
 

Parse the symbol table at data.

Parameters:
data The symbol table data to be parsed
len The length of the symbol table data
error Set to address of a std::string to get error messages
Returns:
false on error

Definition at line 37 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 241 of file Archive.h.

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

Definition at line 240 of file Archive.h.

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

Definition at line 243 of file Archive.h.

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

Definition at line 242 of file Archive.h.

size_t llvm::Archive::size  )  const [inline]
 

Definition at line 245 of file Archive.h.

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 260 of file Archive.h.

References members.

bool Archive::writeMember const ArchiveMember member,
std::ofstream &  ARFile,
bool  CreateSymbolTable,
bool  TruncateNames,
bool  ShouldCompress,
std::string *  ErrMessage
[protected]
 

Writes one ArchiveMember to an ofstream. If an error occurs, returns false, otherwise true. If an error occurs and error is non-null then it will be set to an error message.

Returns:
false Writing member succeeded

true Writing member failed, error set to error message

Parameters:
member  The member to be written
ARFile  The file to write member onto
CreateSymbolTable  Should symbol table be created?
TruncateNames  Should names be truncated to 11 chars?
ShouldCompress  Should the member be compressed?
ErrMsg  If non-null, place were error msg is set

Definition at line 197 of file ArchiveWriter.cpp.

References archPath, llvm::sys::Path::c_str(), fillHeader(), llvm::GetBitcodeSymbols(), llvm::MemoryBuffer::getBufferSize(), llvm::MemoryBuffer::getBufferStart(), llvm::ArchiveMember::getData(), llvm::MemoryBuffer::getFile(), llvm::ArchiveMember::getPath(), llvm::ArchiveMember::getSize(), llvm::ArchiveMember::isBitcode(), numVbrBytes(), 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 287 of file ArchiveWriter.cpp.

References ARFILE_LLVM_SYMTAB_NAME, llvm::ArchiveMemberHeader::date, llvm::ArchiveMemberHeader::gid, 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().

bool Archive::writeToDisk bool  CreateSymbolTable = false,
bool  TruncateNames = false,
bool  Compress = false,
std::string *  ErrMessage = 0
 

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 bitcode 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.

Returns:
true if an error occurred, error set to error message

false if the writing succeeded.

Parameters:
CreateSymbolTable  Create Symbol table
TruncateNames  Truncate the filename to 15 chars
Compress  Compress files
ErrMsg  If non-null, where error msg is set

Definition at line 341 of file ArchiveWriter.cpp.

References archPath, ARFILE_MAGIC, base, begin(), llvm::sys::Path::c_str(), cleanUpMemory(), llvm::sys::Path::clear(), llvm::Compress(), llvm::sys::Path::createTemporaryFileOnDisk(), llvm::iplist< NodeTy, Traits >::empty(), end(), llvm::sys::Path::eraseFromDisk(), llvm::sys::Path::exists(), foreignST, llvm::MemoryBuffer::getBufferSize(), llvm::sys::Path::makeReadableOnDisk(), llvm::sys::Path::makeWriteableOnDisk(), mapfile, members, llvm::sys::RemoveFileOnSignal(), llvm::sys::Path::renamePathOnDisk(), 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 523 of file Archive.h.

Referenced by findModuleDefiningSymbol(), findModulesDefiningSymbols(), getAllModules(), isBitcodeArchive(), mapToMemory(), writeMember(), and writeToDisk().

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

Base of the memory mapped file data.

Definition at line 526 of file Archive.h.

Referenced by checkSignature(), cleanUpMemory(), findModuleDefiningSymbol(), findModulesDefiningSymbols(), mapToMemory(), and writeToDisk().

unsigned llvm::Archive::firstFileOffset [protected]
 

Offset to first normal file.

Definition at line 530 of file Archive.h.

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

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

This holds the foreign symbol table.

Definition at line 532 of file Archive.h.

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

MemoryBuffer* llvm::Archive::mapfile [protected]
 

Raw Archive contents mapped into memory.

Definition at line 525 of file Archive.h.

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

MembersList llvm::Archive::members [protected]
 

The ilist of ArchiveMember.

Definition at line 524 of file Archive.h.

Referenced by addFileBefore(), loadArchive(), loadSymbolTable(), splice(), and writeToDisk().

ModuleMap llvm::Archive::modules [protected]
 

The modules loaded via symbol lookup.

Definition at line 531 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 528 of file Archive.h.

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

SymTabType llvm::Archive::symTab [protected]
 

The symbol table.

Definition at line 527 of file Archive.h.

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

unsigned llvm::Archive::symTabSize [protected]
 

Size in bytes of symbol table.

Definition at line 529 of file Archive.h.

Referenced by cleanUpMemory(), parseSymbolTable(),