> Date: Sat, 19 Sep 2015 18:50:41 +0200 > From: Sebastien Marie <sema...@openbsd.org> > > Hi, > > While working on building llvm 3.7.0 on openbsd (-current amd64 and > i386), I encounter a problem when linking a shared library, while > -Wl,-z,defs was passed on command-line. > > I build a minimal reproductible testcase: > > $ touch test.c > $ c++ -Wl,-z,defs -shared -o libtest.so test.c > /usr/lib/crtbeginS.o: In function `atexit': > (.text+0x18f): undefined reference to `__cxa_atexit' > collect2: ld returned 1 exit status > > According to ld(1), `-z defs' is: > > > -z keyword > > The recognized keywords are: > > > > defs > > Disallows undefined symbols in object files. Undefined > > symbols > > in shared libraries are still allowed. > > > > ... > > So, as in my case I am building a shared libraries (`-shared'), > according to the documentation, undefined symbols shouldn't be an error > when using `-z defs'. > > Looking at ld code, it seems there are no check for "Undefined symbols > in shared libraries are still allowed". So I added this check: if it was > request to ignore unresolved symbols in a shared library, and we are in > a shared library, skip the error. > > The check mainly copies the one just before for unresolved symbols in > objects. > > If the patch corrects my problem, I don't known enough ld(1) to be sure > it doesn't break something else. > > Comments ? OK ?
That isn't really correct. Your example links fine if you do: $ c++ -Wl,-z,defs -shared -o libtest.so test.c -lc it succeeds. The "problem" here is that our system compiler doesn't link shared libraries against libc. This is incompatible with -z defs.