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

ICE on #[link(..., kind = "raw-dylib")] #93842

Closed
ricobbe opened this issue Feb 10, 2022 · 3 comments · Fixed by #98989
Closed

ICE on #[link(..., kind = "raw-dylib")] #93842

ricobbe opened this issue Feb 10, 2022 · 3 comments · Fixed by #98989
Assignees
Labels
C-bug Category: This is a bug. F-raw_dylib `#![feature(raw_dylib)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-windows Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ricobbe
Copy link
Contributor

ricobbe commented Feb 10, 2022

Code

#![feature(raw_dylib)]
#[link(name = "kernel32", kind = "raw-dylib")]
extern "system" {
    fn WaitForSingleObject(handle: isize, dwmilliseconds: u32) -> u32;
}
fn main() {
    unsafe { WaitForSingleObject(0, 0); }
    println!("ok");
}

Cargo.toml:

[package]
name = "waitfor"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

Compile with cargo +nightly run. ICE reproducible on {x86_64,i686}-pc-windows-{msvc,gnu}. Non-windows platforms are irrelevant, as the problem involves the raw_dylib feature, which is only implemented on Windows.

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (e7aca8959 2022-02-09)
binary: rustc
commit-hash: e7aca895980f25f6d2d3c48e10fd04656764d1e4
commit-date: 2022-02-09
host: x86_64-pc-windows-msvc
release: 1.60.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'compiler\rustc_codegen_ssa\src\back\link.rs:2066:17: raw_dylib feature not yet implemented', compiler\rustc_middle\src\util\bug.rs:35:26
Backtrace

stack backtrace:
   0:     0x7ffcb3527d30 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd9a1cc8c1ba9a6ad
   1:     0x7ffcb355779a - core::fmt::write::h346f1639821b09ca
   2:     0x7ffcb3519119 - <std::io::IoSlice as core::fmt::Debug>::fmt::h6ed49041e1bde020
   3:     0x7ffcb352b4a2 - std::panicking::default_hook::hb86a255b5ae1a1b5
   4:     0x7ffcb352b063 - std::panicking::default_hook::hb86a255b5ae1a1b5
   5:     0x7ffca5e4ca76 - <rustc_driver[62efd2c0abe8586f]::args::Error as core[22e88df2c075810]::fmt::Debug>::fmt
   6:     0x7ffcb352bdd2 - std::panicking::rust_panic_with_hook::h0b2277542f9fb56f
   7:     0x7ffcaa28444d - <rustc_middle[69d22b9b016ab07c]::ty::vtable::VtblEntry as core[22e88df2c075810]::fmt::Debug>::fmt
   8:     0x7ffcaa282abf - <rustc_middle[69d22b9b016ab07c]::traits::select::EvaluationResult>::is_stack_dependent
   9:     0x7ffcaa89ba86 - rustc_middle[69d22b9b016ab07c]::ty::context::invalid_hir_id_for_typeck_results
  10:     0x7ffcaa2825f6 - <rustc_middle[69d22b9b016ab07c]::traits::select::EvaluationResult>::is_stack_dependent
  11:     0x7ffcaa28459a - <rustc_middle[69d22b9b016ab07c]::ty::vtable::VtblEntry as core[22e88df2c075810]::fmt::Debug>::fmt
  12:     0x7ffcaa285049 - <rustc_middle[69d22b9b016ab07c]::ty::vtable::VtblEntry as core[22e88df2c075810]::fmt::Debug>::fmt
  13:     0x7ffcaa89af90 - rustc_middle[69d22b9b016ab07c]::util::bug::bug_fmt
  14:     0x7ffca977984d - rustc_codegen_ssa[2943325f22fd461c]::back::link::add_local_native_libraries
  15:     0x7ffca60d3b14 - <rustc_codegen_llvm[ed7fa6d6e12b934]::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa[2943325f22fd461c]::back::archive::ArchiveBuilder>::inject_dll_import_lib
  16:     0x7ffca60d0c9a - <rustc_codegen_llvm[ed7fa6d6e12b934]::back::archive::LlvmArchiveBuilder as rustc_codegen_ssa[2943325f22fd461c]::back::archive::ArchiveBuilder>::inject_dll_import_lib
  17:     0x7ffca60b6185 - <rustc_codegen_llvm[ed7fa6d6e12b934]::LlvmCodegenBackend as rustc_codegen_ssa[2943325f22fd461c]::traits::backend::CodegenBackend>::link
  18:     0x7ffca5f797e8 - <rustc_interface[f518e6e170a46fb9]::queries::Linker>::link
  19:     0x7ffca5de9cb0 - <rustc_driver[62efd2c0abe8586f]::args::Error as core[22e88df2c075810]::fmt::Debug>::fmt
  20:     0x7ffca5ddef0a - <tracing_log[8e7bf0df484a8cae]::InfoCallsite as tracing_core[e4007ebade0f9e88]::callsite::Callsite>::set_interest
  21:     0x7ffca5dbf7c3 - <tracing_log[8e7bf0df484a8cae]::InfoCallsite as tracing_core[e4007ebade0f9e88]::callsite::Callsite>::set_interest
  22:     0x7ffca5e62fa8 - rustc_driver[62efd2c0abe8586f]::pretty::print_after_hir_lowering
  23:     0x7ffcb353c73c - std::sys::windows::thread::Thread::new::h1745d7e554009389
  24:     0x7ffd53661474 - BaseThreadInitThunk
  25:     0x7ffd549b26d8 - RtlUserThreadStart

@ricobbe ricobbe added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 10, 2022
@ricobbe
Copy link
Contributor Author

ricobbe commented Feb 10, 2022

@rustbot claim

@ricobbe
Copy link
Contributor Author

ricobbe commented Feb 10, 2022

Underlying problem: I never got around to implementing raw-dylib support when used in a bin crate; it only works in lib crates currently. However, that's clearly a case that is supposed to work, and it should be relatively easy to fix -- it's just a case of adding the necessary stuff to the code path used to build up the linker command line for bin crates.

@bjorn3 bjorn3 added the F-raw_dylib `#![feature(raw_dylib)]` label Feb 10, 2022
fanninpm added a commit to fanninpm/glacier that referenced this issue Feb 15, 2022
@Alexendoo Alexendoo added the O-windows Operating system: Windows label Feb 15, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Feb 15, 2022
@ricobbe ricobbe removed their assignment Apr 28, 2022
@dpaoliello
Copy link
Contributor

