You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
x86_64-unknown-linux-musl target and main-returning-Result produces a dynamically-linked executable instead of a statically linked one. #54243
Now if we take this simple innocuous looking program and try to run it:
➜ cargo run --target x86_64-unknown-linux-musl
Compiling main-musl-bug v0.1.0 (/home/luqman/Develop/tmp/main-musl-bug)
Finished dev [unoptimized + debuginfo] target(s) in 0.37s
Running `target/x86_64-unknown-linux-musl/debug/main-musl-bug`
error: could not execute process `target/x86_64-unknown-linux-musl/debug/main-musl-bug` (never executed)
Caused by:
No such file or directory (os error 2)
Well, the file is definitely there but running file gives this:
➜ file ./target/x86_64-unknown-linux-musl/debug/main-musl-bug
./target/x86_64-unknown-linux-musl/debug/main-musl-bug: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), dynamically linked, interpreter /lib/ld64.so.1, BuildID[sha1]=c43d7e9e32151f6240e2e93e744c3bda8e2e179f, with debug_info, not stripped
That's odd, I would've expected a statically linked binary but file disagrees here. The no such file or directory error I'm guessing results from the bogus program interpreter in the elf header:
➜ readelf -a ./target/x86_64-unknown-linux-musl/debug/main-musl-bug
[...]
[Requesting program interpreter: /lib/ld64.so.1]
[...]
That path doesn't exist on my machine.
Now, the weird thing is a couple different things workaround the issue:
Is this repros on nightly you can add rustflags = ["-Z", "print-link-args"] to the [build] section of your .cargo/config file (see https://doc.rust-lang.org/cargo/reference/config.html) to see the actual link command used which should help analyse this issue.
I guess you're linking with gcc and are thus linking to the system-wide libsqlite3.so (dynamically) - this leads to your issue, but it's never going to work anyway
The reason --release made this appear to work is that the dynamic link was optimized out (as it's not used anywhere)
I'm guessing something similar occurs with non-Result main the linker can more easily see that the dynamic library is unneeded
Changing the linker to musl-gcc leads to -lsqlite3: Not found errors (as expected - musl-gcc sets library lookup paths to a special place to prevent cross-contamination)
Adding libsqlite3-sys = { version = "0.9.3", features = ["bundled"] } as a dependency causes a local (static/musl) version to be compiled and linked in and the world to work once more. Probably diesel should add that feature when compiling for x86_64-unknown-linux-musl....?
Activity
bossmc commentedon Sep 19, 2018
Is this repros on
nightlyyou can addrustflags = ["-Z", "print-link-args"]to the[build]section of your.cargo/configfile (see https://doc.rust-lang.org/cargo/reference/config.html) to see the actual link command used which should help analyse this issue.bossmc commentedon Sep 21, 2018
I think there's various things going on here:
gccand are thus linking to the system-widelibsqlite3.so(dynamically) - this leads to your issue, but it's never going to work anyway--releasemade this appear to work is that the dynamic link was optimized out (as it's not used anywhere)mainthe linker can more easily see that the dynamic library is unneededmusl-gccleads to-lsqlite3: Not founderrors (as expected -musl-gccsets library lookup paths to a special place to prevent cross-contamination)libsqlite3-sys = { version = "0.9.3", features = ["bundled"] }as a dependency causes a local (static/musl) version to be compiled and linked in and the world to work once more. Probablydieselshould add that feature when compiling forx86_64-unknown-linux-musl....?luqmana commentedon Sep 22, 2018
@bossmc Hmm, I'm pretty sure it's already using
musl-gcc(since I forgot to install it earlier and it complained).And yea, just working around it now by using the bundled version for now.
bossmc commentedon Sep 22, 2018
Can you run the
print-link-argstest and paste the output?luqmana commentedon Sep 22, 2018
Ah ok, you were right, it was indeed just invoking
cc. I only got the error when I was trying the bundled sqlite feature.A bit unfortunate but the bundled feature does actually map to more what I want.
Thanks @bossmc
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables
Require static native libraries when linking static executables