[llvm-commits] CVS: llvm/lib/Linker/LinkArchives.cpp LinkItems.cpp Linker.cpp
Changes in directory llvm/lib/Linker: LinkArchives.cpp updated: 1.57 - 1.58 LinkItems.cpp updated: 1.14 - 1.15 Linker.cpp updated: 1.14 - 1.15 --- Log message: add bitcode support --- Diffs of the changes: (+23 -4) LinkArchives.cpp |1 - LinkItems.cpp|2 ++ Linker.cpp | 24 +--- 3 files changed, 23 insertions(+), 4 deletions(-) Index: llvm/lib/Linker/LinkArchives.cpp diff -u llvm/lib/Linker/LinkArchives.cpp:1.57 llvm/lib/Linker/LinkArchives.cpp:1.58 --- llvm/lib/Linker/LinkArchives.cpp:1.57 Sun Apr 29 19:29:39 2007 +++ llvm/lib/Linker/LinkArchives.cppSun May 6 01:02:13 2007 @@ -16,7 +16,6 @@ #include llvm/Module.h #include llvm/ModuleProvider.h #include llvm/ADT/SetOperations.h -#include llvm/Bytecode/Reader.h #include llvm/Bytecode/Archive.h #include llvm/Config/config.h #include memory Index: llvm/lib/Linker/LinkItems.cpp diff -u llvm/lib/Linker/LinkItems.cpp:1.14 llvm/lib/Linker/LinkItems.cpp:1.15 --- llvm/lib/Linker/LinkItems.cpp:1.14 Sun Apr 29 19:29:39 2007 +++ llvm/lib/Linker/LinkItems.cpp Sun May 6 01:02:13 2007 @@ -83,6 +83,7 @@ return warning(Supposed library ' + Lib + ' isn't a library.); case sys::Bytecode_FileType: +case sys::Bitcode_FileType: case sys::CompressedBytecode_FileType: // LLVM .so file. if (LinkInFile(Pathname, is_native)) @@ -175,6 +176,7 @@ return error(Cannot link archive ' + File.toString() + '); break; +case sys::Bitcode_FileType: case sys::Bytecode_FileType: case sys::CompressedBytecode_FileType: { verbose(Linking bytecode file ' + File.toString() + '); Index: llvm/lib/Linker/Linker.cpp diff -u llvm/lib/Linker/Linker.cpp:1.14 llvm/lib/Linker/Linker.cpp:1.15 --- llvm/lib/Linker/Linker.cpp:1.14 Wed Feb 7 15:41:02 2007 +++ llvm/lib/Linker/Linker.cpp Sun May 6 01:02:13 2007 @@ -14,11 +14,15 @@ #include llvm/Linker.h #include llvm/Module.h #include llvm/Bytecode/Reader.h +#include llvm/Bitcode/ReaderWriter.h #include llvm/Config/config.h +#include llvm/Support/MemoryBuffer.h #include llvm/Support/Streams.h #include llvm/Support/Compressor.h using namespace llvm; +static const bool Bitcode = false; + Linker::Linker(const std::string progname, const std::string modname, unsigned flags) : Composite(0) , LibPaths() @@ -100,9 +104,21 @@ std::auto_ptrModule Linker::LoadObject(const sys::Path FN) { std::string ParseErrorMessage; - Module *Result = ParseBytecodeFile(FN.toString(), - Compressor::decompressToNewBuffer, - ParseErrorMessage); + Module *Result = 0; + + const std::string FNS = FN.toString(); + if (Bitcode) { +std::auto_ptrMemoryBuffer Buffer( + MemoryBuffer::getFileOrSTDIN(FNS[0], FNS.size())); +if (Buffer.get()) + Result = ParseBitcodeFile(Buffer.get(), ParseErrorMessage); +else + ParseErrorMessage = Error reading file ' + FNS + '; + + } else { +Result = ParseBytecodeFile(FNS, Compressor::decompressToNewBuffer, + ParseErrorMessage); + } if (Result) return std::auto_ptrModule(Result); Error = Bytecode file ' + FN.toString() + ' could not be loaded; @@ -137,6 +153,8 @@ return FullPath; if (FullPath.isBytecodeFile())// .so file containing bytecode? return FullPath; + if (FullPath.isBitcodeFile())// .so file containing bitcode? +return FullPath; // Not found .. fall through ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Linker/LinkArchives.cpp LinkItems.cpp
Changes in directory llvm/lib/Linker: LinkArchives.cpp updated: 1.56 - 1.57 LinkItems.cpp updated: 1.13 - 1.14 --- Log message: If an archive is not recognized as an LLVM bytecode archive then declare that it is native so that the linker will pass it on downstream. This avoids a problem where the native link line fails because there is both a .so and a .a file. The .a file gets processed as bytecode and then dropped from the command line. --- Diffs of the changes: (+8 -3) LinkArchives.cpp |7 ++- LinkItems.cpp|4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) Index: llvm/lib/Linker/LinkArchives.cpp diff -u llvm/lib/Linker/LinkArchives.cpp:1.56 llvm/lib/Linker/LinkArchives.cpp:1.57 --- llvm/lib/Linker/LinkArchives.cpp:1.56 Mon Feb 5 15:19:13 2007 +++ llvm/lib/Linker/LinkArchives.cppSun Apr 29 19:29:39 2007 @@ -88,7 +88,7 @@ /// TRUE - An error occurred. /// FALSE - No errors. bool -Linker::LinkInArchive(const sys::Path Filename) { +Linker::LinkInArchive(const sys::Path Filename, bool is_native) { // Make sure this is an archive file we're dealing with if (!Filename.isArchive()) @@ -118,6 +118,11 @@ if (!arch) return error(Cannot read archive ' + Filename.toString() + ': + ErrMsg); + if (!arch-isBytecodeArchive()) { +is_native = true; +return false; + } + is_native = false; // Save a set of symbols that are not defined by the archive. Since we're // entering a loop, there's no point searching for these multiple times. This Index: llvm/lib/Linker/LinkItems.cpp diff -u llvm/lib/Linker/LinkItems.cpp:1.13 llvm/lib/Linker/LinkItems.cpp:1.14 --- llvm/lib/Linker/LinkItems.cpp:1.13 Sun Apr 29 19:00:10 2007 +++ llvm/lib/Linker/LinkItems.cpp Sun Apr 29 19:29:39 2007 @@ -90,7 +90,7 @@ break; case sys::Archive_FileType: - if (LinkInArchive(Pathname)) + if (LinkInArchive(Pathname, is_native)) return error(Cannot link archive ' + Pathname.toString() + '); break; @@ -171,7 +171,7 @@ // A user may specify an ar archive without -l, perhaps because it // is not installed as a library. Detect that and link the archive. verbose(Linking archive file ' + File.toString() + '); - if (LinkInArchive(File)) + if (LinkInArchive(File, is_native)) return error(Cannot link archive ' + File.toString() + '); break; ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/Linker/LinkArchives.cpp LinkItems.cpp
Changes in directory llvm/lib/Linker: LinkArchives.cpp updated: 1.52 - 1.53 LinkItems.cpp updated: 1.8 - 1.9 --- Log message: For PR998: http://llvm.org/PR998 : Fix an infinite loop in the Linker and a few other assorted link problems. Patch contributed by Scott Michel. Thanks, Scott! --- Diffs of the changes: (+30 -16) LinkArchives.cpp | 33 +++-- LinkItems.cpp| 13 +++-- 2 files changed, 30 insertions(+), 16 deletions(-) Index: llvm/lib/Linker/LinkArchives.cpp diff -u llvm/lib/Linker/LinkArchives.cpp:1.52 llvm/lib/Linker/LinkArchives.cpp:1.53 --- llvm/lib/Linker/LinkArchives.cpp:1.52 Thu Nov 2 14:25:49 2006 +++ llvm/lib/Linker/LinkArchives.cppSat Nov 11 05:54:25 2006 @@ -124,8 +124,12 @@ // variable is used to set_subtract from the set of undefined symbols. std::setstd::string NotDefinedByArchive; - // While we are linking in object files, loop. - while (true) { + // Save the current set of undefined symbols, because we may have to make + // multiple passes over the archive: + std::setstd::string CurrentlyUndefinedSymbols; + + do { +CurrentlyUndefinedSymbols = UndefinedSymbols; // Find the modules we need to link into the target module std::setModuleProvider* Modules; @@ -149,17 +153,26 @@ I != E; ++I) { // Get the module we must link in. - std::auto_ptrModule AutoModule( (*I)-releaseModule() ); + std::string moduleErrorMsg; + std::auto_ptrModule AutoModule((*I)-releaseModule( moduleErrorMsg )); Module* aModule = AutoModule.get(); - verbose( Linking in module: + aModule-getModuleIdentifier()); + if (aModule != NULL) { +verbose( Linking in module: + aModule-getModuleIdentifier()); - // Link it in - if (LinkInModule(aModule)) -return error(Cannot link in module ' + - aModule-getModuleIdentifier() + ': + Error); +// Link it in +if (LinkInModule(aModule, moduleErrorMsg)) { + return error(Cannot link in module ' + + aModule-getModuleIdentifier() + ': + moduleErrorMsg); +} + } else { + // (scottm) NOTE: For some reason, Modules.empty() isn't entirely +// accurrate, least with gcc 4.1.2 on Debian and doesn't return true +// when it ought. Consequently, aModule can be NULL -- ignore it for +// the time being, since it seems relatively benign. + } } - + // Get the undefined symbols from the aggregate module. This recomputes the // symbols we still need after the new modules have been linked in. GetAllUndefinedSymbols(Composite, UndefinedSymbols); @@ -175,7 +188,7 @@ // archive. if (UndefinedSymbols.empty()) break; - } + } while (CurrentlyUndefinedSymbols != UndefinedSymbols); return false; } Index: llvm/lib/Linker/LinkItems.cpp diff -u llvm/lib/Linker/LinkItems.cpp:1.8 llvm/lib/Linker/LinkItems.cpp:1.9 --- llvm/lib/Linker/LinkItems.cpp:1.8 Mon Jan 9 21:14:40 2006 +++ llvm/lib/Linker/LinkItems.cpp Sat Nov 11 05:54:25 2006 @@ -32,10 +32,10 @@ I != E; ++I) { if (I-second) { // Link in the library suggested. - bool is_file = true; - if (LinkInLibrary(I-first,is_file)) + bool is_bytecode = true; + if (LinkInLibrary(I-first,is_bytecode)) return true; - if (!is_file) + if (!is_bytecode) NativeItems.push_back(*I); } else { // Link in the file suggested @@ -61,8 +61,8 @@ /// LinkInLibrary - links one library into the HeadModule. /// -bool Linker::LinkInLibrary(const std::string Lib, bool is_file) { - is_file = false; +bool Linker::LinkInLibrary(const std::string Lib, bool is_bytecode) { + is_bytecode = false; // Determine where this library lives. sys::Path Pathname = FindLib(Lib); if (Pathname.isEmpty()) @@ -77,11 +77,12 @@ // LLVM .so file. if (LinkInFile(Pathname)) return error(Cannot link file ' + Pathname.toString() + '); - is_file = true; + is_bytecode = true; break; case sys::ArchiveFileType: if (LinkInArchive(Pathname)) return error(Cannot link archive ' + Pathname.toString() + '); + is_bytecode = true; break; default: return warning(Supposed library ' + Lib + ' isn't a library.); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits