Remove remaining bits of the old LLVM specific symtab handling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184418 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-06-20 13:00:30 +00:00
parent e9ff273aca
commit 6f2c88a08b
6 changed files with 10 additions and 231 deletions

View File

@ -141,8 +141,8 @@ bool ArchiveMember::replaceWith(StringRef newFile, std::string* ErrMsg) {
// Archive class. Everything else (default,copy) is deprecated. This just
// initializes and maps the file into memory, if requested.
Archive::Archive(StringRef filename, LLVMContext &C)
: archPath(filename), members(), mapfile(0), base(0), symTab(), strtab(),
symTabSize(0), firstFileOffset(0), modules(), foreignST(0), Context(C) {}
: archPath(filename), members(), mapfile(0), base(0), strtab(),
firstFileOffset(0), modules(), Context(C) {}
bool
Archive::mapToMemory(std::string* ErrMsg) {
@ -163,18 +163,8 @@ void Archive::cleanUpMemory() {
mapfile = 0;
base = 0;
// Forget the entire symbol table
symTab.clear();
symTabSize = 0;
firstFileOffset = 0;
// Free the foreign symbol table member
if (foreignST) {
delete foreignST;
foreignST = 0;
}
// Delete any Modules and ArchiveMember's we've allocated as a result of
// symbol table searches.
for (ModuleMap::iterator I=modules.begin(), E=modules.end(); I != E; ++I ) {
@ -188,47 +178,3 @@ Archive::~Archive() {
cleanUpMemory();
}
static void getSymbols(Module*M, std::vector<std::string>& symbols) {
// Loop over global variables
for (Module::global_iterator GI = M->global_begin(), GE=M->global_end(); GI != GE; ++GI)
if (!GI->isDeclaration() && !GI->hasLocalLinkage())
if (!GI->getName().empty())
symbols.push_back(GI->getName());
// Loop over functions
for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ++FI)
if (!FI->isDeclaration() && !FI->hasLocalLinkage())
if (!FI->getName().empty())
symbols.push_back(FI->getName());
// Loop over aliases
for (Module::alias_iterator AI = M->alias_begin(), AE = M->alias_end();
AI != AE; ++AI) {
if (AI->hasName())
symbols.push_back(AI->getName());
}
}
Module*
llvm::GetBitcodeSymbols(const char *BufPtr, unsigned Length,
const std::string& ModuleID,
LLVMContext& Context,
std::vector<std::string>& symbols,
std::string* ErrMsg) {
// Get the module.
OwningPtr<MemoryBuffer> Buffer(
MemoryBuffer::getMemBufferCopy(StringRef(BufPtr, Length),ModuleID.c_str()));
Module *M = ParseBitcodeFile(Buffer.get(), Context, ErrMsg);
if (!M)
return 0;
// Get the symbols
getSymbols(M, symbols);
// Done with the module. Note that it's the caller's responsibility to delete
// the Module.
return M;
}

View File

@ -301,20 +301,6 @@ class Archive {
/// @brief Get the iplist of the members
MembersList& getMembers() { return members; }
/// 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.
/// @brief Get the archive's symbol table
const SymTabType& getSymbolTable() { return symTab; }
/// 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
@ -341,7 +327,6 @@ class Archive {
/// returns false if the writing succeeded.
/// @brief Write (possibly modified) archive contents to disk
bool writeToDisk(
bool CreateSymbolTable=false, ///< Create Symbol table
bool TruncateNames=false, ///< Truncate the filename to 15 chars
std::string* ErrMessage=0 ///< If non-null, where error msg is set
);
@ -396,7 +381,6 @@ class Archive {
bool writeMember(
const ArchiveMember& member, ///< The member to be written
std::ofstream& ARFile, ///< The file to write member onto
bool CreateSymbolTable, ///< Should symbol table be created?
bool TruncateNames, ///< Should names be truncated to 11 chars?
std::string* ErrMessage ///< If non-null, place were error msg is set
);
@ -427,12 +411,9 @@ class Archive {
MembersList members; ///< The ilist of ArchiveMember
MemoryBuffer *mapfile; ///< 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.
ArchiveMember* foreignST; ///< This holds the foreign symbol table.
LLVMContext& Context; ///< This holds global data.
/// @}
/// @name Hidden

View File

@ -68,13 +68,6 @@ namespace llvm {
return 0 == memcmp(fmag, ARFILE_MEMBER_MAGIC,2);
}
};
// Get just the externally visible defined symbols from the bitcode
Module* GetBitcodeSymbols(const char *Buffer, unsigned Length,
const std::string& ModuleID,
LLVMContext& Context,
std::vector<std::string>& symbols,
std::string* ErrMsg);
}
#endif

View File

@ -207,7 +207,6 @@ Archive::loadArchive(std::string* error) {
// Set up parsing
members.clear();
symTab.clear();
const char *At = base;
const char *End = mapfile->getBufferEnd();
@ -226,14 +225,6 @@ Archive::loadArchive(std::string* error) {
// check if this is the foreign symbol table
if (mbr->isSVR4SymbolTable() || mbr->isBSD4SymbolTable()) {
// We just save this but don't do anything special
// with it. It doesn't count as the "first file".
if (foreignST) {
// What? Multiple foreign symbol tables? Just chuck it
// and retain the last one found.
delete foreignST;
}
foreignST = mbr;
At += mbr->getSize();
if ((intptr_t(At) & 1) == 1)
At++;
@ -281,7 +272,6 @@ Archive::loadSymbolTable(std::string* ErrorMsg) {
// Set up parsing
members.clear();
symTab.clear();
const char *At = base;
const char *End = mapfile->getBufferEnd();

View File

@ -205,7 +205,6 @@ bool
Archive::writeMember(
const ArchiveMember& member,
std::ofstream& ARFile,
bool CreateSymbolTable,
bool TruncateNames,
std::string* ErrMsg
) {
@ -230,40 +229,6 @@ Archive::writeMember(
fSize = mFile->getBufferSize();
}
// Now that we have the data in memory, update the
// symbol table if it's a bitcode file.
if (CreateSymbolTable && member.isBitcode()) {
std::vector<std::string> symbols;
std::string FullMemberName =
(archPath + "(" + member.getPath() + ")").str();
Module* M =
GetBitcodeSymbols(data, fSize, FullMemberName, Context, symbols, ErrMsg);
// If the bitcode parsed successfully
if ( M ) {
for (std::vector<std::string>::iterator SI = symbols.begin(),
SE = symbols.end(); SI != SE; ++SI) {
std::pair<SymTabType::iterator,bool> Res =
symTab.insert(std::make_pair(*SI,filepos));
if (Res.second) {
symTabSize += SI->length() +
numVbrBytes(SI->length()) +
numVbrBytes(filepos);
}
}
// We don't need this module any more.
delete M;
} else {
delete mFile;
if (ErrMsg)
*ErrMsg = "Can't parse bitcode member: " + member.getPath().str()
+ ": " + *ErrMsg;
return true;
}
}
int hdrSize = fSize;
// Compute the fields of the header
@ -295,10 +260,7 @@ Archive::writeMember(
// This writes to a temporary file first. Options are for creating a symbol
// table, flattening the file names (no directories, 15 chars max) and
// compressing each archive member.
bool
Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
std::string* ErrMsg)
{
bool Archive::writeToDisk(bool TruncateNames, std::string *ErrMsg) {
// Make sure they haven't opened up the file, not loaded it,
// but are now trying to write it which would wipe out the file.
if (members.empty() && mapfile && mapfile->getBufferSize() > 8) {
@ -328,20 +290,13 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
return true;
}
// If we're creating a symbol table, reset it now
if (CreateSymbolTable) {
symTabSize = 0;
symTab.clear();
}
// Write magic string to archive.
ArchiveFile << ARFILE_MAGIC;
// Loop over all member files, and write them out. Note that this also
// builds the symbol table, symTab.
for (MembersList::iterator I = begin(), E = end(); I != E; ++I) {
if (writeMember(*I, ArchiveFile, CreateSymbolTable,
TruncateNames, ErrMsg)) {
if (writeMember(*I, ArchiveFile, TruncateNames, ErrMsg)) {
TmpArchive.eraseFromDisk();
ArchiveFile.close();
return true;
@ -351,69 +306,6 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames,
// Close archive file.
ArchiveFile.close();
// Write the symbol table
if (CreateSymbolTable) {
// At this point we have written a file that is a legal archive but it
// doesn't have a symbol table in it. To aid in faster reading and to
// ensure compatibility with other archivers we need to put the symbol
// table first in the file. Unfortunately, this means mapping the file
// we just wrote back in and copying it to the destination file.
sys::Path FinalFilePath(archPath);
// Map in the archive we just wrote.
{
OwningPtr<MemoryBuffer> arch;
if (error_code ec = MemoryBuffer::getFile(TmpArchive.c_str(), arch)) {
if (ErrMsg)
*ErrMsg = ec.message();
return true;
}
const char* base = arch->getBufferStart();
// Open another temporary file in order to avoid invalidating the
// mmapped data
if (FinalFilePath.createTemporaryFileOnDisk(ErrMsg))
return true;
sys::RemoveFileOnSignal(FinalFilePath.str());
std::ofstream FinalFile(FinalFilePath.c_str(), io_mode);
if (!FinalFile.is_open() || FinalFile.bad()) {
TmpArchive.eraseFromDisk();
if (ErrMsg)
*ErrMsg = "Error opening archive file: " + FinalFilePath.str();
return true;
}
// Write the file magic number
FinalFile << ARFILE_MAGIC;
// If there is a foreign symbol table, put it into the file now. Most
// ar(1) implementations require the symbol table to be first but llvm-ar
// can deal with it being after a foreign symbol table. This ensures
// compatibility with other ar(1) implementations as well as allowing the
// archive to store both native .o and LLVM .bc files, both indexed.
if (foreignST) {
if (writeMember(*foreignST, FinalFile, false, false, ErrMsg)) {
FinalFile.close();
TmpArchive.eraseFromDisk();
return true;
}
}
// Copy the temporary file contents being sure to skip the file's magic
// number.
FinalFile.write(base + sizeof(ARFILE_MAGIC)-1,
arch->getBufferSize()-sizeof(ARFILE_MAGIC)+1);
// Close up shop
FinalFile.close();
} // free arch.
// Move the final file over top of TmpArchive
if (FinalFilePath.renamePathOnDisk(TmpArchive, ErrMsg))
return true;
}
// Before we replace the actual archive, we need to forget all the
// members, since they point to data in that old archive. We need to do
// this because we cannot replace an open file on Windows.

View File

@ -100,7 +100,6 @@ bool FullPath = false; ///< 'P' modifier
bool SymTable = true; ///< 's' & 'S' modifiers
bool OnlyUpdate = false; ///< 'u' modifier
bool Verbose = false; ///< 'v' modifier
bool ReallyVerbose = false; ///< 'V' modifier
// Relative Positional Argument (for insert/move). This variable holds
// the name of the archive member to which the 'a', 'b' or 'i' modifier
@ -217,12 +216,11 @@ ArchiveOperation parseCommandLine() {
case 'k': DontSkipBitcode = true; break;
case 'l': /* accepted but unused */ break;
case 'o': OriginalDates = true; break;
case 's': break; // Ignore for now.
case 'S': break; // Ignore for now.
case 'P': FullPath = true; break;
case 's': SymTable = true; break;
case 'S': SymTable = false; break;
case 'u': OnlyUpdate = true; break;
case 'v': Verbose = true; break;
case 'V': Verbose = ReallyVerbose = true; break;
case 'a':
getRelPos();
AddAfter = true;
@ -303,17 +301,6 @@ bool buildPaths(bool checkExistence, std::string* ErrMsg) {
return false;
}
// printSymbolTable - print out the archive's symbol table.
void printSymbolTable() {
outs() << "\nArchive Symbol Table:\n";
const Archive::SymTabType& symtab = TheArchive->getSymbolTable();
for (Archive::SymTabType::const_iterator I=symtab.begin(), E=symtab.end();
I != E; ++I ) {
unsigned offset = TheArchive->getFirstFileOffset() + I->second;
outs() << " " << format("%9u", offset) << "\t" << I->first <<"\n";
}
}
// doPrint - Implements the 'p' operation. This function traverses the archive
// looking for members that match the path list. It is careful to uncompress
// things that should be and to skip bitcode files unless the 'k' modifier was
@ -398,8 +385,6 @@ doDisplayTable(std::string* ErrMsg) {
}
}
}
if (ReallyVerbose)
printSymbolTable();
return false;
}
@ -478,10 +463,8 @@ doDelete(std::string* ErrMsg) {
}
// We're done editting, reconstruct the archive.
if (TheArchive->writeToDisk(SymTable,TruncateNames,ErrMsg))
if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
return true;
if (ReallyVerbose)
printSymbolTable();
return false;
}
@ -533,10 +516,8 @@ doMove(std::string* ErrMsg) {
}
// We're done editting, reconstruct the archive.
if (TheArchive->writeToDisk(SymTable,TruncateNames,ErrMsg))
if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
return true;
if (ReallyVerbose)
printSymbolTable();
return false;
}
@ -558,10 +539,8 @@ doQuickAppend(std::string* ErrMsg) {
}
// We're done editting, reconstruct the archive.
if (TheArchive->writeToDisk(SymTable,TruncateNames,ErrMsg))
if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
return true;
if (ReallyVerbose)
printSymbolTable();
return false;
}
@ -656,10 +635,8 @@ doReplaceOrInsert(std::string* ErrMsg) {
}
// We're done editting, reconstruct the archive.
if (TheArchive->writeToDisk(SymTable,TruncateNames,ErrMsg))
if (TheArchive->writeToDisk(TruncateNames,ErrMsg))
return true;
if (ReallyVerbose)
printSymbolTable();
return false;
}