Closed
Description
I've run into this weird interaction between the musl target, diesel, returning Result from main and debug vs release mode.
The setup:
Cargo.toml:
[package]
name = "main-musl-bug"
version = "0.1.0"
[dependencies]
diesel = { version = "1.3", features = ["sqlite"] }
main.rs:
extern crate diesel;
fn main() -> Result<(), std::io::Error> {
println!("Hello, world!");
Ok(())
}
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:
- build/run with --release OR
- use a plain old
fn main() { ... }
function.
rustc/cargo version:
➜ ~ rustc -V
rustc 1.29.0 (aa3ca1994 2018-09-11)
➜ ~ cargo -V
cargo 1.29.0 (524a578d7 2018-08-05)
EDIT: Repros on stable.