-
- // A user may specify an ar archive without -l, perhaps because it
- // is not installed as a library. Detect that and link the library.
- if (IsArchive(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link archive '" << Pathname << "'\n";
-
- if (LinkInArchive(HeadModule, Pathname, ErrorMessage, Verbose)) {
- PrintAndReturn(progname, ErrorMessage,
- ": Error linking in archive '" + Pathname + "'");
- return true;
- }
- } else if (IsBytecode(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link bytecode file '" << Pathname << "'\n";
-
- if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
- PrintAndReturn(progname, ErrorMessage,
- ": Error linking in bytecode file '" + Pathname + "'");
- return true;
- }
- }
- }
-
- return false;
-}
-
-/// LinkLibraries - takes the specified library files and links them into the
-/// main bytecode object file.
-///
-/// Inputs:
-/// progname - The name of the program (infamous argv[0]).
-/// HeadModule - The module into which all necessary libraries will be linked.
-/// Libraries - The list of libraries to link into the module.
-/// LibPaths - The list of library paths in which to find libraries.
-/// Verbose - Flags whether verbose messages should be printed.
-/// Native - Flags whether native code is being generated.
-///
-/// Outputs:
-/// HeadModule - The module will have all necessary libraries linked in.
-///
-/// Return value:
-/// FALSE - No error.
-/// TRUE - Error.
-///
-bool LinkLibraries(const char *progname,
- Module *HeadModule,
- const std::vector<std::string> &Libraries,
- const std::vector<std::string> &LibPaths,
- bool Verbose,
- bool Native)
-{
- // String in which to receive error messages.
- std::string ErrorMessage;
-
- for (unsigned i = 0; i < Libraries.size(); ++i) {
- // Determine where this library lives.
- std::string Pathname = FindLib(Libraries[i], LibPaths);
- if (Pathname.empty()) {
- // If the pathname does not exist, then continue to the next one if
- // we're doing a native link and give an error if we're doing a bytecode
- // link.
- if (!Native) {
- PrintAndReturn(progname, "Cannot find library -l" + Libraries[i] + "\n");
- return true;
- }
- }
-
- // A user may specify an ar archive without -l, perhaps because it
- // is not installed as a library. Detect that and link the library.
- if (IsArchive(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link archive '" << Pathname << "' (-l" << Libraries[i] << ")\n";
-
- if (LinkInArchive(HeadModule, Pathname, ErrorMessage, Verbose)) {
- PrintAndReturn(progname, ErrorMessage,
- ": Error linking in archive '" + Pathname + "' (-l" + Libraries[i] + ")");
- return true;
- }
- } else if (IsBytecode(Pathname)) {
- if (Verbose)
- std::cerr << "Trying to link bytecode file '" << Pathname << "' (-l" << Libraries[i] << ")\n";
-
- if (LinkInFile(HeadModule, Pathname, ErrorMessage, Verbose)) {
- PrintAndReturn(progname, ErrorMessage,
- ": error linking in bytecode file '" + Pathname + "' (-l" + Libraries[i] + ")");
- return true;
- }
- }
- }
+
+ // 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);
+
+ // At this point we have two sets of undefined symbols: UndefinedSymbols
+ // which holds the undefined symbols from all the modules, and
+ // NotDefinedByArchive which holds symbols we know the archive doesn't
+ // define. There's no point searching for symbols that we won't find in the
+ // archive so we subtract these sets.
+ set_subtract(UndefinedSymbols, NotDefinedByArchive);
+
+ // If there's no symbols left, no point in continuing to search the
+ // archive.
+ if (UndefinedSymbols.empty())
+ break;
+ } while (CurrentlyUndefinedSymbols != UndefinedSymbols);