Description
Rustc triggers a segmentation fault when compiling the following code. I have tested this on both linux and windows with the latest nightly compiler. It is not possible to compile core
in debug mode for aarch64-unknown-none-softfloat
because of this bug. Luckily, release mode works for both core
and the following example.
Code
#![feature(lang_items)]
#![feature(no_core)]
#![no_core]
#[lang = "sized"]
trait Sized {}
// #[no_mangle]
// #[allow(unconditional_recursion)]
pub fn foo() -> bool {
foo()
}
Another offending example that doesn't use recursion:
#![feature(lang_items)]
#![feature(no_core)]
#![no_core]
#[lang = "sized"]
trait Sized {}
pub fn foo() -> bool {
bar()
}
fn bar() -> bool {
loop {}
}
Error output
~/D/P/segfault> rustc lib.rs --edition=2018 --crate-type lib --target aarch64-unknown-none-softfloat
fish: Job 1, 'rustc lib.rs --edition=2018 --c…' terminated by signal SIGSEGV (Address boundary error)
~/D/P/segfault [SIGSEGV]>
Critical features in target-spec
rustc --print target-spec-json -Z unstable-options --target aarch64-unknown-none-softfloat > aarch64-sf.json
aarch64-sf.json
{
"arch": "aarch64",
"data-layout": "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128",
"disable-redzone": true,
"executables": true,
"features": "+strict-align,-neon,-fp-armv8",
"is-builtin": true,
"linker": "rust-lld",
"linker-flavor": "ld.lld",
"llvm-target": "aarch64-unknown-none",
"max-atomic-width": 128,
"panic-strategy": "abort",
"relocation-model": "static",
"target-pointer-width": "64",
"unsupported-abis": [
"stdcall",
"stdcall-unwind",
"fastcall",
"vectorcall",
"thiscall",
"thiscall-unwind",
"win64",
"sysv64"
]
}
I tried extracting the target spec and running with
rustc lib.rs --edition=2018 --crate-type lib --target aarch64-sf.json
.
The critical line is "features": "+strict-align,-neon,-fp-armv8",
. Setting both +neon
and +fp-armv8
makes the segfault disappear. Those two features are the only difference between aarch64-unknown-none-softfloat
and aarch64-unknown-none
.
llvm-ir
With #[no_mange]
, the llvm-ir I get is
rustc lib.rs --edition=2018 --crate-type lib --target aarch64-unknown-none-softfloat --emit=llvm-ir
:
; ModuleID = 'lib.3a1fbbbh-cgu.0'
source_filename = "lib.3a1fbbbh-cgu.0"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-none"
; Function Attrs: noredzone nounwind
define dso_local zeroext i1 @foo() unnamed_addr #0 {
start:
%0 = call zeroext i1 @foo()
br label %bb1
bb1: ; preds = %start
ret i1 %0
}
attributes #0 = { noredzone nounwind "target-cpu"="generic" }
Changing the return type of foo
from bool
to u8
makes the code compile fine. The only difference in llvm-ir is that the return type is changed from zeroext i1
to i8
llvm-ir with `u8` return type
; ModuleID = 'lib.3a1fbbbh-cgu.0'
source_filename = "lib.3a1fbbbh-cgu.0"
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
target triple = "aarch64-unknown-none"
; Function Attrs: noredzone nounwind
define dso_local i8 @foo() unnamed_addr #0 {
start:
%0 = call i8 @foo()
br label %bb1
bb1: ; preds = %start
ret i8 %0
}
attributes #0 = { noredzone nounwind "target-cpu"="generic" }
Backtrace
Running `gdb` gives the following backtrace:
#0 0x00007ffff1a874e6 in llvm::LegalizerInfo::findAction(std::vector<std::pair<unsigned short, llvm::LegalizeActions::LegalizeAction>, std::allocator<std::pair<unsigned short, llvm::LegalizeActions::LegalizeAction> > > const&, unsigned int) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#1 0x00007ffff1a85aca in llvm::LegalizerInfo::findScalarLegalAction(llvm::InstrAspect const&) const ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#2 0x00007ffff1a85f41 in llvm::LegalizerInfo::getAction(llvm::LegalityQuery const&) const ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#3 0x00007ffff1a86373 in llvm::LegalizerInfo::getAction(llvm::MachineInstr const&, llvm::MachineRegisterInfo const&) const ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#4 0x00007ffff1a513d4 in llvm::LegalizerHelper::legalizeInstrStep(llvm::MachineInstr&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#5 0x00007ffff1a4a25f in llvm::Legalizer::legalizeMachineFunction(llvm::MachineFunction&, llvm::LegalizerInfo const&, llvm::ArrayRef<llvm::GISelChangeObserver*>, llvm::LostDebugLocObserver&, llvm::MachineIRBuilder&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#6 0x00007ffff1a4da24 in llvm::Legalizer::runOnMachineFunction(llvm::MachineFunction&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#7 0x00007ffff13f05fe in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#8 0x00007ffff11ae759 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#9 0x00007ffff11b55a3 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#10 0x00007ffff11aefc0 in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.54.0-nightly.so
#11 0x00007ffff674e4c8 in LLVMRustWriteOutputFile ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#12 0x00007ffff674317f in rustc_codegen_llvm::back::write::write_output_file ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#13 0x00007ffff674628c in rustc_codegen_llvm::back::write::codegen ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#14 0x00007ffff66d8b3b in rustc_codegen_ssa::back::write::finish_intra_module_work ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#15 0x00007ffff66d1d6a in rustc_codegen_ssa::back::write::execute_work_item ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#16 0x00007ffff672e6cc in std::sys_common::backtrace::__rust_begin_short_backtrace ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#17 0x00007ffff673c76c in core::ops::function::FnOnce::call_once{{vtable.shim}} ()
$HOME/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-e924046ea34a2c7b.so
#18 0x00007ffff43a2b37 in alloc::boxed::{{impl}}::call_once<(),FnOnce<()>,alloc::alloc::Global> ()
at /rustc/f64503eb555475d65ae5503ef22439ca5dd394fd/library/alloc/src/boxed.rs:1575
#19 alloc::boxed::{{impl}}::call_once<(),alloc::boxed::Box<FnOnce<()>, alloc::alloc::Global>,alloc::alloc::Global> ()
at /rustc/f64503eb555475d65ae5503ef22439ca5dd394fd/library/alloc/src/boxed.rs:1575
#20 std::sys::unix::thread::{{impl}}::new::thread_start () at library/std/src/sys/unix/thread.rs:71
#21 0x00007ffff42cf299 in start_thread () from /usr/lib/libpthread.so.0
#22 0x00007ffff41e6053 in clone () from /usr/lib/libc.so.6
Meta
rustc --version --verbose
:
rustc 1.54.0-nightly (f64503eb5 2021-05-23)
binary: rustc
commit-hash: f64503eb555475d65ae5503ef22439ca5dd394fd
commit-date: 2021-05-23
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1