summaryrefslogtreecommitdiff
path: root/tools/llvm-ld/llvm-ld.cpp
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2004-12-05 19:15:29 +0000
committerReid Spencer <rspencer@reidspencer.com>2004-12-05 19:15:29 +0000
commitc191d497d54e42880ea662fff48759f53143f8ed (patch)
tree15e012eb8c6e862878d1aa9e6731a0e029f249f1 /tools/llvm-ld/llvm-ld.cpp
parent8bcd0502a3cad823a1521713b55d577ac0eb20f4 (diff)
downloadllvm-c191d497d54e42880ea662fff48759f53143f8ed.tar.gz
llvm-c191d497d54e42880ea662fff48759f53143f8ed.tar.bz2
llvm-c191d497d54e42880ea662fff48759f53143f8ed.tar.xz
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
Diffstat (limited to 'tools/llvm-ld/llvm-ld.cpp')
-rw-r--r--tools/llvm-ld/llvm-ld.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp
index 31c1812df7..3512c2a66a 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<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...
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
-
- // Link in all of the libraries next...
- if (!LinkAsLibrary)
- LinkLibraries(argv[0], Composite.get(), Libraries, LibPaths,
- Verbose, Native);
+ // Set up the Composite module.
+ std::auto_ptr<Module> Composite(0);
+
+ 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());