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

can't call foreign function: InitOnceBeginInitialize when running on Windows #2595

Closed
V0ldek opened this issue Oct 14, 2022 · 2 comments · Fixed by #2601
Closed

can't call foreign function: InitOnceBeginInitialize when running on Windows #2595

V0ldek opened this issue Oct 14, 2022 · 2 comments · Fixed by #2601
Labels
A-windows Area: affects only Windows targets C-bug Category: This is a bug.

Comments

@V0ldek
Copy link
Contributor

V0ldek commented Oct 14, 2022

My crate aligners got a failure in a scheduled Miri pipeline (job) absent any changes to the crate's code on the nightly version available in the night between 13th and 14th of October.

Three of the pipeline targets seem to be failing:

  • x86_64-pc-windows-gnu
  • i686-pc-windows-gnu
  • i686-pc-windows-msvc

Surprisingly, x86_64-pc-windows-msvc seems to be working.

Here's the full error:

error: unsupported operation: can't call foreign function: InitOnceBeginInitialize
Error:   --> C:\Users\runneradmin\.rustup\toolchains\nightly-x86_[64](https://github.com/V0ldek/aligners/actions/runs/3246804722/jobs/5333903357#step:4:65)-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\windows\thread_local_key.rs:88:21
   |
88 |             let r = c::InitOnceBeginInitialize(self.once.get(), 0, &mut pending, ptr::null_mut());
   |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't call foreign function: InitOnceBeginInitialize
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
   = note: BACKTRACE:
   = note: inside `std::sys::windows::thread_local_key::StaticKey::init` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\windows\thread_local_key.rs:88:21
   = note: inside `std::sys::windows::thread_local_key::StaticKey::key` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\windows\thread_local_key.rs:79:18
   = note: inside `std::sys::windows::thread_local_key::StaticKey::get` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys\windows\thread_local_key.rs:73:24
   = note: inside `std::thread::__OsLocalKeyInner::<std::cell::RefCell<std::option::Option<std::sys_common::thread_info::ThreadInfo>>>::get::<[closure@std::sys_common::thread_info::THREAD_INFO::__getit::{closure#0}]>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:1080:32
   = note: inside `std::sys_common::thread_info::THREAD_INFO::__getit` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:271:21
   = note: inside `std::thread::LocalKey::<std::cell::RefCell<std::option::Option<std::sys_common::thread_info::ThreadInfo>>>::try_with::<[closure@std::sys_common::thread_info::set::{closure#0}], ()>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:445:32
   = note: inside `std::thread::LocalKey::<std::cell::RefCell<std::option::Option<std::sys_common::thread_info::ThreadInfo>>>::with::<[closure@std::sys_common::thread_info::set::{closure#0}], ()>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:422:9
   = note: inside `std::sys_common::thread_info::set` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\sys_common\thread_info.rs:42:5
   = note: inside `std::rt::init` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:105:9
   = note: inside closure at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:147:42
   = note: inside `std::panicking::r#try::do_call::<[closure@std::rt::lang_start_internal::{closure#1}], ()>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:483:40
   = note: inside `std::panicking::r#try::<(), [closure@std::rt::lang_start_internal::{closure#1}]>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panicking.rs:447:19
   = note: inside `std::panic::catch_unwind::<[closure@std::rt::lang_start_internal::{closure#1}], ()>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\panic.rs:137:14
   = note: inside `std::rt::lang_start_internal` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:147:5
   = note: inside `std::rt::lang_start::<()>` at C:\Users\runneradmin\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\rt.rs:1[65](https://github.com/V0ldek/aligners/actions/runs/3246804722/jobs/5333903357#step:4:66):17

There's none of my code in this trace. The tests failing are here, but they don't seem to be even running when this fails. Rerunning the actions causes the same result, so it doesn't look like a transient error.

@RalfJung
Copy link
Member

RalfJung commented Oct 14, 2022

Yes indeed, rust-lang/rust#102655 started using those functions so the i686-pc-windows-msvc target is currently defunct.

x86_64-pc-windows-msvc should work though, so if you add --target x86_64-pc-windows-msvc that should help. I am surprised that you state that that target does not work, since when I try it its tests pass (and rustc CI also checks that target).

EDIT: ah, I misread. You said the 64bit GNU target is broken, but the 64bit MSVC target works. That agrees with my observations.

@RalfJung RalfJung added C-bug Category: This is a bug. A-windows Area: affects only Windows targets labels Oct 14, 2022
@ChrisDenton
Copy link
Member

It depends on if the platform natively supports static Thread Local Storage (TLS). If not then this fallback code is used which includes these new functions.

All windows-gnu targets have their own emulated TLS which does not play well with static TLS so the fallback is used. Static TLS should work on all msvc targets but for mysterious reasons it causes crashes on x86 so it's currently disabled there,

bors added a commit that referenced this issue Oct 19, 2022
use Scalar return types for Windows shims

I started doing this while working on #2595; now I don't need the rest of this patch but this part still makes sense.
@bors bors closed this as completed in 64757ed Oct 20, 2022
RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 22, 2022
use Scalar return types for Windows shims

I started doing this while working on rust-lang/miri#2595; now I don't need the rest of this patch but this part still makes sense.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-windows Area: affects only Windows targets C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants