<div dir="ltr">That is a good point. Looks like I forgot to call addInitialUndefinedSymbol() in the link.exe-compatible driver. Only addDeadStrip() is called on an entry point symbol, but addInitialUndefinedSymbol() was never called on the same symbol.<div>

<br></div><div>This reminds me of the discussion that addInitialUndefinedSymbol() should add a given symbol to the dead strip root. I remember I claimed it should do but it was pushed back. It seems that not doing that does not make much sense, and proven to be error prone :/, so we should do that now.</div>

</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Oct 16, 2013 at 10:26 AM, Nick Kledzik <span dir="ltr"><<a href="mailto:kledzik@apple.com" target="_blank">kledzik@apple.com</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">The entry point should also be added to the list of initial undefines.  If it turns out to be never defined, then that undefined symbol will cause the link to error out.  Adding to the undefined list is also necessary if the entry is to be pulled out of an archive.<br>


<br>
Give that, is this change necessary?<br>
<span class="HOEnZb"><font color="#888888"><br>
-Nick<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Oct 15, 2013, at 10:03 PM, Rui Ueyama wrote:<br>
> Author: ruiu<br>
> Date: Wed Oct 16 00:03:39 2013<br>
> New Revision: 192771<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=192771&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=192771&view=rev</a><br>
> Log:<br>
> Propagate deadStripOptimize()'s failure to the caller.<br>
><br>
> We want to make the program to exit with non-zero exit code if there's an error<br>
> during dead stripping.<br>
><br>
> Modified:<br>
>    lld/trunk/include/lld/Core/Resolver.h<br>
>    lld/trunk/lib/Core/Resolver.cpp<br>
>    lld/trunk/test/pecoff/entry.test<br>
><br>
> Modified: lld/trunk/include/lld/Core/Resolver.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=192771&r1=192770&r2=192771&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Core/Resolver.h?rev=192771&r1=192770&r2=192771&view=diff</a><br>


> ==============================================================================<br>
> --- lld/trunk/include/lld/Core/Resolver.h (original)<br>
> +++ lld/trunk/include/lld/Core/Resolver.h Wed Oct 16 00:03:39 2013<br>
> @@ -71,7 +71,7 @@ private:<br>
>   /// \brief The main function that iterates over the files to resolve<br>
>   bool resolveUndefines();<br>
>   void updateReferences();<br>
> -  void deadStripOptimize();<br>
> +  bool deadStripOptimize();<br>
>   bool checkUndefines(bool final);<br>
>   void removeCoalescedAwayAtoms();<br>
>   void checkDylibSymbolCollisions();<br>
><br>
> Modified: lld/trunk/lib/Core/Resolver.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=192771&r1=192770&r2=192771&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/Resolver.cpp?rev=192771&r1=192770&r2=192771&view=diff</a><br>


> ==============================================================================<br>
> --- lld/trunk/lib/Core/Resolver.cpp (original)<br>
> +++ lld/trunk/lib/Core/Resolver.cpp Wed Oct 16 00:03:39 2013<br>
> @@ -363,11 +363,11 @@ void Resolver::markLive(const Atom &atom<br>
><br>
><br>
> // remove all atoms not actually used<br>
> -void Resolver::deadStripOptimize() {<br>
> +bool Resolver::deadStripOptimize() {<br>
>   ScopedTask task(getDefaultDomain(), "deadStripOptimize");<br>
>   // only do this optimization with -dead_strip<br>
>   if (!_context.deadStrip())<br>
> -    return;<br>
> +    return true;<br>
><br>
>   // clear liveness on all atoms<br>
>   _liveAtoms.clear();<br>
> @@ -386,10 +386,10 @@ void Resolver::deadStripOptimize() {<br>
>   // Or, use list of names that are dead stip roots.<br>
>   for (const StringRef &name : _context.deadStripRoots()) {<br>
>     const Atom *symAtom = _symbolTable.findByName(name);<br>
> -    if (symAtom->definition() == Atom::definitionUndefined) {<br>
> +    if (!symAtom || symAtom->definition() == Atom::definitionUndefined) {<br>
>       llvm::errs() << "Dead strip root '" << symAtom->name()<br>
>                    << "' is not defined\n";<br>
> -      return;<br>
> +      return false;<br>
>     }<br>
>     _deadStripRoots.insert(symAtom);<br>
>   }<br>
> @@ -402,6 +402,7 @@ void Resolver::deadStripOptimize() {<br>
>   // now remove all non-live atoms from _atoms<br>
>   _atoms.erase(std::remove_if(_atoms.begin(), _atoms.end(),<br>
>                               NotLive(_liveAtoms)), _atoms.end());<br>
> +  return true;<br>
> }<br>
><br>
><br>
> @@ -473,7 +474,8 @@ bool Resolver::resolve() {<br>
>   if (!this->resolveUndefines())<br>
>     return false;<br>
>   this->updateReferences();<br>
> -  this->deadStripOptimize();<br>
> +  if (!this->deadStripOptimize())<br>
> +    return false;<br>
>   if (this->checkUndefines(false)) {<br>
>     if (!_context.allowRemainingUndefines())<br>
>       return false;<br>
><br>
> Modified: lld/trunk/test/pecoff/entry.test<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/entry.test?rev=192771&r1=192770&r2=192771&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/entry.test?rev=192771&r1=192770&r2=192771&view=diff</a><br>


> ==============================================================================<br>
> --- lld/trunk/test/pecoff/entry.test (original)<br>
> +++ lld/trunk/test/pecoff/entry.test Wed Oct 16 00:03:39 2013<br>
> @@ -2,8 +2,15 @@<br>
> # Verify that entry atom will not be dead-stripped.<br>
><br>
> # RUN: yaml2obj %p/Inputs/main.obj.yaml > %t.obj<br>
> -# RUN: lld -flavor link /mllvm:-debug-only=WriterPECOFF /out:%t.exe \<br>
> -# RUN:   /subsystem:console /entry:_main /force -- %t.obj >& %t.log<br>
> -# RUN: FileCheck %s < %t.log<br>
> +# RUN: lld -flavor link /mllvm:-debug-only=WriterPECOFF /out:%t1.exe \<br>
> +# RUN:   /subsystem:console /entry:main /force -- %t.obj >& %t1.log<br>
> +# RUN: FileCheck -check-prefix=CHECK %s < %t1.log<br>
><br>
> CHECK: : _main<br>
> +<br>
> +<br>
> +# RUN: not lld -flavor link /out:%t2.exe /subsystem:console \<br>
> +# RUN:    /entry:no_such_symbol /force -- %t.obj >& %t2.log<br>
> +# RUN: FileCheck -check-prefix=FAIL %s < %t2.log<br>
> +<br>
> +FAIL: Dead strip root '_no_such_symbol' is not defined<br>
><br>
><br>
> _______________________________________________<br>
> llvm-commits mailing list<br>
> <a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br>
</div></div></blockquote></div><br></div>