summaryrefslogtreecommitdiff
path: root/tools/llvm-ld
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2006-11-11 11:54:25 +0000
committerReid Spencer <rspencer@reidspencer.com>2006-11-11 11:54:25 +0000
commit4952143236afe43b974798c45ed265bb175c9d7f (patch)
tree3b5e0e979f39154d18b36fbb5ee60ef323650393 /tools/llvm-ld
parent44e2f8f9fae4a7d960390eb486eaedd38ea0ce51 (diff)
downloadllvm-4952143236afe43b974798c45ed265bb175c9d7f.tar.gz
llvm-4952143236afe43b974798c45ed265bb175c9d7f.tar.bz2
llvm-4952143236afe43b974798c45ed265bb175c9d7f.tar.xz
For PR998:
Fix an infinite loop in the Linker and a few other assorted link problems. Patch contributed by Scott Michel. Thanks, Scott! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31680 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-ld')
-rw-r--r--tools/llvm-ld/llvm-ld.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/tools/llvm-ld/llvm-ld.cpp b/tools/llvm-ld/llvm-ld.cpp
index 60fe746b7a..d96494ad33 100644
--- a/tools/llvm-ld/llvm-ld.cpp
+++ b/tools/llvm-ld/llvm-ld.cpp
@@ -264,7 +264,7 @@ static int GenerateCFile(const std::string &OutputFile,
/// Inputs:
/// InputFilename - The name of the input bytecode file.
/// OutputFilename - The name of the file to generate.
-/// Libraries - The list of libraries with which to link.
+/// LinkItems - The native libraries, files, code with which to link
/// LibPaths - The list of directories in which to find libraries.
/// gcc - The pathname to use for GGC.
/// envp - A copy of the process's current environment.
@@ -276,7 +276,7 @@ static int GenerateCFile(const std::string &OutputFile,
///
static int GenerateNative(const std::string &OutputFilename,
const std::string &InputFilename,
- const std::vector<std::string> &Libraries,
+ const Linker::ItemList &LinkItems,
const sys::Path &gcc, char ** const envp,
std::string& ErrMsg) {
// Remove these environment variables from the environment of the
@@ -323,10 +323,13 @@ static int GenerateNative(const std::string &OutputFilename,
}
// Add in the libraries to link.
- for (unsigned index = 0; index < Libraries.size(); index++)
- if (Libraries[index] != "crtend") {
- args.push_back("-l");
- args.push_back(Libraries[index].c_str());
+ for (unsigned index = 0; index < LinkItems.size(); index++)
+ if (LinkItems[index].first != "crtend") {
+ if (LinkItems[index].second) {
+ std::string lib_name = "-l" + LinkItems[index].first;
+ args.push_back(lib_name.c_str());
+ } else
+ args.push_back(LinkItems[index].first.c_str());
}
args.push_back(0);
@@ -433,13 +436,17 @@ int main(int argc, char **argv, char **envp) {
try {
// Initial global variable above for convenience printing of program name.
progname = sys::Path(argv[0]).getBasename();
- Linker TheLinker(progname, OutputFilename, Verbose);
// Parse the command line options
cl::ParseCommandLineOptions(argc, argv, " llvm linker\n");
sys::PrintStackTraceOnErrorSignal();
- // Set up the library paths for the Linker
+ // Construct a Linker (now that Verbose is set)
+ Linker TheLinker(progname, OutputFilename, Verbose);
+ // Keep track of the native link items (vice the bytecode items)
+ Linker::ItemList LinkItems;
+
+ // Add library paths to the linker
TheLinker.addPaths(LibPaths);
TheLinker.addSystemPaths();
@@ -463,11 +470,10 @@ int main(int argc, char **argv, char **envp) {
} else {
// Build a list of the items from our command line
Linker::ItemList Items;
- Linker::ItemList NativeItems;
BuildLinkItems(Items, InputFilenames, Libraries);
// Link all the items together
- if (TheLinker.LinkInItems(Items,NativeItems) )
+ if (TheLinker.LinkInItems(Items,LinkItems) )
return 1;
}
@@ -558,7 +564,7 @@ int main(int argc, char **argv, char **envp) {
if (Verbose) std::cout << "Generating Native Code\n";
if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
- Libraries,gcc,envp,ErrMsg)) {
+ LinkItems,gcc,envp,ErrMsg)) {
std::cerr << argv[0] << ": " << ErrMsg << "\n";
return 1;
}
@@ -592,7 +598,7 @@ int main(int argc, char **argv, char **envp) {
}
if (Verbose) std::cout << "Generating Native Code\n";
- if (0 != GenerateNative(OutputFilename, CFile.toString(), Libraries,
+ if (0 != GenerateNative(OutputFilename, CFile.toString(), LinkItems,
gcc, envp, ErrMsg)) {
std::cerr << argv[0] << ": " << ErrMsg << "\n";
return 1;