Open plusls opened 7 months ago
Hej @plusls, could you add some more detail about your setup?
Which version of magic-sys
are you using?
Are you using magic-sys
directly or via the magic
crate and which version?
Which version of the musl-dev
and file-dev
packages did you end up with?
How are you building your project, did you set any environment variables to configure magic-sys
?
What did you debug with gdb, your build-script? When/where is magic_open
set to null
?
I use the rust-magic-sys 0.3.0, and I try to use it in docker image rust:alpine
,with deps
apk add musl-dev file-dev
deps version:
I direct build my program with cargo build --release, without other envirom var.
my code:
fn main() {
unsafe {magic_sys::magic_open(0)};
println!("Hello, world!");
}
And I saw that
I found that it success link to libmagic
I don't know why, the value in got table
of magic_open
is null ptr, I debug it with gdb
and reverse it with ida pro
any progress? @robo9k
I can reproduce this, but since I'm usually using neither Alpine nor MUSL I don't really know why the shared libmagic
library is not loaded, even though it is being linked against.
You can fix this by "dynamically linking" to libc (but this seems to link to libgcc_s
, compare with your ldd
screenshot):
$ RUSTFLAGS="-C target-feature=-crt-static" cargo build
This pretty much seems to be the same as https://users.rust-lang.org/t/segfault-when-linking-against-shared-libraries-on-alpine/98629 and even the gdb
backtrace is as unhelpful there.
And in my gdb I found that the reference of
magic_open
is null, I have no ideal why.alpine env: based on rust:1.76-alpine