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

Segfault when using llvm_asm memory constraint #87612

Closed
tuomas56 opened this issue Jul 30, 2021 · 3 comments · Fixed by #92816
Closed

Segfault when using llvm_asm memory constraint #87612

tuomas56 opened this issue Jul 30, 2021 · 3 comments · Fixed by #92816
Labels
C-bug Category: This is a bug.

Comments

@tuomas56
Copy link

I tried this code:

#![feature(llvm_asm)]
#![crate_type="staticlib"]

// using no_mangle to force codegen, otherwise nothing is emitted
#[no_mangle]
pub unsafe fn test() -> u32 {
    let test: u32;
    llvm_asm!("mov $$32, $0" : "=m"(test));
    test
}

I expected to see this happen:

> rustc test.rs
<no output>

Instead, this happened:

> rustc test.rs 
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x4fdb63)[0x7f6a182c2b63]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x153c0)[0x7f6a17a1f3c0]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm19SelectionDAGBuilder14visitInlineAsmERKNS_8CallBaseE+0x1621)[0x7f6a14f71c31]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm19SelectionDAGBuilder5visitERKNS_11InstructionE+0x67)[0x7f6a14f4ff07]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm16SelectionDAGISel16SelectBasicBlockENS_14ilist_iteratorINS_12ilist_detail12node_optionsINS_11InstructionELb0ELb0EvEELb0ELb1EEES6_Rb+0x12e)[0x7f6a1500f3be]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x1a3b)[0x7f6a1500e49b]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0xb1d)[0x7f6a1500ba9d]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(+0x48c1177)[0x7f6a16f13177]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0xee)[0x7f6a14b3496e]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x639)[0x7f6a148f7869]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x33)[0x7f6a148fe703]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x470)[0x7f6a148f80d0]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x20c41e8)[0x7f6a19e891e8]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x2050c3f)[0x7f6a19e15c3f]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x2053afc)[0x7f6a19e18afc]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x204f29b)[0x7f6a19e1429b]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x2048ada)[0x7f6a19e0dada]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x20940bc)[0x7f6a19e590bc]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x20b267c)[0x7f6a19e7767c]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/libstd-9c44f1fe63de3edb.so(rust_metadata_std_ed022288c3a1d27e+0xa8a97)[0x7f6a17aeda97]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9609)[0x7f6a17a13609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7f6a17927293]
Segmentation fault

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (492723897 2021-07-29)
binary: rustc
commit-hash: 492723897e9b4db6701b3a75b72618d08a7d5319
commit-date: 2021-07-29
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1
Backtrace

> BACKTRACE=1 rustc test.rs
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x4fdb63)[0x7f6d10697b63]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x153c0)[0x7f6d0fdf43c0]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm19SelectionDAGBuilder14visitInlineAsmERKNS_8CallBaseE+0x1621)[0x7f6d0d346c31]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm19SelectionDAGBuilder5visitERKNS_11InstructionE+0x67)[0x7f6d0d324f07]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm16SelectionDAGISel16SelectBasicBlockENS_14ilist_iteratorINS_12ilist_detail12node_optionsINS_11InstructionELb0ELb0EvEELb0ELb1EEES6_Rb+0x12e)[0x7f6d0d3e43be]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm16SelectionDAGISel20SelectAllBasicBlocksERKNS_8FunctionE+0x1a3b)[0x7f6d0d3e349b]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm16SelectionDAGISel20runOnMachineFunctionERNS_15MachineFunctionE+0xb1d)[0x7f6d0d3e0a9d]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(+0x48c1177)[0x7f6d0f2e8177]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE+0xee)[0x7f6d0cf0996e]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x639)[0x7f6d0cccc869]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x33)[0x7f6d0ccd3703]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x470)[0x7f6d0cccd0d0]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x20c41e8)[0x7f6d1225e1e8]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x2050c3f)[0x7f6d121eac3f]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x2053afc)[0x7f6d121edafc]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x204f29b)[0x7f6d121e929b]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x2048ada)[0x7f6d121e2ada]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x20940bc)[0x7f6d1222e0bc]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so(+0x20b267c)[0x7f6d1224c67c]
/home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/libstd-9c44f1fe63de3edb.so(rust_metadata_std_ed022288c3a1d27e+0xa8a97)[0x7f6d0fec2a97]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9609)[0x7f6d0fde8609]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43)[0x7f6d0fcfc293]
Segmentation fault

