On Sat, Sep 19, 2015 at 10:07:04AM -0700, Philip Guenther wrote: > On Sat, Sep 19, 2015 at 9:50 AM, Sebastien Marie <sema...@openbsd.org> wrote: > > 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 > > If you want to use -zdefs when building a shared library, you MUST > include in the link the libraries that it depends on, including libc. >
First, I encountered this problem while building clang. The linking of libclang.so.3.7 use -Wl,-z,defs. For building with it, it would require -lc for several symbols, and the last symbols will be `environ'. If I add `crt0.o' for `environ', it will require `__init' and `main'. I am not sure that I can provide them for linking libclang.so ? > I believe the current behavior is correct and matches other systems. I tested under Linux (debian wheezy) the testcase written before, and I don't have any error like under OpenBSD. $ uname -a Linux srvlinux 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux $ touch test.c $ c++ -Wl,-z,defs -shared -o libtest.so test.c $ ls libtest.so libtest.so $ Thanks. -- Sebastien Marie