Skip to content
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

SIGSEGV compiling AVX-512 inline asm #66223

Closed
athre0z opened this issue Nov 8, 2019 · 5 comments
Closed

SIGSEGV compiling AVX-512 inline asm #66223

athre0z opened this issue Nov 8, 2019 · 5 comments
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@athre0z
Copy link
Contributor

athre0z commented Nov 8, 2019

This (possibly invalid?) inline asm below segfaults the compiler:

#![feature(asm)]

unsafe fn _mm512_set1_epi64(a: i64) {
    asm! {
        "vpbroadcastq zmm0{k1}, $0"
        :: "m"(a)
        :: "intel"
    }
}

fn main() {
    unsafe { _mm512_set1_epi64(123); }
}

Playground link

Rust version: rustc 1.40.0-nightly (1423bec 2019-11-05)

Backtrace

Thread 4 Crashed:
0   librustc_codegen_llvm-llvm.dylib	0x000000010ce1b74d llvm::X86ATTInstPrinter::getRegisterName(unsigned int) + 13
1   librustc_codegen_llvm-llvm.dylib	0x000000010cbfc97e llvm::X86AsmPrinter::PrintOperand(llvm::MachineInstr const*, unsigned int, llvm::raw_ostream&) + 270
2   librustc_codegen_llvm-llvm.dylib	0x000000010cbfd000 llvm::X86AsmPrinter::PrintIntelMemReference(llvm::MachineInstr const*, unsigned int, llvm::raw_ostream&) + 640
3   librustc_codegen_llvm-llvm.dylib	0x000000010cbfd5fb llvm::X86AsmPrinter::PrintAsmMemoryOperand(llvm::MachineInstr const*, unsigned int, char const*, llvm::raw_ostream&) + 59
4   librustc_codegen_llvm-llvm.dylib	0x000000010da9a65f llvm::AsmPrinter::EmitInlineAsm(llvm::MachineInstr const*) const + 1967
5   librustc_codegen_llvm-llvm.dylib	0x000000010da8ad96 llvm::AsmPrinter::EmitFunctionBody() + 3254
6   librustc_codegen_llvm-llvm.dylib	0x000000010cbfbe78 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) + 296
7   librustc_codegen_llvm-llvm.dylib	0x000000010dc0ecd9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 281
8   librustc_codegen_llvm-llvm.dylib	0x000000010e4a2a88 llvm::FPPassManager::runOnFunction(llvm::Function&) + 808
9   librustc_codegen_llvm-llvm.dylib	0x000000010e4a2de3 llvm::FPPassManager::runOnModule(llvm::Module&) + 131
10  librustc_codegen_llvm-llvm.dylib	0x000000010e4a3229 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 857
11  librustc_codegen_llvm-llvm.dylib	0x000000010cbdaae2 LLVMRustWriteOutputFile + 562
12  librustc_codegen_llvm-llvm.dylib	0x000000010cb8d4e6 rustc_codegen_llvm::back::write::write_output_file::hf57707ffdc6e18f0 (.llvm.4680699105796709659) + 86
13  librustc_codegen_llvm-llvm.dylib	0x000000010ca95e19 rustc_codegen_llvm::back::write::codegen::_$u7b$$u7b$closure$u7d$$u7d$::h1e2284aa1f07df86 (.llvm.14548906211475689160) + 1225
14  librustc_codegen_llvm-llvm.dylib	0x000000010ca945b3 rustc::util::common::time_ext::h484a300a27ce3e24 + 163
15  librustc_codegen_llvm-llvm.dylib	0x000000010cb9cc55 _$LT$rustc_codegen_llvm..LlvmCodegenBackend$u20$as$u20$rustc_codegen_ssa..traits..write..WriteBackendMethods$GT$::codegen::ha65c2290ec2d1389 + 3317
16  librustc_codegen_llvm-llvm.dylib	0x000000010cabefa2 std::sys_common::backtrace::__rust_begin_short_backtrace::h4b331c6d068dc9d3 + 3746
17  librustc_codegen_llvm-llvm.dylib	0x000000010cac02fb std::panicking::try::do_call::h721f6a3e03c50e53 (.llvm.15542101850647140514) + 43
18  libstd-cd43daae2cf7ddf1.dylib 	0x0000000107be6d1f __rust_maybe_catch_panic + 31
19  librustc_codegen_llvm-llvm.dylib	0x000000010caa5156 core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::h125a629455a19778 + 134
20  libstd-cd43daae2cf7ddf1.dylib 	0x0000000107bb8a0e _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h9b41d7adac010663 + 62
21  libstd-cd43daae2cf7ddf1.dylib 	0x0000000107be5a5e std::sys::unix::thread::Thread::new::thread_start::h0725fe9398379348 + 142
22  libsystem_pthread.dylib       	0x00007fff68993d76 _pthread_start + 125
23  libsystem_pthread.dylib       	0x00007fff689905d7 thread_start + 15
@nagisa nagisa added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Nov 8, 2019
@nagisa
Copy link
Member

nagisa commented Nov 8, 2019

Please try with a LLVM build that has assertions enabled.

@nagisa nagisa added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-inline-assembly Area: Inline assembly (`asm!(…)`) labels Nov 8, 2019
@athre0z
Copy link
Contributor Author

athre0z commented Nov 9, 2019

As requested, I just built the latest rustc (475c713) from source, with LLVM assertions enabled.