GDB Backtrace

Reading symbols from rustc...
(gdb) run test.rs
Starting program: /home/tuomas/.cargo/bin/rustc test.rs
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
process 12241 is executing new program: /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffee3ff700 (LWP 12245)]
[New Thread 0x7fffe8387700 (LWP 12246)]
[New Thread 0x7fffe7dff700 (LWP 12247)]
[New Thread 0x7fffe73ff700 (LWP 12248)]
[New Thread 0x7fffe6dff700 (LWP 12249)]

Thread 6 "opt test.6a6880" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffe6dff700 (LWP 12249)]
0x00007ffff1809c31 in llvm::SelectionDAGBuilder::visitInlineAsm(llvm::CallBase const&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
(gdb) bt
#0  0x00007ffff1809c31 in llvm::SelectionDAGBuilder::visitInlineAsm(llvm::CallBase const&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#1  0x00007ffff17e7f07 in llvm::SelectionDAGBuilder::visit(llvm::Instruction const&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#2  0x00007ffff18a73be in llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, false, false, void>, false, true>, bool&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#3  0x00007ffff18a649b in llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#4  0x00007ffff18a3a9d in llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#5  0x00007ffff37ab177 in (anonymous namespace)::X86DAGToDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .llvm.6640036156556231831] ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#6  0x00007ffff13cc96e in llvm::MachineFunctionPass::runOnFunction(llvm::Function&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#7  0x00007ffff118f869 in llvm::FPPassManager::runOnFunction(llvm::Function&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#8  0x00007ffff1196703 in llvm::FPPassManager::runOnModule(llvm::Module&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightl--Type <RET> for more, q to quit, c to continue without paging--
y.so
#9  0x00007ffff11900d0 in llvm::legacy::PassManagerImpl::run(llvm::Module&) ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/../lib/libLLVM-12-rust-1.56.0-nightly.so
#10 0x00007ffff67211e8 in LLVMRustWriteOutputFile ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#11 0x00007ffff66adc3f in rustc_codegen_llvm::back::write::write_output_file ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#12 0x00007ffff66b0afc in rustc_codegen_llvm::back::write::codegen ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#13 0x00007ffff66ac29b in rustc_codegen_ssa::back::write::finish_intra_module_work ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#14 0x00007ffff66a5ada in rustc_codegen_ssa::back::write::execute_work_item ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#15 0x00007ffff66f10bc in std::sys_common::backtrace::__rust_begin_short_backtrace ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#16 0x00007ffff670f67c in core::ops::function::FnOnce::call_once{{vtable-shim}} ()
   from /home/tuomas/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/../lib/librustc_driver-41fdbb8b89e55544.so
#17 0x00007ffff4385a97 in <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once ()
    at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/alloc/src/boxed.rs:1572
#18 <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once ()
    at /rustc/492723897e9b4db6701b3a75b72618d08a7d5319/library/alloc/src/boxed.rs:1572
#19 std::sys::unix::thread::Thread::new::thread_start () at library/std/src/sys/unix/thread.rs:91
#20 0x00007ffff42ab609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x00007ffff41bf293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

@tuomas56 tuomas56 added the C-bug Category: This is a bug. label Jul 30, 2021
@jackh726
Copy link
Member

jackh726 commented Aug 3, 2021

llvm_asm is soon to be deprecated in favor of asm.

I'm not sure if we're still tracking llvm_asm issues cc @Amanieu

@Amanieu
Copy link
Member

Amanieu commented Aug 4, 2021

I'm in favor of closing all llvm_asm issues once #87590 lands.

@Amanieu
Copy link
Member

Amanieu commented Aug 4, 2021

Practically speaking, nobody is working on improving/fixing llvm_asm, so I doubt any llvm_asm bugs will ever get fixed.

@bors bors closed this as completed in a34c079 Jan 17, 2022
flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 27, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Feb 23, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Mar 30, 2022
Remove deprecated LLVM-style inline assembly

The `llvm_asm!` was deprecated back in rust-lang#87590 1.56.0, with intention to remove
it once `asm!` was stabilized, which already happened in rust-lang#91728 1.59.0. Now it
is time to remove `llvm_asm!` to avoid continued maintenance cost.

Closes rust-lang#70173.
Closes rust-lang#92794.
Closes rust-lang#87612.
Closes rust-lang#82065.

cc `@rust-lang/wg-inline-asm`

r? `@Amanieu`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants