Fix PR139:\

When not linking as a library, use LinkItems to retain command line order of \
linking, otherwise use LinkFiles


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18549 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Reid Spencer 2004-12-05 19:15:29 +00:00
parent 8bcd0502a3
commit c191d497d5
2 changed files with 37 additions and 37 deletions

View File

@ -168,31 +168,30 @@ int main(int argc, char **argv, char **envp) {
int exitCode = 0; int exitCode = 0;
try { try {
std::string ModuleID("gccld-output");
std::auto_ptr<Module> Composite(new Module(ModuleID));
// We always look first in the current directory when searching for
// libraries.
LibPaths.insert(LibPaths.begin(), ".");
// If the user specified an extra search path in their environment, respect
// it.
if (char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH"))
LibPaths.push_back(SearchPath);
// Remove any consecutive duplicates of the same library... // Remove any consecutive duplicates of the same library...
Libraries.erase(std::unique(Libraries.begin(), Libraries.end()), Libraries.erase(std::unique(Libraries.begin(), Libraries.end()),
Libraries.end()); Libraries.end());
// Link in all of the files // Set up the Composite module.
if (LinkFiles(argv[0], Composite.get(), InputFilenames, Verbose)) std::auto_ptr<Module> Composite(0);
return 1; // Error already printed
if (!LinkAsLibrary) if (LinkAsLibrary) {
LinkLibraries(argv[0], Composite.get(), Libraries, LibPaths, // Link in only the files, we ignore libraries in this case.
Verbose, Native); Composite.reset( new Module(argv[0]) );
if (LinkFiles(argv[0], Composite.get(), InputFilenames, Verbose))
return 1; // Error already printed
} else {
// Build a list of the items from our command line
LinkItemList Items;
BuildLinkItems(Items, InputFilenames, Libraries);
// Link in all of the libraries next... // Link all the items together
Composite.reset( LinkItems(argv[0], Items, LibPaths, Verbose, Native) );
// Check for an error during linker
if (!Composite.get())
return 1; // Error already printed
}
// Create the output file. // Create the output file.
std::string RealBytecodeOutput = OutputFilename; std::string RealBytecodeOutput = OutputFilename;

View File

@ -389,29 +389,30 @@ int main(int argc, char **argv, char **envp) {
cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n"); cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n");
sys::PrintStackTraceOnErrorSignal(); sys::PrintStackTraceOnErrorSignal();
std::string ModuleID("llvm-ld-output");
std::auto_ptr<Module> Composite(new Module(ModuleID));
// We always look first in the current directory when searching for libraries.
LibPaths.insert(LibPaths.begin(), ".");
// If the user specified an extra search path in their environment, respect
// it.
if (char *SearchPath = getenv("LLVM_LIB_SEARCH_PATH"))
LibPaths.push_back(SearchPath);
// Remove any consecutive duplicates of the same library... // Remove any consecutive duplicates of the same library...
Libraries.erase(std::unique(Libraries.begin(), Libraries.end()), Libraries.erase(std::unique(Libraries.begin(), Libraries.end()),
Libraries.end()); Libraries.end());
// Link in all of the files // Set up the Composite module.
if (LinkFiles(argv[0], Composite.get(), InputFilenames, Verbose)) std::auto_ptr<Module> Composite(0);
return 1; // Error already printed
// Link in all of the libraries next... if (LinkAsLibrary) {
if (!LinkAsLibrary) // Link in only the files, we ignore libraries in this case.
LinkLibraries(argv[0], Composite.get(), Libraries, LibPaths, Composite.reset( new Module(argv[0]) );
Verbose, Native); if (LinkFiles(argv[0], Composite.get(), InputFilenames, Verbose))
return 1; // Error already printed
} else {
// Build a list of the items from our command line
LinkItemList Items;
BuildLinkItems(Items, InputFilenames, Libraries);
// Link all the items together
Composite.reset( LinkItems(argv[0], Items, LibPaths, Verbose, Native) );
// Check for an error during linker
if (!Composite.get())
return 1; // Error already printed
}
// Optimize the module // Optimize the module
Optimize(Composite.get()); Optimize(Composite.get());