[lld] r192831 - Make undefines check into an assertion.

Rui Ueyama ruiu at google.com
Wed Oct 16 12:21:50 PDT 2013


Author: ruiu
Date: Wed Oct 16 14:21:50 2013
New Revision: 192831

URL: http://llvm.org/viewvc/llvm-project?rev=192831&view=rev
Log:
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.

Modified:
    lld/trunk/include/lld/Core/Resolver.h
    lld/trunk/lib/Core/Resolver.cpp
    lld/trunk/lib/Driver/WinLinkDriver.cpp
    lld/trunk/test/pecoff/entry.test
    lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp

Modified: lld/trunk/include/lld/Core/Resolver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=192831&r1=192830&r2=192831&view=diff
==============================================================================
--- lld/trunk/include/lld/Core/Resolver.h (original)
+++ lld/trunk/include/lld/Core/Resolver.h Wed Oct 16 14:21:50 2013
@@ -71,7 +71,7 @@ private:
   /// \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();

Modified: lld/trunk/lib/Core/Resolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=192831&r1=192830&r2=192831&view=diff
==============================================================================
--- lld/trunk/lib/Core/Resolver.cpp (original)
+++ lld/trunk/lib/Core/Resolver.cpp Wed Oct 16 14:21:50 2013
@@ -363,11 +363,11 @@ void Resolver::markLive(const Atom &atom
 
 
 // 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 @@ bool Resolver::deadStripOptimize() {
   // 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 @@ bool Resolver::deadStripOptimize() {
   // 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 @@ bool Resolver::resolve() {
   if (!this->resolveUndefines())
     return false;
   this->updateReferences();
-  if (!this->deadStripOptimize())
-    return false;
+  this->deadStripOptimize();
   if (this->checkUndefines(false)) {
     if (!_context.allowRemainingUndefines())
       return false;

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=192831&r1=192830&r2=192831&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Wed Oct 16 14:21:50 2013
@@ -501,10 +501,15 @@ WinLinkDriver::parse(int argc, const cha
   // 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

Modified: lld/trunk/test/pecoff/entry.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/entry.test?rev=192831&r1=192830&r2=192831&view=diff
==============================================================================
--- lld/trunk/test/pecoff/entry.test (original)
+++ lld/trunk/test/pecoff/entry.test Wed Oct 16 14:21:50 2013
@@ -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

Modified: lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp?rev=192831&r1=192830&r2=192831&view=diff
==============================================================================
--- lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp (original)
+++ lld/trunk/unittests/DriverTests/WinLinkDriverTest.cpp Wed Oct 16 14:21:50 2013
@@ -224,8 +224,6 @@ TEST_F(WinLinkParserTest, Include) {
   auto symbols = _context.initialUndefinedSymbols();
   EXPECT_FALSE(symbols.empty());
   EXPECT_EQ("foo", symbols[0]);
-  symbols.pop_front();
-  EXPECT_TRUE(symbols.empty());
 }
 
 //





More information about the llvm-commits mailing list