summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-11-15 01:20:11 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-11-15 01:20:11 +0000
commit766b793143fa863283498233e8962391da09b63a (patch)
tree7a344adee85815f8ae6dddff08bed62bf0d5529d /lib
parent6238a85e4f6931a9572e5d327c3ffa7ce1087d50 (diff)
Changes necessary to enable linking of archives without LLVM symbol tables.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17811 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Archive/ArchiveReader.cpp49
-rw-r--r--lib/Archive/ArchiveWriter.cpp33
-rw-r--r--lib/Bytecode/Archive/ArchiveReader.cpp49
-rw-r--r--lib/Bytecode/Archive/ArchiveWriter.cpp33
-rw-r--r--lib/Bytecode/Reader/ReaderWrappers.cpp15
5 files changed, 144 insertions, 35 deletions
diff --git a/lib/Archive/ArchiveReader.cpp b/lib/Archive/ArchiveReader.cpp
index ae1a9330789..794e1b271f3 100644
--- a/lib/Archive/ArchiveReader.cpp
+++ b/lib/Archive/ArchiveReader.cpp
@@ -391,13 +391,58 @@ Archive::findModuleDefiningSymbol(const std::string& symbol) {
// ModuleProviders that define those symbols.
void
Archive::findModulesDefiningSymbols(const std::set<std::string>& symbols,
- std::set<ModuleProvider*>& modules)
+ std::set<ModuleProvider*>& result)
{
+ assert(mapfile && base && "Can't findModulesDefiningSymbols on new archive");
+ if (symTab.empty()) {
+ // We don't have a symbol table, so we must build it now but lets also
+ // make sure that we populate the modules table as we do this to ensure
+ // that we don't load them twice when findModuleDefiningSymbol is called
+ // below.
+
+ // Get a pointer to the first file
+ const char* At = ((const char*)base) + firstFileOffset;
+ const char* End = ((const char*)base) + mapfile->size();
+
+ while ( At < End) {
+ // Compute the offset to be put in the symbol table
+ unsigned offset = At - base - firstFileOffset;
+
+ // Parse the file's header
+ ArchiveMember* mbr = parseMemberHeader(At, End);
+
+ // If it contains symbols
+ if (mbr->isBytecode() || mbr->isCompressedBytecode()) {
+ // Get the symbols
+ std::vector<std::string> symbols;
+ ModuleProvider* MP = GetBytecodeSymbols((const unsigned char*)At,
+ mbr->getSize(), mbr->getPath().get(),symbols);
+
+ if (MP) {
+ // Insert the module's symbols into the symbol table
+ for (std::vector<std::string>::iterator I = symbols.begin(),
+ E=symbols.end(); I != E; ++I ) {
+ symTab.insert(std::make_pair(*I,offset));
+ }
+ // Insert the ModuleProvider and the ArchiveMember into the table of
+ // modules.
+ modules.insert(std::make_pair(offset,std::make_pair(MP,mbr)));
+ } else {
+ throw std::string("Can't parse bytecode member: ") +
+ mbr->getPath().get();
+ }
+ }
+ }
+ }
+
+ // At this point we have a valid symbol table (one way or another) so we
+ // just use it to quickly find the symbols requested.
+
for (std::set<std::string>::const_iterator I=symbols.begin(),
E=symbols.end(); I != E; ++I) {
ModuleProvider* mp = findModuleDefiningSymbol(*I);
if (mp) {
- modules.insert(mp);
+ result.insert(mp);
}
}
}
diff --git a/lib/Archive/ArchiveWriter.cpp b/lib/Archive/ArchiveWriter.cpp
index 727b2bfcdf4..fa4d9e64fde 100644
--- a/lib/Archive/ArchiveWriter.cpp
+++ b/lib/Archive/ArchiveWriter.cpp
@@ -197,19 +197,28 @@ Archive::writeMember(
if (CreateSymbolTable &&
(member.isBytecode() || member.isCompressedBytecode())) {
std::vector<std::string> symbols;
- GetBytecodeSymbols((const unsigned char*)data,fSize,member.getPath().get(),
- symbols);
- 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);
+ ModuleProvider* MP = GetBytecodeSymbols(
+ (const unsigned char*)data,fSize,member.getPath().get(), symbols);
+
+ // If the bytecode parsed successfully
+ if ( MP ) {
+ 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 MP;
+ } else {
+ throw std::string("Can't parse bytecode member: ") +
+ member.getPath().get();
}
}
diff --git a/lib/Bytecode/Archive/ArchiveReader.cpp b/lib/Bytecode/Archive/ArchiveReader.cpp
index ae1a9330789..794e1b271f3 100644
--- a/lib/Bytecode/Archive/ArchiveReader.cpp
+++ b/lib/Bytecode/Archive/ArchiveReader.cpp
@@ -391,13 +391,58 @@ Archive::findModuleDefiningSymbol(const std::string& symbol) {
// ModuleProviders that define those symbols.
void
Archive::findModulesDefiningSymbols(const std::set<std::string>& symbols,
- std::set<ModuleProvider*>& modules)
+ std::set<ModuleProvider*>& result)
{
+ assert(mapfile && base && "Can't findModulesDefiningSymbols on new archive");
+ if (symTab.empty()) {
+ // We don't have a symbol table, so we must build it now but lets also
+ // make sure that we populate the modules table as we do this to ensure
+ // that we don't load them twice when findModuleDefiningSymbol is called
+ // below.
+
+ // Get a pointer to the first file
+ const char* At = ((const char*)base) + firstFileOffset;
+ const char* End = ((const char*)base) + mapfile->size();
+
+ while ( At < End) {
+ // Compute the offset to be put in the symbol table
+ unsigned offset = At - base - firstFileOffset;
+
+ // Parse the file's header
+ ArchiveMember* mbr = parseMemberHeader(At, End);
+
+ // If it contains symbols
+ if (mbr->isBytecode() || mbr->isCompressedBytecode()) {
+ // Get the symbols
+ std::vector<std::string> symbols;
+ ModuleProvider* MP = GetBytecodeSymbols((const unsigned char*)At,
+ mbr->getSize(), mbr->getPath().get(),symbols);
+
+ if (MP) {
+ // Insert the module's symbols into the symbol table
+ for (std::vector<std::string>::iterator I = symbols.begin(),
+ E=symbols.end(); I != E; ++I ) {
+ symTab.insert(std::make_pair(*I,offset));
+ }
+ // Insert the ModuleProvider and the ArchiveMember into the table of
+ // modules.
+ modules.insert(std::make_pair(offset,std::make_pair(MP,mbr)));
+ } else {
+ throw std::string("Can't parse bytecode member: ") +
+ mbr->getPath().get();
+ }
+ }
+ }
+ }
+
+ // At this point we have a valid symbol table (one way or another) so we
+ // just use it to quickly find the symbols requested.
+
for (std::set<std::string>::const_iterator I=symbols.begin(),
E=symbols.end(); I != E; ++I) {
ModuleProvider* mp = findModuleDefiningSymbol(*I);
if (mp) {
- modules.insert(mp);
+ result.insert(mp);
}
}
}
diff --git a/lib/Bytecode/Archive/ArchiveWriter.cpp b/lib/Bytecode/Archive/ArchiveWriter.cpp
index 727b2bfcdf4..fa4d9e64fde 100644
--- a/lib/Bytecode/Archive/ArchiveWriter.cpp
+++ b/lib/Bytecode/Archive/ArchiveWriter.cpp
@@ -197,19 +197,28 @@ Archive::writeMember(
if (CreateSymbolTable &&
(member.isBytecode() || member.isCompressedBytecode())) {
std::vector<std::string> symbols;
- GetBytecodeSymbols((const unsigned char*)data,fSize,member.getPath().get(),
- symbols);
- 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);
+ ModuleProvider* MP = GetBytecodeSymbols(
+ (const unsigned char*)data,fSize,member.getPath().get(), symbols);
+
+ // If the bytecode parsed successfully
+ if ( MP ) {
+ 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 MP;
+ } else {
+ throw std::string("Can't parse bytecode member: ") +
+ member.getPath().get();
}
}
diff --git a/lib/Bytecode/Reader/ReaderWrappers.cpp b/lib/Bytecode/Reader/ReaderWrappers.cpp
index de2fd030e8b..7cdcf64de1e 100644
--- a/lib/Bytecode/Reader/ReaderWrappers.cpp
+++ b/lib/Bytecode/Reader/ReaderWrappers.cpp
@@ -391,26 +391,27 @@ bool llvm::GetBytecodeSymbols(const sys::Path& fName,
}
}
-bool llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
+ModuleProvider*
+llvm::GetBytecodeSymbols(const unsigned char*Buffer, unsigned Length,
const std::string& ModuleID,
std::vector<std::string>& symbols) {
try {
- std::auto_ptr<ModuleProvider>
- AMP(getBytecodeBufferModuleProvider(Buffer, Length, ModuleID));
+ ModuleProvider* MP =
+ getBytecodeBufferModuleProvider(Buffer, Length, ModuleID);
// Get the module from the provider
- Module* M = AMP->releaseModule();
+ Module* M = MP->materializeModule();
// Get the symbols
getSymbols(M, symbols);
// Done with the module
- delete M;
- return true;
+ return MP;
} catch (...) {
- return false;
+ // Fall through
}
+ return 0;
}
// vim: sw=2 ai