diff --git a/tools/gccld/gccld.cpp b/tools/gccld/gccld.cpp index c1f430affa4..48fbd8b633d 100644 --- a/tools/gccld/gccld.cpp +++ b/tools/gccld/gccld.cpp @@ -168,31 +168,30 @@ int main(int argc, char **argv, char **envp) { int exitCode = 0; try { - std::string ModuleID("gccld-output"); - std::auto_ptr 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... Libraries.erase(std::unique(Libraries.begin(), Libraries.end()), Libraries.end()); - // Link in all of the files - if (LinkFiles(argv[0], Composite.get(), InputFilenames, Verbose)) - return 1; // Error already printed + // Set up the Composite module. + std::auto_ptr Composite(0); - if (!LinkAsLibrary) - LinkLibraries(argv[0], Composite.get(), Libraries, LibPaths, - Verbose, Native); + if (LinkAsLibrary) { + // Link in only the files, we ignore libraries in this case. + 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. std::string RealBytecodeOutput = OutputFilename; diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp index 31c1812df7b..3512c2a66a3 100644 --- a/tools/llvm-ld/llvm-ld.cpp +++ b/tools/llvm-ld/llvm-ld.cpp @@ -389,29 +389,30 @@ int main(int argc, char **argv, char **envp) { cl::ParseCommandLineOptions(argc, argv, " llvm linker for GCC\n"); sys::PrintStackTraceOnErrorSignal(); - std::string ModuleID("llvm-ld-output"); - std::auto_ptr 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... Libraries.erase(std::unique(Libraries.begin(), Libraries.end()), Libraries.end()); - // Link in all of the files - if (LinkFiles(argv[0], Composite.get(), InputFilenames, Verbose)) - return 1; // Error already printed + // Set up the Composite module. + std::auto_ptr Composite(0); - // Link in all of the libraries next... - if (!LinkAsLibrary) - LinkLibraries(argv[0], Composite.get(), Libraries, LibPaths, - Verbose, Native); + if (LinkAsLibrary) { + // Link in only the files, we ignore libraries in this case. + 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 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(Composite.get());