Hi,
I'm having a strange issue on 5.8 regarding compiling -static binaries.
In short, unless I specify -nopie for a particular statically-linked
binary, it segfaults. Am I making a mistake, maybe, in my compilation?
First, uname -a:
OpenBSD xxx 5.8 GENERIC#1170 amd64
All of the packages are up to date. Usual bsd.rd install process.
The binary in question is linked as follows in the usual case, where
$(OBJS) is a list of .o's and .a's. All of the -l libraries are from
packages except for -lkcgi and -lkcgijson, which are static libraries.
(I have other -static binaries compiled with these that work just fine.)
The binary in question is . The objects
are compiled without any special flags. Linking...
% cc -L/usr/local/lib -o admin $(OBJS) -lsqlite3 -lkcgi -lkcgijson -lz
-lgmp -lexpat `curl-config --libs` -lintl -liconv -lm
(curl-config --libs => -L/usr/local/lib -lcurl -lidn -lssl -lcrypto
-lssl -lcrypto -lz)
% ldd ./admin
./admin:
StartEnd Type Open Ref GrpRef Name
19e7ed30 19e7ed72c000 exe 1 0 0 ./admin
19eac365f000 19eac3b36000 rlib 0 1 0 /usr/lib/libsqlite3.so.30.1
19ea1a989000 19ea1ad9e000 rlib 0 2 0 /usr/lib/libz.so.5.0
19ea95ad4000 19ea95f41000 rlib 0 1 0 /usr/local/lib/libgmp.so.9.0
19ea6ff29000 19ea7034e000 rlib 0 1 0 /usr/lib/libexpat.so.11.0
19eaebd87000 19eaec1ea000 rlib 0 1 0 /usr/local/lib/libcurl.so.24.9
19ea4eee4000 19ea4f317000 rlib 0 2 0 /usr/local/lib/libidn.so.17.2
19eadb56f000 19eadb9cf000 rlib 0 2 0 /usr/lib/libssl.so.35.0
19eab1128000 19eab16f8000 rlib 0 3 0 /usr/lib/libcrypto.so.35.0
19ea48539000 19ea48943000 rlib 0 3 0 /usr/local/lib/libintl.so.6.0
19ea02859000 19ea02d57000 rlib 0 4 0 /usr/local/lib/libiconv.so.6.0
19ea8268 19ea82aa8000 rlib 0 1 0 /usr/lib/libm.so.9.0
19eadfa7f000 19eadff59000 rlib 0 1 0 /usr/lib/libc.so.80.1
19ea03e0 19ea03e0 rtld 0 1 0 /usr/libexec/ld.so
If I run the dynamically-linked binary, everything's fine.
Then I try the same, but linking with -static:
% cc -static -L/usr/local/lib -o admin ...
Now,
% ./admin
Segmentation fault (core dumped)
% gdb ./admin
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: ./admin
Program received signal SIGSEGV, Segmentation fault.
0x0f92a5b46ced in _dl_boot_bind ()
(gdb) bt
#0 0x0f92a5b46ced in _dl_boot_bind ()
#1 0x0f92a5b468e9 in __start ()
#2 0x in ?? ()
And...
% ktrace -di -t einstuw ./admin
Segmentation fault (core dumped)
% kdump
29725 EMUL "native"
29725 ktrace NAMI "./admin"
29725 EMUL "native"
29725 adminPSIG SIGSEGV SIG_DFL code SEGV_MAPERR<1>
addr=0x8dfcbd00469 trapno=6
29725 adminNAMI "admin.core"
29725 adminCSW stop kernel
29725 adminCSW resume kernel
29725 adminCSW stop kernel
29725 adminCSW resume kernel
However, if I link with "-static -nopie", everything works fine. (I
didn't do -fno-pie for the objects, just -nopie after -static.)
I have other binaries that are compiled with `-static' (w/o -nopie) and
they work just fine. Are one of the packages in the ldd output above
perhaps not compiled with the correct magic?
Best,
Kristaps