-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
// and to handle annoying things like static libraries.
//
//===----------------------------------------------------------------------===//
#include "llvm/Linker.h"
#include "llvm/Module.h"
// and to handle annoying things like static libraries.
//
//===----------------------------------------------------------------------===//
#include "llvm/Linker.h"
#include "llvm/Module.h"
// If the program doesn't define a main, try pulling one in from a .a file.
// This is needed for programs where the main function is defined in an
// archive, such f2c'd programs.
// If the program doesn't define a main, try pulling one in from a .a file.
// This is needed for programs where the main function is defined in an
// archive, such f2c'd programs.
UndefinedSymbols.insert("main");
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (I->hasName()) {
UndefinedSymbols.insert("main");
for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
if (I->hasName()) {
assert(!I->hasDLLImportLinkage()
&& "Found dllimported non-external symbol!");
DefinedSymbols.insert(I->getName());
}
}
assert(!I->hasDLLImportLinkage()
&& "Found dllimported non-external symbol!");
DefinedSymbols.insert(I->getName());
}
}
assert(!I->hasDLLImportLinkage()
&& "Found dllimported non-external symbol!");
DefinedSymbols.insert(I->getName());
}
}
assert(!I->hasDLLImportLinkage()
&& "Found dllimported non-external symbol!");
DefinedSymbols.insert(I->getName());
}
}
// Prune out any defined symbols from the undefined symbols set...
for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
I != UndefinedSymbols.end(); )
// Prune out any defined symbols from the undefined symbols set...
for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
I != UndefinedSymbols.end(); )
// If all the symbols are defined, the program is complete, and there is
// no reason to link in any archive files.
std::set<std::string> UndefinedSymbols;
GetAllUndefinedSymbols(Composite, UndefinedSymbols);
if (UndefinedSymbols.empty()) {
// If all the symbols are defined, the program is complete, and there is
// no reason to link in any archive files.
std::set<std::string> UndefinedSymbols;
GetAllUndefinedSymbols(Composite, UndefinedSymbols);
if (UndefinedSymbols.empty()) {
// 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
// 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
- // Find the modules we need to link into the target module
- std::set<ModuleProvider*> Modules;
+ // Find the modules we need to link into the target module. Note that arch
+ // keeps ownership of these modules and may return the same Module* from a
+ // subsequent call.
+ std::set<Module*> Modules;
- // Loop over all the ModuleProviders that we got back from the archive
- for (std::set<ModuleProvider*>::iterator I=Modules.begin(), E=Modules.end();
+ // Loop over all the Modules that we got back from the archive
+ for (std::set<Module*>::iterator I=Modules.begin(), E=Modules.end();
- }
- } 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.
- }