Segfault after dynamically linking against musl libc
When trying to build 'cbfstool', a relatively simple tool from coreboot utilities, a following segmentation fault appears before anything is printed when trying to launch the ELF executable:
git clone --recursive https://review.coreboot.org/coreboot.org
cd coreboot/util/cbfstool
make
./cbfstool
The only output is:
Segmentation fault
Other tools from the directory run just fine.
Some observations when trying to find the root cause:
-
valgrind
output:
valgrind ./cbfstool
==24285== Process terminating with default action of signal 11 (SIGSEGV)
==24285== Bad permissions for mapped region at address 0x1420E0
==24285== at 0x405C1F0: ??? (in /lib/ld-musl-x86_64.so.1)
This seems to point into the musl libc code.
-
strace
output:
strace ./cbfstool
execve("./cbfstool", ["./cbfstool"], 0x7fffad891e00 /* 18 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x7f97e2dd7b48) = 0
set_tid_address(0x7f97e2dd7fb8) = 24283
brk(NULL) = 0x5580439de000
brk(0x5580439e0000) = 0x5580439e0000
mmap(0x5580439de000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x5580439de000
mprotect(0x7f97e2dd4000, 4096, PROT_READ) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_ACCERR, si_addr=0x55804381a0e0} ---
+++ killed by SIGSEGV +++
Segmentation fault
A possible workaround is to build the tool statically:
make clean
TOOLLDFLAGS=-static make
Then cbfstool
also works as expected:
./cbfstool
cbfstool: Management utility for CBFS formatted ROM images
USAGE:
./cbfstool [-h]
./cbfstool FILE COMMAND [-v] [PARAMETERS]...
OPTIONs:
...
To me this seems as a problem of musl libc or the dynamic linker failing to load the shared libc as this is the only shared library loaded by cbfstool.
- Alpine version: 3.18.0 (latest-stable)
- Arch: x86_64
- kernel version: 6.1.33-0-lts
- musl version: musl-1.2.4-r0
- binutils version: binutils-2.40-r7
Relevant coreboot discussion: https://review.coreboot.org/c/coreboot/+/75049?tab=comments