<div dir="ltr">Hi Scott,<div><br></div><div>I think you are saying that lld doesn't report an error for undefined symbols that exist in a .so which cannot be resolved at link-time. That's intentional. Trying to resolve undefined symbols in a .so at link-time doesn't make sense because we can just link fine without resolving such symbols, and the static linker doesn't really know whether it's actually an error condition or not. The real failure could only happen at load-time when the undefined symbols cannot be resolved using other DSOs. So we do not care about undefined symbols in DSOs in most cases.<div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 11, 2017 at 3:39 PM, Scott Smith via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I have a test case where lld-5.0 fails to detect an undefined symbol (this bug also happens with clang/lld 4.0).  I haven't narrowed down exactly all the circumstances when this can occur, but in this case it was for a virtual method in a class defined in a shared library.  If I build the executable with the raw object files, the linker notices the missing method (see test1 vs test2).  This was tested on Ubuntu 14.04 using the llvm/clang-5.0 downloaded from the official apt repository.</div><div><br></div><div>If I use gold (from binutils 2.26), it finds the error during link time.<br></div><div><br></div><div><br></div><div>********** DEMO OUTPUT<br></div><div>$ make clean && make<br>rm -f main.o virtual.o virtual.so test1 test2<br>clang++-5.0 -fPIC -c main.cc<br>clang++-5.0 -fPIC -c virtual.cc<br>clang++-5.0 -fPIC -fuse-ld=lld-5.0 -shared -o virtual.so virtual.o<br>clang++-5.0 -fPIC -fuse-ld=lld-5.0 -Wl,-R$ORIGIN. -o test1 main.o virtual.so<br>clang++-5.0 -fPIC -fuse-ld=lld-5.0 -Wl,-R$ORIGIN. -o test2 main.o virtual.o<br>/usr/bin/ld.lld-5.0: error: undefined symbol: foo::bar()<br>>>> referenced by virtual.cc<br>>>>               virtual.o:(vtable for foo)<br>clang: error: linker command failed with exit code 1 (use -v to see invocation)<br>make: *** [test2] Error 1</div><div><br></div><div>Note that running test1 results in an error:</div><div>$ ./test1<br>./test1: symbol lookup error: ./virtual.so: undefined symbol: _ZN3foo3barEv<br><br></div><div>********** CODE main.cc<br></div><div>#include "virtual.h"<br>int main() {<br>        foo baz;<br>        return 0;<br>}<br></div><div><br></div><div>********** CODE virtual.h</div><div>struct foo {<br>        virtual ~foo();<br>        virtual void bar();<br>};<br></div><div><br></div><div>********** CODE virtual.cc</div><div>#include "virtual.h"<br>foo::~foo() { }<br></div><div><br></div><div>********* CODE Makefile</div><div>all: test1 test2<br><br>CC = clang++-5.0 -fPIC<br>LD = ${CC} -fuse-ld=lld-5.0<br><br>test1: main.o virtual.so<br>    ${LD} -Wl,-R$$ORIGIN. -o test1 main.o virtual.so<br><br>test2: main.o virtual.o<br>    ${LD} -Wl,-R$$ORIGIN. -o test2 main.o virtual.o<br><br>virtual.o: virtual.cc virtual.h<br>    ${CC} -c virtual.cc<br><br>virtual.so: virtual.o<br>    ${LD} -shared -o virtual.so virtual.o<br><br>main.o: main.cc virtual.h<br>    ${CC} -c main.cc<br><br>clean:<br>    rm -f main.o virtual.o virtual.so test1 test2<br></div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div></div></div>