>>> rustc -V
rustc 1.40.0-dev
Compiling rustc-sigsegv v0.1.0 (/Users/ath/Development/rustc-sigsegv)
unknown operand type!
UNREACHABLE executed at /Users/ath/Development/rust/src/llvm-project/llvm/lib/Target/X86/X86AsmPrinter.cpp:207!
error: could not compile `rustc-sigsegv`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rustc_sigsegv src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=cfaa57f8238538cc -C extra-filename=-cfaa57f8238538cc --out-dir /Users/ath/Development/rustc-sigsegv/target/release/deps -L dependency=/Users/ath/Development/rustc-sigsegv/target/release/deps -C target-cpu=native` (signal: 6, SIGABRT: process abort signal)
Thread 5 Crashed:
0   libsystem_kernel.dylib        	0x00007fff7275c47a __pthread_kill + 10
1   libsystem_pthread.dylib       	0x00007fff72819707 pthread_kill + 384
2   libsystem_c.dylib             	0x00007fff726e4a08 abort + 120
3   librustc_codegen_llvm-llvm.dylib	0x000000010585f41e llvm::llvm_unreachable_internal(char const*, char const*, unsigned int) + 462
4   librustc_codegen_llvm-llvm.dylib	0x0000000103d8553d llvm::X86AsmPrinter::PrintOperand(llvm::MachineInstr const*, unsigned int, llvm::raw_ostream&) + 493
5   librustc_codegen_llvm-llvm.dylib	0x0000000103d85f50 llvm::X86AsmPrinter::PrintIntelMemReference(llvm::MachineInstr const*, unsigned int, llvm::raw_ostream&) + 752
6   librustc_codegen_llvm-llvm.dylib	0x0000000103d86679 llvm::X86AsmPrinter::PrintAsmMemoryOperand(llvm::MachineInstr const*, unsigned int, char const*, llvm::raw_ostream&) + 57
7   librustc_codegen_llvm-llvm.dylib	0x00000001042bf513 llvm::AsmPrinter::EmitInlineAsm(llvm::MachineInstr const*) const + 1939
8   librustc_codegen_llvm-llvm.dylib	0x00000001042ada06 llvm::AsmPrinter::EmitFunctionBody() + 2854
9   librustc_codegen_llvm-llvm.dylib	0x0000000103d84848 llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) + 296
10  librustc_codegen_llvm-llvm.dylib	0x00000001044c7c6a llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 330
11  librustc_codegen_llvm-llvm.dylib	0x000000010518ddf0 llvm::FPPassManager::runOnFunction(llvm::Function&) + 1040
12  librustc_codegen_llvm-llvm.dylib	0x000000010518e113 llvm::FPPassManager::runOnModule(llvm::Module&) + 131
13  librustc_codegen_llvm-llvm.dylib	0x000000010518e5a2 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 898
14  librustc_codegen_llvm-llvm.dylib	0x0000000103d5f41f LLVMRustWriteOutputFile + 559
15  librustc_codegen_llvm-llvm.dylib	0x0000000103d25a16 rustc_codegen_llvm::back::write::write_output_file::h759bbedac00052e7 + 86
16  librustc_codegen_llvm-llvm.dylib	0x0000000103d10325 rustc_codegen_llvm::back::write::codegen::_$u7b$$u7b$closure$u7d$$u7d$::h1c521ce99173cfc9 (.llvm.8720060979851273667) + 1141
17  librustc_codegen_llvm-llvm.dylib	0x0000000103d0f9e3 rustc::util::common::time_ext::h9514d078fc909e9a + 163
18  librustc_codegen_llvm-llvm.dylib	0x0000000103d290fc rustc_codegen_llvm::back::write::codegen::h9f2d7d8d3aa37443 + 3196
19  librustc_codegen_llvm-llvm.dylib	0x0000000103d42a23 rustc_codegen_ssa::back::write::execute_work_item::h7528378acd4d9784 + 499
20  librustc_codegen_llvm-llvm.dylib	0x0000000103d5bb92 std::sys_common::backtrace::__rust_begin_short_backtrace::hfced81a9c03b20d6 + 242
21  librustc_codegen_llvm-llvm.dylib	0x0000000103c524cb std::panicking::try::do_call::h1930a25734e038db (.llvm.14567149245432969043) + 43
22  libstd-148845df6e670d53.dylib 	0x000000010389438f __rust_maybe_catch_panic + 31
23  librustc_codegen_llvm-llvm.dylib	0x0000000103d305c6 core::ops::function::FnOnce::call_once$u7b$$u7b$vtable.shim$u7d$$u7d$::he0fb440a524af8d4 + 134
24  libstd-148845df6e670d53.dylib 	0x000000010388ad1e _$LT$alloc..boxed..Box$LT$F$GT$$u20$as$u20$core..ops..function..FnOnce$LT$A$GT$$GT$::call_once::h2b7e113d1172c209 + 62
25  libstd-148845df6e670d53.dylib 	0x00000001038617de std::sys_common::thread::start_thread::h651378ca55643958 + 142
26  libstd-148845df6e670d53.dylib 	0x0000000103882eb9 std::sys::unix::thread::Thread::new::thread_start::hf3afdbafdcb0fb09 + 9
27  libsystem_pthread.dylib       	0x00007fff72819d76 _pthread_start + 125
28  libsystem_pthread.dylib       	0x00007fff728165d7 thread_start + 15

It is worth noting that this only occurs when building with --release -- debug builds are fine.

@nagisa
Copy link
Member

nagisa commented Nov 9, 2019

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 9, 2019
@JohnTitor JohnTitor added the requires-nightly This issue requires a nightly compiler in some way. label Apr 22, 2020
@JohnTitor
Copy link
Member

I think this issue should be fixed by #67759.

@Amanieu
Copy link
Member

Amanieu commented May 22, 2020

This issue does not apply to the new asm! (RFC 2850) which doesn't support memory constraints.

The legacy llvm_asm! is deprecated and is no longer maintained.

@Amanieu Amanieu closed this as completed May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inline-assembly Area: Inline assembly (`asm!(…)`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants