I have a static binary linked against GnuTLS, o.a., that fails to run when
built on OpenBSD 5.8. The program appears to crash even before it's able to
start.
I run:
OpenBSD 5.8-current (GENERIC.MP) #0: Fri Oct 9 18:37:33 CEST 2015
re...@ws0001.home.lan:/usr/src/sys/arch/amd64/compile/GENERIC.MP
(built from src.tar.gz of the OpenBSD 5.8 CD with patches 001, 002, 003 and
004 applied)
Since linking GnuTLS is optional for my program I decided to leave it out and
the problem went away. No other libraries appear to cause problems.
To demonstrate the problem I tried to create a program, as small as possible,
statically linked against GnuTLS that shows the failure. I used the following
source/Makefile file, and include some basic output of building/running the
program.
*) source file static_test.c:
#include
int
main(int argc, char **argv)
{
gnutls_global_init();
gnutls_global_deinit();
return (0);
}
*) Makefile:
CFLAGS+=-I/usr/local/include
LDFLAGS+= -L/usr/local/lib
LDADD+= -static
LDADD+= -lgnutls
LDADD+= -liconv -lintl -lz
LDADD+= -lp11-kit -lffi
LDADD+= -ltasn1 -lnettle -lhogweed -lgmp
LDADD+= -lpthread
PROG= static_test
NOMAN=
.include
*) creating it with 'make':
$ make obj
$ make depend
mkdep -a -I/usr/local/include /home/remco/static_test/static_test.c
$ make
cc -O2 -pipe -I/usr/local/include -c /home/remco/static_test/static_test.c
cc -L/usr/local/lib -o static_test static_test.o -static -lgnutls -liconv
-lintl -lz -lp11-kit -lffi -ltasn1 -lnettle -lhogweed -lgmp -lpthread
/usr/local/lib/libgnutls.a(gnutls_ui.o): In function `gnutls_session_get_desc':
gnutls_ui.c:(.text+0xda6): warning: warning: strcpy() is almost always misused,
please use strlcpy()
/usr/local/lib/libgnutls.a(gnutls_str.o): In function `_gnutls_str_cat':
gnutls_str.c:(.text+0x1744): warning: warning: strcat() is almost always
misused, please use strlcat()
/usr/local/lib/libgnutls.a(gnutls_str.o): In function `_gnutls_bin2hex':
gnutls_str.c:(.text+0x8e2): warning: warning: sprintf() is often misused,
please use snprintf()
$ ldd obj/static_test
obj/static_test:
StartEnd Type Open Ref GrpRef Name
0c1b6ceb 0c1b6d5d1000 dlib 10 0
/home/remco/static_test/obj/static_test
$ gdb obj/static_test
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd5.8"...
(gdb) run
Starting program: /home/remco/static_test/obj/static_test
Program received signal SIGSEGV, Segmentation fault.
0x1d8c4d423a6d in _dl_boot_bind ()
(gdb) bt
#0 0x1d8c4d423a6d in _dl_boot_bind ()
#1 0x1d8c4d423669 in __start ()
#2 0x in ?? ()
(gdb) q
The program is running. Exit anyway? (y or n) y
*) creating it with 'env NOPIE=make':
$ make clean
rm -f a.out [Ee]rrs mklog *.core y.tab.h static_test static_test.o
$ env NOPIE= make
cc -O2 -pipe -I/usr/local/include -fno-pie -c
/home/remco/static_test/static_test.c
cc -L/usr/local/lib -nopie -o static_test static_test.o -static -lgnutls
-liconv -lintl -lz -lp11-kit -lffi -ltasn1 -lnettle -lhogweed -lgmp -lpthread
/usr/local/lib/libgnutls.a(gnutls_ui.o): In function `gnutls_session_get_desc':
gnutls_ui.c:(.text+0xda6): warning: warning: strcpy() is almost always misused,
please use strlcpy()
/usr/local/lib/libgnutls.a(gnutls_str.o): In function `_gnutls_str_cat':
gnutls_str.c:(.text+0x1744): warning: warning: strcat() is almost always
misused, please use strlcat()
/usr/local/lib/libgnutls.a(gnutls_str.o): In function `_gnutls_bin2hex':
gnutls_str.c:(.text+0x8e2): warning: warning: sprintf() is often misused,
please use snprintf()
$ ldd obj/static_test
obj/static_test:
not a dynamic executable
$ gdb obj/static_test
GNU gdb 6.3
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "amd64-unknown-openbsd5.8"...
(gdb) run
Starting program: /home/remco/static_test/obj/static_test
Program received signal SIGSEGV, Segmentation fault.
0x in ?? ()
(gdb) bt
#0 0x in ?? ()
#1 0x0055038e in pthread_once (once_control=0xaef050,
init_routine=0x4f5610 ) at
/usr/src/lib/librthread/rthread_once.c:26
#2 0x0040044e in __register_frame_info ()
#3 0x00400536 in atexit ()
#4 0x004002a9 in __init ()
#5 0x in ?? ()
(gdb) q
The