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 xxxxxxxxxxx 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 <github.com/kristapsdz/gamelab>.  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:
Start            End              Type Open Ref GrpRef Name
000019e7ed300000 000019e7ed72c000 exe  1 0 0 ./admin
000019eac365f000 000019eac3b36000 rlib 0 1 0 /usr/lib/libsqlite3.so.30.1
000019ea1a989000 000019ea1ad9e000 rlib 0 2 0 /usr/lib/libz.so.5.0
000019ea95ad4000 000019ea95f41000 rlib 0 1 0 /usr/local/lib/libgmp.so.9.0
000019ea6ff29000 000019ea7034e000 rlib 0 1 0 /usr/lib/libexpat.so.11.0
000019eaebd87000 000019eaec1ea000 rlib 0 1 0 /usr/local/lib/libcurl.so.24.9
000019ea4eee4000 000019ea4f317000 rlib 0 2 0 /usr/local/lib/libidn.so.17.2
000019eadb56f000 000019eadb9cf000 rlib 0 2 0 /usr/lib/libssl.so.35.0
000019eab1128000 000019eab16f8000 rlib 0 3 0 /usr/lib/libcrypto.so.35.0
000019ea48539000 000019ea48943000 rlib 0 3 0 /usr/local/lib/libintl.so.6.0
000019ea02859000 000019ea02d57000 rlib 0 4 0 /usr/local/lib/libiconv.so.6.0
000019ea82680000 000019ea82aa8000 rlib 0 1 0 /usr/lib/libm.so.9.0
000019eadfa7f000 000019eadff59000 rlib 0 1 0 /usr/lib/libc.so.80.1
000019ea03e00000 000019ea03e00000 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.
0x00000f92a5b46ced in _dl_boot_bind ()
(gdb) bt
#0  0x00000f92a5b46ced in _dl_boot_bind ()
#1  0x00000f92a5b468e9 in __start ()
#2  0x0000000000000000 in ?? ()

And...

% ktrace -di -t einstuw ./admin
Segmentation fault (core dumped)
% kdump
 29725          EMUL  "native"
 29725 ktrace   NAMI  "./admin"
 29725          EMUL  "native"
 29725 admin    PSIG  SIGSEGV SIG_DFL code SEGV_MAPERR<1>
addr=0x8dfcbd00469 trapno=6
 29725 admin    NAMI  "admin.core"
 29725 admin    CSW  stop kernel
 29725 admin    CSW  resume kernel
 29725 admin    CSW  stop kernel
 29725 admin    CSW  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

Reply via email to