diff options
| -rw-r--r-- | lld/include/lld/Core/Resolver.h | 2 | ||||
| -rw-r--r-- | lld/lib/Core/Resolver.cpp | 12 | ||||
| -rw-r--r-- | lld/test/pecoff/entry.test | 13 |
3 files changed, 18 insertions, 9 deletions
diff --git a/lld/include/lld/Core/Resolver.h b/lld/include/lld/Core/Resolver.h index 7ffd3523b50..82b8b7331b4 100644 --- a/lld/include/lld/Core/Resolver.h +++ b/lld/include/lld/Core/Resolver.h @@ -71,7 +71,7 @@ private: /// \brief The main function that iterates over the files to resolve bool resolveUndefines(); void updateReferences(); - void deadStripOptimize(); + bool deadStripOptimize(); bool checkUndefines(bool final); void removeCoalescedAwayAtoms(); void checkDylibSymbolCollisions(); diff --git a/lld/lib/Core/Resolver.cpp b/lld/lib/Core/Resolver.cpp index 8b211cb9a5e..7fdb6f5aa79 100644 --- a/lld/lib/Core/Resolver.cpp +++ b/lld/lib/Core/Resolver.cpp @@ -363,11 +363,11 @@ void Resolver::markLive(const Atom &atom) { // remove all atoms not actually used -void Resolver::deadStripOptimize() { +bool Resolver::deadStripOptimize() { ScopedTask task(getDefaultDomain(), "deadStripOptimize"); // only do this optimization with -dead_strip if (!_context.deadStrip()) - return; + return true; // clear liveness on all atoms _liveAtoms.clear(); @@ -386,10 +386,10 @@ void 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->definition() == Atom::definitionUndefined) { + if (!symAtom || symAtom->definition() == Atom::definitionUndefined) { llvm::errs() << "Dead strip root '" << symAtom->name() << "' is not defined\n"; - return; + return false; } _deadStripRoots.insert(symAtom); } @@ -402,6 +402,7 @@ void 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; } @@ -473,7 +474,8 @@ bool Resolver::resolve() { if (!this->resolveUndefines()) return false; this->updateReferences(); - this->deadStripOptimize(); + if (!this->deadStripOptimize()) + return false; if (this->checkUndefines(false)) { if (!_context.allowRemainingUndefines()) return false; diff --git a/lld/test/pecoff/entry.test b/lld/test/pecoff/entry.test index 76a27309526..e7f5d1f7ee4 100644 --- a/lld/test/pecoff/entry.test +++ b/lld/test/pecoff/entry.test @@ -2,8 +2,15 @@ # Verify that entry atom will not be dead-stripped. # RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj -# RUN: lld -flavor link /mllvm:-debug-only=WriterPECOFF /out:%t.exe \ -# RUN: /subsystem:console /entry:_main /force -- %t.obj >& %t.log -# RUN: FileCheck %s < %t.log +# RUN: lld -flavor link /mllvm:-debug-only=WriterPECOFF /out:%t1.exe \ +# RUN: /subsystem:console /entry:main /force -- %t.obj >& %t1.log +# 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 |

