[llvm-commits] CVS: llvm/tools/gccld/Linker.cpp
John Criswell
criswell at cs.uiuc.edu
Tue Dec 23 11:38:02 PST 2003
Changes in directory llvm/tools/gccld:
Linker.cpp updated: 1.19 -> 1.20
---
Log message:
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.
---
Diffs of the changes: (+21 -11)
Index: llvm/tools/gccld/Linker.cpp
diff -u llvm/tools/gccld/Linker.cpp:1.19 llvm/tools/gccld/Linker.cpp:1.20
--- llvm/tools/gccld/Linker.cpp:1.19 Fri Nov 28 01:44:09 2003
+++ llvm/tools/gccld/Linker.cpp Tue Dec 23 11:37:06 2003
@@ -200,17 +200,27 @@
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))
More information about the llvm-commits
mailing list