- // Loop over all the ModuleProviders that we got back from the archive
- for (std::set<ModuleProvider*>::iterator I=Modules.begin(), E=Modules.end();
- I != E; ++I) {
- // Get the module we must link in.
- Module* aModule = (*I)->releaseModule();
-
- // Link it in
- if (LinkModules(M, aModule, ErrorMessage)) {
- // don't create a memory leak
- delete aModule;
- delete arch;
- return true; // Couldn't link in the right object file...
- }
-
- // Since we have linked in this object, throw it away now.
- delete aModule;
- }
-
- // We have linked in a set of modules determined by the archive to satisfy
- // our missing symbols. Linking in the new modules will have satisfied some
- // symbols but may introduce additional missing symbols. We need to update
- // the list of undefined symbols and try again until the archive doesn't
- // have any modules that satisfy our symbols.
- GetAllUndefinedSymbols(M, UndefinedSymbols);
- }
-
- return false;
-}
-
-/// LinkInFile - opens a bytecode file and links in all objects which
-/// provide symbols that are currently undefined.
-///
-/// Inputs:
-/// HeadModule - The module in which to link the bytecode file.
-/// Filename - The pathname of the bytecode file.
-/// Verbose - Flags whether verbose messages should be printed.
-///
-/// Outputs:
-/// ErrorMessage - A C++ string detailing what error occurred, if any.
-///
-/// Return Value:
-/// TRUE - An error occurred.
-/// FALSE - No errors.
-///
-static bool LinkInFile(Module *HeadModule,
- const std::string &Filename,
- std::string &ErrorMessage,
- bool Verbose)
-{
- std::auto_ptr<Module> M(LoadObject(Filename, ErrorMessage));
- if (M.get() == 0) return true;
- bool Result = LinkModules(HeadModule, M.get(), &ErrorMessage);
- if (Verbose) std::cerr << "Linked in bytecode file '" << Filename << "'\n";
- return Result;
-}
-
-/// LinkFiles - takes a module and a list of files and links them all together.
-/// It locates the file either in the current directory, as its absolute
-/// or relative pathname, or as a file somewhere in LLVM_LIB_SEARCH_PATH.
-///
-/// Inputs:
-/// progname - The name of the program (infamous argv[0]).
-/// HeadModule - The module under which all files will be linked.
-/// Files - A vector of C++ strings indicating the LLVM bytecode filenames
-/// to be linked. The names can refer to a mixture of pure LLVM
-/// bytecode files and archive (ar) formatted files.
-/// Verbose - Flags whether verbose output should be printed while linking.
-///
-/// Outputs:
-/// HeadModule - The module will have the specified LLVM bytecode files linked
-/// in.
-///
-/// Return value:
-/// FALSE - No errors.
-/// TRUE - Some error occurred.
-///
-bool llvm::LinkFiles(const char *progname, Module *HeadModule,
- const std::vector<std::string> &Files, bool Verbose) {
- // String in which to receive error messages.
- std::string ErrorMessage;
-
- // Full pathname of the file
- std::string Pathname;
-
- // Get the library search path from the environment
- char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH");