Make undefines check into an assertion.

Dead-strip root symbols can be undefined atoms, but should not really be
nonexistent, because dead-strip root symbols should be added to initial
undefined atoms at startup. Whenever you look up its name in the symbol
table, some type of atom will always exist.

llvm-svn: 192831
diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h
index 82b8b73..7ffd352 100644
--- a/lld/include/lld/Core/Resolver.h
+++ b/lld/include/lld/Core/Resolver.h
@@ -71,7 +71,7 @@
   /// \brief The main function that iterates over the files to resolve
   bool resolveUndefines();
   void updateReferences();
-  bool deadStripOptimize();
+  void deadStripOptimize();
   bool checkUndefines(bool final);
   void removeCoalescedAwayAtoms();
   void checkDylibSymbolCollisions();
diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp
index 7fdb6f5..3a34cd3 100644
--- a/lld/lib/Core/Resolver.cpp
+++ b/lld/lib/Core/Resolver.cpp
@@ -363,11 +363,11 @@
 
 
 // remove all atoms not actually used
-bool Resolver::deadStripOptimize() {
+void Resolver::deadStripOptimize() {
   ScopedTask task(getDefaultDomain(), "deadStripOptimize");
   // only do this optimization with -dead_strip
   if (!_context.deadStrip())
-    return true;
+    return;
 
   // clear liveness on all atoms
   _liveAtoms.clear();
@@ -386,11 +386,11 @@
   // Or, use list of names that are dead stip roots.
   for (const StringRef &name : _context.deadStripRoots()) {
     const Atom *symAtom = _symbolTable.findByName(name);
-    if (!symAtom || symAtom->definition() == Atom::definitionUndefined) {
-      llvm::errs() << "Dead strip root '" << symAtom->name()
-                   << "' is not defined\n";
-      return false;
-    }
+    assert(symAtom);
+    if (symAtom->definition() == Atom::definitionUndefined)
+      // Dead-strip root atoms can be undefined at this point only when
+      // allowUndefines flag is on. Skip such undefines.
+      continue;
     _deadStripRoots.insert(symAtom);
   }
 
@@ -402,7 +402,6 @@
   // now remove all non-live atoms from _atoms
   _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(),
                               NotLive(_liveAtoms)), _atoms.end());
-  return true;
 }
 
 
@@ -474,8 +473,7 @@
   if (!this->resolveUndefines())
     return false;
   this->updateReferences();
-  if (!this->deadStripOptimize())
-    return false;
+  this->deadStripOptimize();
   if (this->checkUndefines(false)) {
     if (!_context.allowRemainingUndefines())
       return false;
diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp
index 0c9f177..644fc0a 100644
--- a/lld/lib/Driver/WinLinkDriver.cpp
+++ b/lld/lib/Driver/WinLinkDriver.cpp
@@ -501,10 +501,15 @@
   // symbols given by /include to the dead strip root set, so that it
   // won't be removed from the output.
   if (ctx.deadStrip()) {
-    if (!ctx.entrySymbolName().empty())
-      ctx.addDeadStripRoot(ctx.entrySymbolName());
-    for (const StringRef symbolName : ctx.initialUndefinedSymbols())
+    StringRef entry = ctx.entrySymbolName();
+    if (!entry.empty()) {
+      ctx.addInitialUndefinedSymbol(entry);
+      ctx.addDeadStripRoot(entry);
+    }
+    for (const StringRef symbolName : ctx.initialUndefinedSymbols()) {
+      ctx.addInitialUndefinedSymbol(entry);
       ctx.addDeadStripRoot(symbolName);
+    }
   }
 
   // Arguments after "--" are interpreted as filenames even if they
diff --git a/lld/test/pecoff/entry.test b/lld/test/pecoff/entry.test
index e7f5d1f..deee5ed 100644
--- a/lld/test/pecoff/entry.test
+++ b/lld/test/pecoff/entry.test
@@ -7,10 +7,3 @@
 # RUN: FileCheck -check-prefix=CHECK %s < %t1.log
 
 CHECK: : _main
-
-
-# RUN: not lld -flavor link /out:%t2.exe /subsystem:console \
-# RUN:    /entry:no_such_symbol /force -- %t.obj >& %t2.log
-# RUN: FileCheck -check-prefix=FAIL %s < %t2.log
-
-FAIL: Dead strip root '_no_such_symbol' is not defined
diff --git a/lld/unittests/DriverTests/WinLinkDriverTest.cpp b/lld/unittests/DriverTests/WinLinkDriverTest.cpp
index 9f801de..56cc487 100644
--- a/lld/unittests/DriverTests/WinLinkDriverTest.cpp
+++ b/lld/unittests/DriverTests/WinLinkDriverTest.cpp
@@ -224,8 +224,6 @@
   auto symbols = _context.initialUndefinedSymbols();
   EXPECT_FALSE(symbols.empty());
   EXPECT_EQ("foo", symbols[0]);
-  symbols.pop_front();
-  EXPECT_TRUE(symbols.empty());
 }
 
 //