Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when running static build with with-dns-sd #1276

Closed
yubiuser opened this issue Apr 21, 2024 · 4 comments
Closed

Segmentation fault when running static build with with-dns-sd #1276

yubiuser opened this issue Apr 21, 2024 · 4 comments
Labels

Comments

@yubiuser
Copy link
Contributor

yubiuser commented Apr 21, 2024

I'm trying to build a static binary on alpine within a docker container. It works well when using -no-default-features. In order to compile it with with-dns-sd I needed to manually add links to certain avahi libraries. It now builds without issues, but as soon as I start librespot I get a segmentation fault.

Here is the relevant part of the docker file

FROM docker.io/alpine:3.19 AS librespot
RUN apk add --no-cache \
    avahi-dev\
    dbus-dev \
    gettext-static \
    git \
    curl \
    libgcc \
    gcc \
    musl-dev \
    pkgconfig

ENV RUSTFLAGS="-C target-feature=+crt-static -C link-arg=-L/usr/lib/ -C link-arg=-l:libdns_sd.a -C link-arg=-l:libavahi-client.a -C link-arg=-l:libavahi-common.a -C link-arg=-l:libdbus-1.a -C link-arg=-l:libintl.a"
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL="sparse"
ENV CARGO_INCREMENTAL=0
RUN git clone https://github.com/librespot-org/librespot
WORKDIR /librespot
ENV RUSTUP_HOME=/usr/local/rustup \
    CARGO_HOME=/usr/local/cargo \
    PATH=/usr/local/cargo/bin:$PATH

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --no-modify-path --profile minimal
RUN cargo build --release --no-default-features --features with-dns-sd --target x86_64-unknown-linux-musl

Capturing the crash with gdb

/librespot/target/x86_64-unknown-linux-musl/release # gdb librespot
GNU gdb (GDB) 14.1
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-alpine-linux-musl".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from librespot...
(gdb) r
Starting program: /librespot/target/x86_64-unknown-linux-musl/release/librespot 
warning: Error disabling address space randomization: Operation not permitted
[2024-04-21T18:42:29Z INFO  librespot] librespot 0.5.0-dev a6065d6 (Built on 2024-04-21, Build ID: w2wDYa7H, Profile: release)
*** WARNING *** The program 'librespot' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see <http://0pointer.de/blog/projects/avahi-compat.html>
[New LWP 19]

Thread 1 "librespot" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) backtrace
#0  0x0000000000000000 in ?? ()
#1  0x00007e99bf74206e in _libintl_rwlock_unlock_multithreaded (lock=0x7e99bfae7c60 <_libintl_state_lock>) at glthread/lock.c:496
#2  0x00007e99bf73efb6 in set_binding_values (domainname=<optimized out>, dirnamep=dirnamep@entry=0x7ffd932fe908, codesetp=codesetp@entry=0x0, wdirnamep=0x0) at ./bindtextdom.c:370
#3  0x00007e99bf73f0d6 in set_binding_values (wdirnamep=0x0, codesetp=0x0, dirnamep=0x7ffd932fe908, domainname=domainname@entry=0x7e99bf7dc430 "avahi") at ./bindtextdom.c:92
#4  libintl_bindtextdomain (domainname=domainname@entry=0x7e99bf7dc430 "avahi", dirname=<optimized out>, dirname@entry=0x7e99bf7dc423 "/usr//locale") at ./bindtextdom.c:407
#5  0x00007e99bf73ed17 in avahi_init_i18n () at i18n.c:34
#6  0x00007e99bf7326c9 in avahi_client_new (poll_api=0x7e99bf00ea30, flags=flags@entry=0, callback=callback@entry=0x7e99bf5039e0 <reg_client_callback>, userdata=userdata@entry=0x7e99bf01fea0, 
    ret_error=ret_error@entry=0x7ffd932fe9b4) at client.c:483
#7  0x00007e99bf504b21 in DNSServiceRegister (ret_sdref=0x7ffd932feac8, flags=0, interface=<optimized out>, name=0x7e99bf024110 "Librespot", regtype=<optimized out>, domain=<optimized out>, 
    host=<optimized out>, port=2960, txtLen=<optimized out>, txtRecord=<optimized out>, callback=0x0, context=0x0) at compat.c:1149
#8  0x00007e99bf50242b in dns_sd::DNSService::register ()
#9  0x00007e99bf1cc606 in librespot_discovery::Builder::launch ()
#10 0x00007e99bf0ef9cd in <core::pin::Pin<P> as core::future::future::Future>::poll ()
#11 0x00007e99bf1778fb in tokio::runtime::scheduler::current_thread::Context::enter ()
#12 0x00007e99bf18f98c in tokio::runtime::context::scoped::Scoped<T>::set ()
#13 0x00007e99bf177c23 in tokio::runtime::scheduler::current_thread::CoreGuard::block_on ()
#14 0x00007e99bf18fd51 in tokio::runtime::context::runtime::enter_runtime ()
#15 0x00007e99bf1a291f in tokio::runtime::runtime::Runtime::block_on ()
#16 0x00007e99bf139619 in librespot::main ()
#17 0x00007e99bf17b7a3 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
#18 0x00007e99bf1975a9 in std::rt::lang_start::{{closure}} ()
#19 0x00007e99bf6cd0c8 in core::ops::function::impls::{impl#2}::call_once<(), (dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> ()
    at library/core/src/ops/function.rs:284
#20 std::panicking::try::do_call<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> () at library/std/src/panicking.rs:554
#21 std::panicking::try<i32, &(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe)> () at library/std/src/panicking.rs:518
#22 std::panic::catch_unwind<&(dyn core::ops::function::Fn<(), Output=i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe), i32> () at library/std/src/panic.rs:142
#23 std::rt::lang_start_internal::{closure#2} () at library/std/src/rt.rs:148
#24 std::panicking::try::do_call<std::rt::lang_start_internal::{closure_env#2}, isize> () at library/std/src/panicking.rs:554
#25 std::panicking::try<isize, std::rt::lang_start_internal::{closure_env#2}> () at library/std/src/panicking.rs:518
#26 std::panic::catch_unwind<std::rt::lang_start_internal::{closure_env#2}, isize> () at library/std/src/panic.rs:142
#27 std::rt::lang_start_internal () at library/std/src/rt.rs:148
#28 0x00007e99bf1396e5 in main ()

I even tried to compile avahi manually and copied the necessary libraries but it fails at the same point.
The issue might not be directly caused by librespot but due to musl vs glibc and/or ´avahi and libintl

@roderickvd
Copy link
Member

Latest head is now set up for Alpine I think. Does that do anything?

@yubiuser
Copy link
Contributor Author

Unfortunately not. I still think this might be an issue 'outside' of librespot but with avahi and/or libintl

@wisp3rwind
Copy link
Contributor

@yubiuser maybe #1347 would be interesting to you? The PR adds an alternative zeroconf implementation that does not use the dns_sd compatibility layer on top of Avahi, but talks to Avahi directly.

@yubiuser
Copy link
Contributor Author

This sounds very interesting. Once you get the CI to pass, I'll start looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants