From: Rafael Espindola Date: Thu, 20 Jun 2013 13:00:30 +0000 (+0000) Subject: Remove remaining bits of the old LLVM specific symtab handling. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=6f2c88a08b30e9e22d71ed7d7abb89bbcc9d1629;p=oota-llvm.git 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 --- diff --git a/tools/llvm-ar/Archive.cpp b/tools/llvm-ar/Archive.cpp index dcb640198ee..cac65cf7706 100644 --- a/tools/llvm-ar/Archive.cpp +++ b/tools/llvm-ar/Archive.cpp @@ -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& 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& symbols, - std::string* ErrMsg) { - // Get the module. - OwningPtr 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; -} diff --git a/tools/llvm-ar/Archive.h b/tools/llvm-ar/Archive.h index 33a12c0c90a..79d95873fde 100644 --- a/tools/llvm-ar/Archive.h +++ b/tools/llvm-ar/Archive.h @@ -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 diff --git a/tools/llvm-ar/ArchiveInternals.h b/tools/llvm-ar/ArchiveInternals.h index a39c76bb471..a2a3077b10f 100644 --- a/tools/llvm-ar/ArchiveInternals.h +++ b/tools/llvm-ar/ArchiveInternals.h @@ -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& symbols, - std::string* ErrMsg); } #endif diff --git a/tools/llvm-ar/ArchiveReader.cpp b/tools/llvm-ar/ArchiveReader.cpp index a9df13eca11..8eba5954561 100644 --- a/tools/llvm-ar/ArchiveReader.cpp +++ b/tools/llvm-ar/ArchiveReader.cpp @@ -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(); diff --git a/tools/llvm-ar/ArchiveWriter.cpp b/tools/llvm-ar/ArchiveWriter.cpp index 3656ad4854c..5563b564b39 100644 --- a/tools/llvm-ar/ArchiveWriter.cpp +++ b/tools/llvm-ar/ArchiveWriter.cpp @@ -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 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::iterator SI = symbols.begin(), - SE = symbols.end(); SI != SE; ++SI) { - - std::pair 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 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. diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index fa07b9a9ab8..36bec4206d3 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -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; }