diff options
| author | John Criswell <criswell@uiuc.edu> | 2003-12-23 17:37:06 +0000 |
|---|---|---|
| committer | John Criswell <criswell@uiuc.edu> | 2003-12-23 17:37:06 +0000 |
| commit | b6d3cb944939c337a658a5f6414491ba8a6c8774 (patch) | |
| tree | c984196f0b1f1a2213bcc4f46378368659051dd2 /llvm/tools/gccld | |
| parent | bd03ac85676252a935c67efb7a74096a81c712db (diff) | |
| download | bcm5719-llvm-b6d3cb944939c337a658a5f6414491ba8a6c8774.tar.gz bcm5719-llvm-b6d3cb944939c337a658a5f6414491ba8a6c8774.zip | |
Modified the linker so that it always links in an object from an archive
that defines the symbol "main." This is a hack that ensures that programs
that place their main function in a library and then link it in
(i.e. Apache 2.x) get their main function linked in.
There is probably a more correct way to do this, but this works for now.
llvm-svn: 10594
Diffstat (limited to 'llvm/tools/gccld')
| -rw-r--r-- | llvm/tools/gccld/Linker.cpp | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/llvm/tools/gccld/Linker.cpp b/llvm/tools/gccld/Linker.cpp index c230206d7e0..ec9f89c5e06 100644 --- a/llvm/tools/gccld/Linker.cpp +++ b/llvm/tools/gccld/Linker.cpp @@ -200,17 +200,27 @@ static bool LinkInArchive(Module *M, const std::set<std::string> &DefSymbols = DefinedSymbols[i]; bool ObjectRequired = false; - for (std::set<std::string>::iterator I = UndefinedSymbols.begin(), - E = UndefinedSymbols.end(); I != E; ++I) - if (DefSymbols.count(*I)) { - if (Verbose) - std::cerr << " Found object '" - << Objects[i]->getModuleIdentifier () - << "' providing symbol '" << *I << "'...\n"; - ObjectRequired = true; - break; - } - + + // + // If the object defines main(), then it is automatically required. + // Otherwise, look to see if it defines a symbol that is currently + // undefined. + // + if ((DefSymbols.find ("main")) == DefSymbols.end()) { + for (std::set<std::string>::iterator I = UndefinedSymbols.begin(), + E = UndefinedSymbols.end(); I != E; ++I) + if (DefSymbols.count(*I)) { + if (Verbose) + std::cerr << " Found object '" + << Objects[i]->getModuleIdentifier () + << "' providing symbol '" << *I << "'...\n"; + ObjectRequired = true; + break; + } + } else { + ObjectRequired = true; + } + // We DO need to link this object into the program... if (ObjectRequired) { if (LinkModules(M, Objects[i], &ErrorMessage)) |

