Closed xuxiaocheng0201 closed 3 weeks ago
Could it be due to my incorrect environment variable settings?
brew install filosottile/musl-cross/musl-cross
export CC_x86_64_unknown_linux_musl=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-gcc
export AR_x86_64_unknown_linux_musl=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-ar
What should the correct environment variable settings be like? I couldn't find any relevant documentation to describe it. If anyone could provide a clue, I would be extremely grateful.
Could you show the output of xxd /Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/build/openssl-sys-46078b20ef0b4c0a/out/openssl-build/install/lib/libssl.a | head
and ar t /Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/build/openssl-sys-46078b20ef0b4c0a/out/openssl-build/install/lib/libssl.a
after you build with nightly and get the error?
Also I'm removed the ICE label as this no longer gives an ICE on nightly.
Sure! @bjorn3
The output of xxd /Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/build/openssl-sys-46078b20ef0b4c0a/out/openssl-build/install/lib/libssl.a | head
is:
00000000: 213c 6172 6368 3e0a 2331 2f32 3020 2020 !<arch>.#1/20
00000010: 2020 2020 2020 2020 3137 3238 3537 3434 17285744
00000020: 3839 2020 3530 3120 2020 3230 2020 2020 89 501 20
00000030: 3130 3036 3434 2020 3238 2020 2020 2020 100644 28
00000040: 2020 600a 5f5f 2e53 594d 4445 4620 534f `.__.SYMDEF SO
00000050: 5254 4544 0000 0000 0000 0000 0000 0000 RTED............
00000060: 2331 2f31 3220 2020 2020 2020 2020 2020 #1/12
00000070: 3020 2020 2020 2020 2020 2020 3020 2020 0 0
00000080: 2020 3020 2020 2020 3020 2020 2020 2020 0 0
00000090: 3534 3133 3220 2020 2020 600a 2f00 0000 54132 `./...
The output of ar t /Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/build/openssl-sys-46078b20ef0b4c0a/out/openssl-build/install/lib/libssl.a
is:
I looks like the libssl.a produced by openssl-build is corrupt. The output of ar t
shows the names of all archive members, which are supposed to consist of exclusively ASCII characters. Rightfully errors out on corrupt archives. As nightly no longer ICE's, I don't think there is anything left to do on the rustc side. That said, I don't mind trying to help you with debugging why a corrupt libssl.a is produced. Something I've seen cause corruption of static library archives in the past is when something generates a macOS style archive and then the archive is manipulated by a tool that expects Linux style archives or vice versa. One thing you could try is setting export RANLIB_x86_64_unknown_linux_musl=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-ranlib
and then rebuilding after a cargo clean
. Ranlib is a tool which runs on archives to add/update a symbol table. The symbol table format is one of the major differences between macOS style and Linux style archives.
Wow, it works. But there is another question that is not related to this issue. Then the output is:
WARN rustc_codegen_ssa::back::link Linker does not support -static-pie command line option. Retrying with -static instead.
error: linking with `cc` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/self-contained:/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/self-contained:/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/self-contained:/Users/xuxiaocheng/.cargo/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Library/Apple/usr/bin:/usr/local/share/dotnet:~/.dotnet/tools:/Users/xuxiaocheng/Applications/flutter/bin:/Users/xuxiaocheng/.cargo/bin:/Users/xuxiaocheng/.gem/bin:/Library/Java/JavaVirtualMachines/graalvm-jdk-17.0.12+8.1/Contents/Home/bin:/opt/homebrew/bin/:/opt/homebrew/opt/llvm/bin:/opt/homebrew/bin/python3:/opt/homebrew/opt/python@3.12/libexec/bin:/Users/xuxiaocheng/Library/Android/sdk/ndk/27.1.12297006/toolchains/llvm/prebuilt/darwin-x86_64/bin:/opt/homebrew/opt/node@20/bin" VSLANG="1033" "cc" "-m64" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crt1.o" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbegin.o" "/var/folders/_w/y4dz37394kq6ck56xzqcp6d40000gn/T/rustcUMg8zD/symbols.o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4.1iaj672wno4p7gtftdjcafzap.rcgu.o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4.1zus0a988jgf9u72jhzxk1top.rcgu.o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4.3swvung9ke81tlwo859ptp14c.rcgu.o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4.81g0etzz8ziqep3bzd7kuucva.rcgu.o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4.b2ghjnjoh6puzhgulo3e7o3bw.rcgu.o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4.a9zeabbofo5sewom0uxp4009e.rcgu.o" "-Wl,--as-needed" "-Wl,-Bstatic" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-eef8f5f1a6241997.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-fb4457de67986823.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-f7bbd4335a62ca1b.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-08f38fe1d0dbe825.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-8e5defbd8afe1bfa.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-5a999f56fc2ac3ad.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-2bb4f5a5fda29daa.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-0b5ce9a8a91a8736.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-edcb15c1b392bf2e.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-459028a03e67e8c7.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-b5e48f8f9535b218.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-9eedd7aa38f2108f.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-b938e0bbdb9ad16e.rlib" "-lunwind" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-6886fff82d1fb411.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-e0d6a31e6f3d350b.rlib" "-lc" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-b015fe652967a4a9.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-e8889f443ab9420f.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-db5962732af76041.rlib" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-a0b3069b5e99ee25.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-nostartfiles" "-L" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/build/openssl-sys-46078b20ef0b4c0a/out/openssl-build/install/lib" "-L" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "-L" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/Users/xuxiaocheng/Rust/tester/target/x86_64-unknown-linux-musl/debug/deps/tester-d799fda059ad16a4" "-Wl,--gc-sections" "-static" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtend.o" "/Users/xuxiaocheng/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
= note: ld: unknown option: --as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: could not compile `tester` (bin "tester") due to 1 previous error
I remove the dependency and got the similar output. Maybe cross-compiling from macos to linux is not supported?
Try export RUSTFLAGS="-Clinker=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-gcc"
to use the right linker.
That's great! Thank you very much!!
For future reader:
Run brew install filosottile/musl-cross/musl-cross
and export these.
export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-gcc
export CC_x86_64_unknown_linux_musl=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-gcc
export AR_x86_64_unknown_linux_musl=/opt/homebrew/Cellar/musl-cross/0.9.9_2/bin/x86_64-linux-musl-ar
To cross-compile from macos to linux.
Code
Simply cross-compile
openssl
fromaarch64-apple-darwin
tox86_64-unknown-linux-musl
withvendored
feature.Cargo.toml
:main.rs
:Command:
cargo build --target x86_64-unknown-linux-musl
Meta
rustc --version --verbose
:Then I tried nightly, But it gives a different output:
Error output
Backtrace
``` Compiling openssl-sys v0.9.103 thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/back/archive.rs:418:67: called `Option::unwrap()` on a `None` value stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt Compiling openssl v0.10.66 2: core::panicking::panic 3: core::option::unwrap_failed 4:::build
5: rustc_codegen_ssa::back::link::link_binary
6: ::link
7: ::link
8: >::set::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
9: rustc_span::create_session_globals_then::, rustc_interface::util::run_in_thread_with_globals, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.81.0 (eeb90cda1 2024-09-04) running on aarch64-apple-darwin
note: compiler flags: --crate-type rlib -C embed-bitcode=no -C debuginfo=2
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
```