@rustbot claim

JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 4, 2022
…erister

Enable raw-dylib for bin crates

Fixes rust-lang#93842

When a `raw-dylib` is used in a `bin` crate, we need to link to the library name specified.
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 4, 2022
…erister

Enable raw-dylib for bin crates

Fixes rust-lang#93842

When a `raw-dylib` is used in a `bin` crate, we need to link to the library name specified.
@bors bors closed this as completed in daaae25 Jul 26, 2022
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Aug 24, 2022
…ister

Enable raw-dylib for bin crates

Fixes rust-lang#93842

When `raw-dylib` is used in a `bin` crate, we need to collect all of the `raw-dylib` functions, generate the import library and add that to the linker command line.

I also changed the tests so that 1) the C++ dlls are created after the Rust dlls, thus there is no chance of accidentally using them in the Rust linking process and 2) disabled generating import libraries when building with MSVC.
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this issue Mar 7, 2023
…ister

Enable raw-dylib for bin crates

Fixes rust-lang#93842

When `raw-dylib` is used in a `bin` crate, we need to collect all of the `raw-dylib` functions, generate the import library and add that to the linker command line.

I also changed the tests so that 1) the C++ dlls are created after the Rust dlls, thus there is no chance of accidentally using them in the Rust linking process and 2) disabled generating import libraries when building with MSVC.
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. F-raw_dylib `#![feature(raw_dylib)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ O-windows Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants