Description
Hi,
I am a contributor to the Alpine Linux distribution (which uses musl libc). Since recently, Alpine has support for riscv64. In this context, I am currently trying to make Rust available on this architecture. With some patching, I was able to successfully bootstrap a stage2 rustc for riscv64 musl by cross-compiling using our x86_64 Rust package on Alpine Linux Edge. Compiling basic software (e.g. hello world) with the stage2 rustc works on riscv64 musl. Unfortunately, re-compiling rustc itself with stage2 does not and causes a segmentation fault early on in the build process.
Code
$ python3 ./x.py dist
Building rustbuild
Compiling proc-macro2 v1.0.30
Compiling memchr v2.4.1
Compiling unicode-xid v0.2.2
Compiling syn v1.0.80
Compiling cfg-if v1.0.0
Compiling serde_derive v1.0.125
Compiling lazy_static v1.4.0
Compiling log v0.4.14
Compiling regex-automata v0.1.10
Compiling libc v0.2.116
Compiling serde v1.0.125
Compiling regex-syntax v0.6.25
Compiling ryu v1.0.5
Compiling crossbeam-utils v0.8.6
Compiling serde_json v1.0.59
Compiling fnv v1.0.7
Compiling once_cell v1.7.2
Compiling same-file v1.0.6
Compiling unicode-width v0.1.8
Compiling bootstrap v0.0.0 (/home/buildozer/aports/community/rust/src/rustc-1.60.0-src/src/bootstrap)
Compiling itoa v0.4.6
Compiling cc v1.0.69
Compiling build_helper v0.1.0 (/home/buildozer/aports/community/rust/src/rustc-1.60.0-src/src/build_helper)
error: could not compile `ryu`
Caused by:
process didn't exit successfully: `/usr/bin/rustc --crate-name build_script_build --edition=2018 /home/buildozer/aports/community/rust/src/rustc-1.60.0-src/vendor/ryu-1.0.5/build.rs --error-format=json --json=diagnostic-rendered-ansi,
artifacts,future-incompat --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=0 -C metadata=0008fc44e561b019 -C extra-filename=-0008fc44e561b019 --out-dir /home/buildozer/aports/community/rust/src/rustc-1.60.0-src/bui
ld/bootstrap/debug/build/ryu-0008fc44e561b019 -L dependency=/home/buildozer/aports/community/rust/src/rustc-1.60.0-src/build/bootstrap/debug/deps --cap-lints allow -C target-feature=-crt-static -C linker=gcc -Wrust_2018_idioms -Wunused_
lifetimes -Wsemicolon_in_expressions_from_macros` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...
thread 'rustc' panicked at 'index out of bounds: the len is 6 but the index is 2636', compiler/rustc_span/src/hygiene.rs:448:21
stack backtrace:
thread 'rustc' panicked at 'index out of bounds: the len is 171 but the index is 10920', compiler/rustc_span/src/hygiene.rs:448:21
stack backtrace:
thread 'rustc' panicked at 'index out of bounds: the len is 155 but the index is 257', compiler/rustc_span/src/hygiene.rs:448:21
The backtrace for this segfault looks as follows:
(gdb) bt
#0 0x0000003f8d13bff4 in <rustc_span::span_encoding::Span as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#1 0x0000003f8d12c6a6 in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_hir_expr::{closure#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#2 0x0000003f8d12cbf4 in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_hir_expr::{closure#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#3 0x0000003f8d12e184 in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_hir_expr::{closure#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#4 0x0000003f8d12cadc in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_hir_expr::{closure#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#5 0x0000003f8d13f39a in <&[rustc_hir::hir::Stmt] as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#6 0x0000003f8d12cefc in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_hir_expr::{closure#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#7 0x0000003f8d12c60c in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_hir_expr () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#8 0x0000003f8c040e56 in <rustc_query_system::ich::hcx::StableHashingContext as rustc_hir::stable_hash_impls::HashStableContext>::hash_body_id () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#9 0x0000003f8c0831d0 in <rustc_hir::hir::OwnerNode as rustc_data_structures::stable_hasher::HashStable<rustc_query_system::ich::hcx::StableHashingContext>>::hash_stable () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#10 0x0000003f8c053590 in <rustc_ast_lowering::LoweringContext>::make_owner_info () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#11 0x0000003f8c03b138 in <rustc_ast_lowering::item::ItemLowerer as rustc_ast::visit::Visitor>::visit_item () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#12 0x0000003f8c04f340 in rustc_ast_lowering::lower_crate () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#13 0x0000003f8b9e5122 in <rustc_interface::queries::Queries>::global_ctxt () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#14 0x0000003f8b8f3808 in rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#15 0x0000003f8b925ecc in std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>> () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#16 0x0000003f8b8eef4a in <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} () from /usr/lib/librustc_driver-e81ecd0b9419698e.so
#17 0x0000003f8b1eade6 in std::sys::unix::thread::Thread::new::thread_start () from /usr/lib/libstd-5a982fb5ee18f2d1.so
#18 0x0000003f8dc18b72 in start (p=0x3f857cd6b8) at src/thread/pthread_create.c:203
#19 0x0000003f8dc1a248 in __clone () at src/thread/riscv64/clone.s:30
Backtrace stopped: frame did not save the PC
It looks to me like it is segfaulting while attempting to print a backtrace?
Full log: alpine-edge-riscv64-buildlog.txt
Meta
rustc --version --verbose
:
rustc 1.60.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: riscv64-alpine-linux-musl
release: 1.60.0
LLVM version: 13.0.1
As you can see, this version uses a custom Alpine triplet with some minor patches applied which cause rustc to link against musl dynamically by default. You can find the full set of patches (including the once required to make rust-1.6.0 build on riscv64 musl in the first place) here. I don't think that the issue is caused by the patches that we are currently applying, hence reporting this here (if strictly needed I can also compile a rustc without our custom triplet, however, as noted above vanilla rust-1.6.0 wont compile without patches on riscv64 musl anyhow).
Any ideas what might be causing this or tips on how to debug this further?
Related: #93975
CC: @nekopsykose, @kaniini, @Cogitri