-
Notifications
You must be signed in to change notification settings - Fork 399
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
x86_64-unknown-linux-musl
links to Glibc With C++ Dependencies
#902
Comments
So the two targets that fail are:
ARM64 musl is actually fine: it just wants to name what it links against as a glibc loader, but it only works with a musl loader. x86_64 just doesn't work, nor will it. Likely the only real solution long-term, if this target with C++ is desired enough, is to make |
should we include this in 0.2.3? |
It shouldn't be too much work, so I think that's fine. We could push it back thought to 0.3.0, since x86_64 Alpine build systems are not too difficult to setup. |
x86_64-unknown-linux-musl
links to Glibc With C++ Dependencies
It might be worth adding a warning for this target, since it seems to fail with dylib. I might check to ensure it works with static linking C++ dependencies. |
A little bit more information on the IssueLet's try to build and run a Rust executable with a C++ dependency. $ git clone https://github.com/cross-rs/rust-cpp-hello-word
$ cd rust-cpp-hello-word
$ cross run --target x86_64-unknown-linux-musl
Finished dev [unoptimized + debuginfo] target(s) in 0.13s
Running `/qemu-runner x86_64 /target/x86_64-unknown-linux-musl/debug/hellopp`
Segmentation fault (core dumped) Let's also try to run the binary natively on Alpine: $ docker run -it --rm -v "$PWD/target/x86_64-unknown-linux-musl":/target alpine:latest sh
$ target/debug/hellopp
Segmentation fault (core dumped) So the binary is still failing, even when it's run on Alpine. BasisFirst, let's just ensure that we're on the same page: the following program headers and sections are fine: NOTE: having
For static libraries, the following program headers are normal:
So just having some GNU sections, program headers, or symbols is normal. The ProblemLet's download our x86_64 musl toolchain and try to build a C++ executable from it: # outside the container
$ docker pull ghcr.io/cross-rs/x86_64-unknown-linux-musl:main
$ docker run -it --rm ghcr.io/cross-rs/x86_64-unknown-linux-musl:main bash
# inside the container
$ echo '#include <cstdio>
#include <iostream>
int main() {
printf("Hello World!\n");
std::cout << "Hello World!" << std::endl;
return 0;
}
' > main.cc
# DYNAMIC
# this links to libstdc++ built using GLIBCXX symbols.
$ $CXX_x86_64_unknown_linux_musl main.cc -o musl_dynamic
$ readelf -a musl_dynamic | grep GLIBCXX | head -n 1
000000601080 000c00000005 R_X86_64_COPY 0000000000601080 _ZSt4cout@GLIBCXX_3.4 + 0
# however, no libc built against glibc symbols are found
$ readelf -a musl_dynamic | grep GLIBC | grep puts | head -n 1
# STATIC
# we probably have the same issue with the static build, but it's
# trickier to determine, since the symbols aren't versioned.
$CXX_x86_64_unknown_linux_musl main.cc -static -o musl_static This unfortunately seems to be a broader issues than just x86_64: # outside the container
$ docker pull ghcr.io/cross-rs/aarch64-unknown-linux-musl:main
$ docker run -it --rm ghcr.io/cross-rs/aarch64-unknown-linux-musl:main bash
# inside the container
$ echo '#include <cstdio>
#include <iostream>
int main() {
printf("Hello World!\n");
std::cout << "Hello World!" << std::endl;
return 0;
}
' > main.cc
# DYNAMIC
$ $CXX_aarch64_unknown_linux_musl main.cc -o musl_dynamic
$ readelf -a musl_dynamic | grep GLIBCXX | head -n 1
000000411058 000f00000400 R_AARCH64_COPY 0000000000411058 _ZSt4cout@GLIBCXX_3.4 + 0 This mostly isn't an issue, since the existing
SummaryIn short, we probably need to update our toolchains to build |
I've tried deversioning them by compiling the archive to a shared library, and nothing seems to work. It might be worth looking into how Alpine builds their toolchain. |
I should have a fix for this out today. It turns out, compiling |
Checklist
Describe your issue
UPDATE: All targets except
x86_64-unknown-linux-musl
have been patched as of #905, and the MIPS64 targets in #906.When compiling for some musl targets, they link to dynamically to glibc rather than musl libc statically. This only occurs with C++ dependencies. A simple test is as follows:
Some targets, such as
armv7-unknown-linux-musleabihf
link properly, however, while running, they cannot find the correct dynamic library loader.This is related to #101, although not exactly.
What target(s) are you cross-compiling for?
aarch64-unknown-linux-musl
Which operating system is the host (e.g computer cross is on) running?
What architecture is the host?
What container engine is cross using?
cross version
cross 0.2.2 (latest main)
Example
No response
Additional information / notes
No response
The text was updated successfully, but these errors were encountered: