summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Linker/LinkArchives.cpp13
-rw-r--r--tools/gccld/Linker.cpp13
2 files changed, 14 insertions, 12 deletions
diff --git a/lib/Linker/LinkArchives.cpp b/lib/Linker/LinkArchives.cpp
index ec9f89c5e0..7cd440d1d2 100644
--- a/lib/Linker/LinkArchives.cpp
+++ b/lib/Linker/LinkArchives.cpp
@@ -202,11 +202,14 @@ static bool LinkInArchive(Module *M,
bool ObjectRequired = false;
//
- // If the object defines main(), then it is automatically required.
- // Otherwise, look to see if it defines a symbol that is currently
- // undefined.
+ // If the object defines main() and the program currently has main()
+ // undefined, then automatically link in the module. Otherwise, look to
+ // see if it defines a symbol that is currently undefined.
//
- if ((DefSymbols.find ("main")) == DefSymbols.end()) {
+ if ((M->getMainFunction() == NULL) &&
+ ((DefSymbols.find ("main")) != DefSymbols.end())) {
+ ObjectRequired = true;
+ } else {
for (std::set<std::string>::iterator I = UndefinedSymbols.begin(),
E = UndefinedSymbols.end(); I != E; ++I)
if (DefSymbols.count(*I)) {
@@ -217,8 +220,6 @@ static bool LinkInArchive(Module *M,
ObjectRequired = true;
break;
}
- } else {
- ObjectRequired = true;
}
// We DO need to link this object into the program...
diff --git a/tools/gccld/Linker.cpp b/tools/gccld/Linker.cpp
index ec9f89c5e0..7cd440d1d2 100644
--- a/tools/gccld/Linker.cpp
+++ b/tools/gccld/Linker.cpp
@@ -202,11 +202,14 @@ static bool LinkInArchive(Module *M,
bool ObjectRequired = false;
//
- // If the object defines main(), then it is automatically required.
- // Otherwise, look to see if it defines a symbol that is currently
- // undefined.
+ // If the object defines main() and the program currently has main()
+ // undefined, then automatically link in the module. Otherwise, look to
+ // see if it defines a symbol that is currently undefined.
//
- if ((DefSymbols.find ("main")) == DefSymbols.end()) {
+ if ((M->getMainFunction() == NULL) &&
+ ((DefSymbols.find ("main")) != DefSymbols.end())) {
+ ObjectRequired = true;
+ } else {
for (std::set<std::string>::iterator I = UndefinedSymbols.begin(),
E = UndefinedSymbols.end(); I != E; ++I)
if (DefSymbols.count(*I)) {
@@ -217,8 +220,6 @@ static bool LinkInArchive(Module *M,
ObjectRequired = true;
break;
}
- } else {
- ObjectRequired = true;
}
// We DO need to link this object into the program...