musl segfault at program exit
I have built libdmg-hfsplus from source (https://github.com/aerofs/libdmg-hfsplus) with the following APKBUILD
pkgname=dmg-hfsplus
pkgver=0.1.0
pkgrel=1
pkgdesc="DMG/HFS utilities"
url="https://github.com/aerofs/libdmg-hfsplus"
arch="all"
license="GPL 3"
depends="zlib bzip2 libcrypto1.0"
makedepends="cmake openssl-dev zlib-dev bzip2-dev"
options="!strip"
source=""
_builddir="$srcdir"/libdmg-hfsplus
fetch() {
mkdir -p "$srcdir" || return 1
default_fetch || return 1
rm -rf "$_builddir" || return 1
git clone --depth=1 https://github.com/aerofs/libdmg-hfsplus.git "$_builddir"
}
prepare() {
cd "$_builddir"
for i in $source; do
case $i in
*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
esac
done
}
build() {
cd "$_builddir" || return 1
cmake CMakeLists.txt -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX="$pkgdir"/usr || return 1
make || return 1
}
package() {
cd "$_builddir" || return 1
make install || return 1
rm -rf "$pkgdir"/usr/include
}
md5sums=""
It builds and runs fine up until the point where I try to create a DMG
image with the “dmg build” command.
This particular command seems to work fine, except it invariably ends in
a segfault after it is done.
Running in gdb gives this singularly unhelpful output:
(elided)
Cleaning up...
Done.
During startup program terminated with signal SIGSEGV, Segmentation fault.
Valgrind suggests the issue might be in musl:
==42== Syscall param writev(vector[...]) points to uninitialised byte(s)
==42== at 0x4049268: __stdio_write (in /lib/ld-musl-x86_64.so.1)
==42== by 0x3FF: ???
==42== by 0xFFF0007CB: ???
==42== by 0x3: ???
==42== by 0xFFF0000B7: ???
==42== by 0x3: ???
==42== by 0x4E9BC7F: ???
==42== Address 0x4e9c0f8 is 1,144 bytes inside a block of size 1,264 alloc'd
==42== at 0x4C91ACC: malloc (vg_replace_malloc.c:299)
==42== by 0x4048D58: fdopen (in /lib/ld-musl-x86_64.so.1)
==42== by 0xC25: ???
==42== by 0x4048ECF: __fmodeflags (in /lib/ld-musl-x86_64.so.1)
==42== by 0x3: ???
==42== by 0x11C35A: ??? (in /usr/bin/dmg)
==42== by 0x1: ???
==42== by 0x404A197: fopen (in /lib/ld-musl-x86_64.so.1)
==42== by 0x11BCC5: ftellWrapper (abstractfile.c:23)
==42== by 0xFFF000E86: ???
==42== by 0xFFF000BF7: ???
==42== by 0xFFF000E44: ???
==42==
Cleaning up...
==42== Syscall param writev(vector[...]) points to uninitialised byte(s)
==42== at 0x4049268: __stdio_write (in /lib/ld-musl-x86_64.so.1)
==42== by 0x127: ???
==42== Address 0x4e9be04 is 388 bytes inside a block of size 1,264 alloc'd
==42== at 0x4C91ACC: malloc (vg_replace_malloc.c:299)
==42== by 0x4048D58: fdopen (in /lib/ld-musl-x86_64.so.1)
==42== by 0xC25: ???
==42== by 0x4048ECF: __fmodeflags (in /lib/ld-musl-x86_64.so.1)
==42== by 0x3: ???
==42== by 0x11C35A: ??? (in /usr/bin/dmg)
==42== by 0x1: ???
==42== by 0x404A197: fopen (in /lib/ld-musl-x86_64.so.1)
==42== by 0x11BCC5: ftellWrapper (abstractfile.c:23)
==42== by 0xFFF000E86: ???
==42== by 0xFFF000BF7: ???
==42== by 0xFFF000E44: ???
==42==
Done.
==42== Invalid read of size 8
==42== at 0x4020CFF: ??? (in /lib/ld-musl-x86_64.so.1)
==42== by 0x4020F82: ??? (in /lib/ld-musl-x86_64.so.1)
==42== Address 0x3e0b14093faffe39 is not stack'd, malloc'd or (recently) free'd
==42==
==42==
==42== Process terminating with default action of signal 11 (SIGSEGV)
==42== General Protection Fault
==42== at 0x4020CFF: ??? (in /lib/ld-musl-x86_64.so.1)
==42== by 0x4020F82: ??? (in /lib/ld-musl-x86_64.so.1)
==42==
==42== HEAP SUMMARY:
==42== in use at exit: 1,392 bytes in 4 blocks
==42== total heap usage: 1,607 allocs, 1,607 frees, 2,678,778,898 bytes allocated
==42==
==42== LEAK SUMMARY:
==42== definitely lost: 0 bytes in 0 blocks
==42== indirectly lost: 0 bytes in 0 blocks
==42== possibly lost: 0 bytes in 0 blocks
==42== still reachable: 1,392 bytes in 4 blocks
==42== suppressed: 0 bytes in 0 blocks
==42== Rerun with --leak-check=full to see details of leaked memory
==42==
==42== For counts of detected and suppressed errors, rerun with: -v
==42== Use --track-origins=yes to see where uninitialised values come from
==42== ERROR SUMMARY: 8 errors from 4 contexts (suppressed: 0 from 0)
Segmentation fault
I’ve tried compiling with -fstack-protector-all and -fstack-check but that didn’t help.
I’ve downloaded musl-dbg as well but it didn’t noticeably improve valgrind’s output.
Is there anything I can do to track down this issue?
(from redmine: issue id 5123, created on 2016-02-16, closed on 2016-02-22)