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

Miscompilation of Bevy with MSVC #1249

Closed
PROMETHIA-27 opened this issue Jul 25, 2022 · 56 comments · Fixed by #1363
Closed

Miscompilation of Bevy with MSVC #1249

PROMETHIA-27 opened this issue Jul 25, 2022 · 56 comments · Fixed by #1363
Labels
C-bug Category: This is a bug. O-windows Operating system: Windows

Comments

@PROMETHIA-27
Copy link

PROMETHIA-27 commented Jul 25, 2022

Compiling on windows with the latest CI artifact build.

Full error message:

   Compiling bevy_reflect v0.7.0
error: could not compile `bevy_reflect`

Caused by:
  process didn't exit successfully: `rustc --crate-name bevy_reflect --edition=2021 C:\Users\elect\.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\bevy_reflect-0.7.0\src\lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C metadata=93cc29b344f5fd9d -C extra-filename=-93cc29b344f5fd9d --out-dir C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps -L dependency=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps --extern bevy_reflect_derive=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\bevy_reflect_derive-7a7ec19481b36f7b.dll --extern bevy_utils=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\libbevy_utils-638c5a2ec5f001df.rmeta --extern downcast_rs=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\libdowncast_rs-f56d5e827a193966.rmeta --extern erased_serde=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\liberased_serde-9c11269d65f6973f.rmeta --extern parking_lot=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\libparking_lot-63f537677751ed65.rmeta --extern serde=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\libserde-b6c12e91e4361d2b.rmeta --extern thiserror=C:\Assets\ProgrammingProjects\Rust\testing\target\debug\deps\libthiserror-546b84b988865560.rmeta --cap-lints allow -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=C:\users\elect\desktop\cg_clif\build\bin\rustc_codegen_cranelift.dll --sysroot C:\users\elect\desktop\cg_clif\build -L native=C:\Users\elect\.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\winapi-x86_64-pc-windows-gnu-0.4.0\lib` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

Not sure what's causing this. Happens consistently, so it's not random, but I have no idea what's in bevy_reflect that causes it. It's a pretty simple crate, doesn't do anything particularly weird.

Unfortunately this crate is depended on by the most important bevy crates, so bevy as a whole can't be compiled on cranelift.
Not certain if this is limited to windows/just my PC, unable to test it anywhere else. Going to try and play with it to see if I can learn anything about it.

EDIT: This appears to not apply to the main branch of bevy. Instead, the main branch has the same error on bevy_hierarchy.
EDIT 2: This appears to also not apply to compiling the main branch directly, rather than as a git dependency. That works fine.
EDIT 3: After some testing, these appear to be the conditions of the crash:

  1. There must be a tuple struct type T present in a dependency with the following conditions: (named structs and any enum types do not cause this issue)
  2. The type must contain a field which is an instantiation of a generic type, in which the instantiation passes a slice or array type of (seemingly) any type or length directly. Passing a &[T] does not trigger it; only a [T]. As such this does not occur if nesting types, unless the nesting is to produce a multidimensional array. This also does not occur if the field itself is an array or slice. Not all dynamically sized types cause this issue; str is fine. Not all types taking a const generic parameter cause this issue; a Custom<const T: u32> is fine.
  3. The type must #[derive(Component)], referring to bevy_ecs's Component trait. Manual impls do not cause this issue. The manual impl is as follows:
impl Component for T {
    type Storage = TableStorage;
}

No other derive I tested causes this issue.

This issue occurs for the Children type in bevy_hierarchy which has the following definition:

/// Contains references to the child entities of this entity
#[derive(Component, Debug, Reflect)]
#[reflect(Component, MapEntities)]
pub struct Children(pub(crate) SmallVec<[Entity; 8]>);

Unable to identify the problem in bevy_reflect. There are no instances of #[derive(Component)], but many other macros which are significantly more complex than Component.

@bjorn3
Copy link
Member

bjorn3 commented Jul 25, 2022

Are you able to attach a debugger and get a backtrace when it crashes?

@bjorn3 bjorn3 added C-bug Category: This is a bug. O-windows Operating system: Windows labels Jul 25, 2022
@PROMETHIA-27
Copy link
Author

PROMETHIA-27 commented Jul 25, 2022

Yes, but I'm not sure what to look for. It might be hitting a UD2 instruction but I don't really think so, that's about all that stands out to me. The stack is just a bunch of offsets in the assembly. I tried building from source with --debug to see if that would put debug info back in, but that doesn't seem to have done anything.

Edit: Also just noticed that jit and lazy-jit have the same issue with a hello world project.

@bjorn3
Copy link
Member

bjorn3 commented Jul 25, 2022

I'm probably not going to get around debugging this myself soon as I don't have a windows dev environment for rust set up. I unfortunately also don't have a clue where the bug could be, so I can't do a blind attempt at fixing it either. Linux has the best support as that is what I use myself. *Bsd also works really well as it is close enough to Linux. macOS should work too most of the time, but support is a tiny bit worse as it uses a different object file format. Windows support is not the best as you noticed. Only the MinGW toolchain is supported at all.

@PROMETHIA-27
Copy link
Author

That's unfortunate. I don't have the expertise to debug any further than I have, but hopefully someone will be able to pick this up at a later date.

@bjorn3
Copy link
Member

bjorn3 commented Aug 8, 2022

https://github.com/bjorn3/rustc_codegen_cranelift/pull/1255 shows an ABI incompatibility with MSVC. Debugging that one should probably be easier than this.

@afonso360
Copy link
Contributor

Hey @PROMETHIA-27, would you be able to test this branch to see if it fixes the issues you are experiencing?

It contains a fix for an ABI issue that sounds suspiciously like what you are hitting.

@PROMETHIA-27
Copy link
Author

I was unable to build the project (kept getting error: the 'cargo.exe' binary, normally provided by the 'cargo' component, is not applicable to the 'nightly-2022-07-27-x86_64-pc-windows-gnu' toolchain), but I grabbed an artifact off of CI and that worked! Looks like bevy can now run on cargo_cranelift on windows. Unfortunately jit and lazy-jit seem to still just STATUS_ACCESS_VIOLATION rustc while compiling. Maybe it's not properly removing the execution protection on the allocations it uses to emit code?

@afonso360
Copy link
Contributor

but I grabbed an artifact off of CI and that worked!

That's great! 🎉

Unfortunately jit and lazy-jit seem to still just STATUS_ACCESS_VIOLATION rustc while compiling. Maybe it's not properly removing the execution protection on the allocations it uses to emit code?

I haven't really tested anything with the jit, I think I disabled it early on for windows when porting the testsuite into rust.

Hopefully it's something simple 😄

@bjorn3
Copy link
Member

bjorn3 commented Aug 20, 2022

but I grabbed an artifact off of CI and that worked!

Nice!

Unfortunately jit and lazy-jit seem to still just STATUS_ACCESS_VIOLATION rustc while compiling. Maybe it's not properly removing the execution protection on the allocations it uses to emit code?

Cranelift-jit should set the mappings to RX before an attempt at executing the code is made.

@afonso360
Copy link
Contributor

We do run the cranelift test suite on the JIT, and it runs fine on windows. But I don't know much beyond that.

@bjorn3
Copy link
Member

bjorn3 commented Sep 27, 2022

@PROMETHIA-27
Copy link
Author

PROMETHIA-27 commented Sep 27, 2022

So:

  • I was able to actually build the project this time, after clearing my toolchains out. And letting it reinstall the override one. I guess that was on my side
  • Building hello world works fine
  • Building with bevy as a dependency works, but trying to run a default app segfaults
  • Both jit modes segfault while compiling on a hello_world project
  • At least regular jit (probably lazy too) fails to compile with bevy as a dependency because static libs (this seems intended, but i figured it was worth noting since this implies that it segfaults sometime after this step; which occurs after every crate is compiled)

I think that's a regression overall? IIRC I had the default app actually running last time

@afonso360
Copy link
Contributor

Building with bevy as a dependency works, but trying to run a default app segfaults

Yeah, this sounds like a regression, I'll try to reproduce that locally

The JIT segfaulting is also something I'm able to reproduce, but It was segfaulting before, so I don't think that one is a regression.

@afonso360
Copy link
Contributor

afonso360 commented Sep 27, 2022

I'm having some issues reproducing this. I've cloned bevy, and ran

..\rustc_codegen_cranelift\build\cargo-clif.exe run -v --example breakout

This compiles fine all the way until the last linking step, and then it seems to be stuck on the last linking step. The linker is using 100% of one cpu core, and has been running for the last 10 mins. Did you also run into this?

I tried both on the latest and main branch, I also tried --example rotation and -Zshare-generics=off because is saw some users with a linker error. But all of those yield the same issue.

build output:
...
   Compiling bevy v0.9.0-dev (C:\Users\Afonso\CLionProjects\bevy)
     Running `rustc --crate-name breakout --edition=2021 examples/games/breakout.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link
 -C embed-bitcode=no -C debuginfo=2 --cfg "feature=\"animation\"" --cfg "feature=\"bevy_asset\"" --cfg "feature=\"bevy_audio\"" --cfg "feature=\"bevy_gilrs\"" --cfg "feature=\"bevy_scene\"" --cfg "fe
ature=\"bevy_winit\"" --cfg "feature=\"default\"" --cfg "feature=\"filesystem_watcher\"" --cfg "feature=\"hdr\"" --cfg "feature=\"png\"" --cfg "feature=\"render\"" --cfg "feature=\"vorbis\"" --cfg "f
eature=\"x11\"" -C metadata=a5f9a42575642687 --out-dir C:\Users\Afonso\CLionProjects\bevy\target\debug\examples -C incremental=C:\Users\Afonso\CLionProjects\bevy\target\debug\incremental -L dependenc
y=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps --extern anyhow=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\libanyhow-15561fa7fc3f4ef7.rlib --extern bevy=C:\Users\Afonso\CLionProjects
\bevy\target\debug\deps\libbevy-50ceb663272dd135.rlib --extern bevy_internal=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\libbevy_internal-34cbf0c23f394258.rlib --extern bytemuck=C:\Users\Afo
nso\CLionProjects\bevy\target\debug\deps\libbytemuck-edb0d53af52ff1a8.rlib --extern crossbeam_channel=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\libcrossbeam_channel-badd8b417dd3f093.rlib -
-extern futures_lite=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\libfutures_lite-e798f34ff12dff42.rlib --extern rand=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\librand-240071f861a3
028b.rlib --extern ron=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\libron-95741b88d4d68ccd.rlib --extern serde=C:\Users\Afonso\CLionProjects\bevy\target\debug\deps\libserde-14009cd3ea1fb87c.
rlib -Cpanic=abort -Zpanic-abort-tests -Zcodegen-backend=C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift\build\bin\rustc_codegen_cranelift.dll --sysroot C:\Users\Afonso\CLionProjects\rustc_code
gen_cranelift\build -L native=C:\Users\Afonso\.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\windows_x86_64_msvc-0.36.1\lib -L native=C:\Users\Afonso\.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\
windows_x86_64_msvc-0.37.0\lib`
    Building [=======================> ] 277/278: breakout(example)

Edit: Ok, so I re read this issue and it looks like you are using a hello world application (presumably this?) and compiling bevy as a dependency.

When I tried to do that, everything compiled and ran as expected.

Here's a repo with what I tried. Can you test that and see if it crashes for you?

@PROMETHIA-27
Copy link
Author

I tested two projects: one was hello world,

fn main() {
  println!("Hello, world!");
}

and the other was a bevy default app.

use bevy::prelude::*;
fn main() {
  App::new().add_plugins(DefaultPlugins).run();
}

Your repo does seem to work fine.

@afonso360
Copy link
Contributor

afonso360 commented Sep 27, 2022

Right, with the default app, I run into the linker being stuck issue. 😕

I'm going to try and troubleshoot that

@afonso360
Copy link
Contributor

afonso360 commented Sep 27, 2022

So, I let this run for a while with the default app, and it turns out its just really really slow. 18min to compile slow 🧐

   Compiling bevy_hello_world v0.1.0 (C:\Users\Afonso\CLionProjects\bevy_hello_world)
    Finished dev [unoptimized + debuginfo] target(s) in 18m 09s
     Running `target\debug\bevy_hello_world.exe`
thread 'main' panicked at 'Initializing the event loop outside of the main thread is a significant cross-platform compatibility hazard. If you really, absolutely need to create an EventLoop on a diff
erent thread, please use the `EventLoopExtWindows::new_any_thread` function.', C:\Users\Afonso\.cargo\registry\src\github.aaakk.us.kg-1ecc6299db9ec823\winit-0.26.1\src\platform_impl\windows\event_loop.rs:139
:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\bevy_hello_world.exe` (exit code: 0xc000001d, STATUS_ILLEGAL_INSTRUCTION)
PS C:\Users\Afonso\CLionProjects\bevy_hello_world>

But at least I can reproduce something, I'll track this down and see where it gets. Is that the error that you are also seeing?

Edit: It seems some people are also hitting this with LLVM, so it may be an issue with the VS version I'm using

Edit 2: I replaced the default linker with rust-lld.exe and it compiled and ran the default app fine, can you test this branch?

Edit 3: (sorry I don't want to spam notifications)

I re-tried the bevy example breakout with the rust-lld.exe trick and it compiled and ran fine on my system! 🎉

I wonder if the issues we are seeing are all related to MSVC linker stuff? I'm using VS2019 with this linker version:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>link.exe
Microsoft (R) Incremental Linker Version 14.29.30146.0
Copyright (C) Microsoft Corporation.  All rights reserved.

@PROMETHIA-27
Copy link
Author

PROMETHIA-27 commented Sep 27, 2022

No, the error I got was a segfault (or window's equivalent, STATUS_ACCESS_VIOLATION) and it didn't take an abnormal amount of time to compile.
Switching to LLD (like this) does not change this.
My MSVC linker's not in quite the same place as yours (it's deeper in that same directory), but it's v14.32.31332.0

@afonso360
Copy link
Contributor

afonso360 commented Sep 28, 2022

It looks like you are using VS2022, which is the latest version. I downloaded and installed VS2022 (14.33.31630.0), rebuilt everything with it, took 15 min to link and ran into the same issue as before 😕 .

On an interesting note, I was able to compile and run the bevy breakout example in 2min, so its no longer hitting that issue there. (Edit: Nevermind, I left the rust-lld.exe in there by accident, without it, it still takes a long time.)

I'm a bit at a loss here... Can you send a backtrace or run it in WinDbg to see where its crashing?

@PROMETHIA-27
Copy link
Author

PROMETHIA-27 commented Sep 28, 2022

I took a look with WinDbg but I still don't know what I'm looking for. It seemed to crash on a function pointer call? It segfaults on call rdx, where rdx has the value 0x00007ff7f687a7dc. Across different builds this is mostly the same, although I think it was rbx once and a slightly different but mostly similar offset. The previous line was mov rdx, qword ptr [7FF7F7FBCC78h] or something very similar both times.

The call stack doesn't seem useful, it's just one frame named [0x0] cranelift_test + 0x3579e41.

Nothing else pops out at me as being useful/relevant. Is cranelift able to build .pdbs? I think that would be useful but it doesn't seem to. Or embed more debug info. Normally windbg can actually point back to source code from assembly, but with cranelift builds it seems to be completely lacking any debug info.

While messing around with the loaded plugins I managed to get it to crash with a panic, which also seemed to raise an ILLEGAL_INSTRUCTION error, after the panic printed.
I narrowed down the source of the segfault to LogPlugin; if it's added before all other plugins (the default behavior with DefaultPlugins) it will segfault. It seems like aside from normal dependency panics, this is the only real issue with the default plugins/reordering them. I was unable to determine what ordering characteristics cause the segfault, because moving other plugins around moves where LogPlugin must be to prevent a crash, but primarily it's safest to add it as late as possible.
I don't have a clue why, because it doesn't seem particularly unsafe or complex. With the tracing feature on it can do some panic hook manipulation, but that's off by default. However, I did notice that it seemed to be particularly likely to crash when added before rendering related plugins like TextPlugin, WinitPlugin, and RenderPlugin. That might just be coincidence though.

Edit: Also tried getting a backtrace with RUST_BACKTRACE=1, didn't work.

Edit 2: The problem is even narrower than I thought! It's crashing at app construction time, not when the app is running. Just adding default plugins and not calling .run() crashes with a segfault. So something that LogPlugin is doing in the build function is the cause.

@bjorn3
Copy link
Member

bjorn3 commented Sep 28, 2022

So something that LogPlugin is doing in the build function is the cause.

Not necessarily. If you have a miscompilation, minor unrelated changes can cause the miscompiled part to flip between crashing and not crashing for example due to a different value in a register somewhere or due to different code layout. Unfortunately miscompilations are pretty hard to debug. Right now I'm debugging a miscompilation that happens on the main branch of Cranelift (not 0.88.1 like cg_clif uses right now. 0.88.0 had a another miscompilation on AArch64, so I had to skip it)

@afonso360
Copy link
Contributor

afonso360 commented Sep 29, 2022

Is cranelift able to build .pdbs? I think that would be useful but it doesn't seem to.

I do have a pdb next to the exe on the target dir, but to be honest I've never checked if they work. I did notice that a regular rust pdb for the bevy_hello_world has 350MiB but the ones produced by cg_clif have 50MiB, so maybe we aren't including a lot of info on it?


I tried a bunch of plugin combinations and different orders on my machine, but none of them seemed to cause that issue.

Yesterday I had the thought "Hey, maybe everything magically works on my machine, lets try a different one", so I added CI today to the bevy_hello_world repo. And... it works, so that's not very helpful.

But then another thing occurred to me, In that CI run I'm using the cg_clif artifacts from CI and last time you tried and it worked it was also a CI artifact. So maybe that figures into it? Could you try running it on your machine with the CI artifacts?

Looking at the commit log between the last version that worked and now, the other thing that jumps out at me was the parallelization effort by @bjorn3. Although I think that would be unlikely since it looks you can reproduce this consistently.
Either way, I tried a bunch of -j values (Which I think is the correct flag to control the jobserver... But I'm not too sure) to see if it would crash, but no luck there.

Another thing that is different is there are some slight differences in the stack probing code that you tried last time (and worked) and the code that actually was included upstream, so maybe there is a bug there? If the artifact thing fails, I'm going to try to revert to a old version of cranelift with the new stack probing code to see if that triggers something.

Thanks for all your effort debugging this! Its been very helpful on narrowing things down!

@bjorn3
Copy link
Member

bjorn3 commented Sep 29, 2022

I do have a pdb next to the exe on the target dir, but to be honest I've never checked if they work. I did notice that a regular rust pdb for the bevy_hello_world has 350MiB but the ones produced by cg_clif have 50MiB, so maybe we aren't including a lot of info on it?

cg_clif only knows how to generate DWARF debuginfo. As such there is no debuginfo on Windows. Not sure why there is a pdb that large generated. If you know of any crate to generate codeview debuginfo please let me know.

Which I think is the correct flag to control the jobserver... But I'm not too sure

It is.

@PROMETHIA-27
Copy link
Author

PROMETHIA-27 commented Sep 29, 2022

It's been a few minutes since I started building with the msvc artifact, so I think you're onto something. Will update when it's finished but I suspect that because of the toolchain override, when I built it built a gnu toolchain cargo-clif, but I use stable-msvc normally. So I can't imagine that was a nice interaction. Next I'll try building with my build on stable-gnu and see if that works.

EDIT: Should've waited one more minute. Just finished, in 11min, and I got the same event loop not-main-thread error that was mentioned. My build did not work, but something interesting I noticed is that either artifact force installs a matching nightly toolchain when run, while my build does not. gnu artifact not only built but ran perfectly.

@afonso360
Copy link
Contributor

Should've waited one more minute. Just finished, in 11min, and I got the same event loop not-main-thread error that was mentioned.

That sounds like exactly what I've been seeing when linking with the default linker, using rust-lld.exe fixes that and makes the issue go away. I think that is a separate issue, although its worth investigating later.

when I built it built a gnu toolchain cargo-clif, but I use stable-msvc normally. So I can't imagine that was a nice interaction. Next I'll try building with my build on stable-gnu and see if that works.

Building x86_64-pc-windows-gnu from x86_64-pc-windows-msvc does have some issues. I've had to disable some tests when I enabled that in CI.

But if I understand this correctly you had a x86_64-pc-windows-gnu cg_clif cross-compiling to a x86_64-pc-windows-msvc target, right? (I also haven't tested that configuration)

My build did not work, but something interesting I noticed is that either artifact force installs a matching nightly toolchain when run, while my build does not. gnu artifact not only built but ran perfectly.

I'm not too sure about why this happens.

@afonso360
Copy link
Contributor

Even with gimli-rs/object#475 we are still failing to compile bevy (with the same behaviour as in https://github.com/bjorn3/rustc_codegen_cranelift/issues/1249#issuecomment-1259733923), however now linking is pretty much instant, which helps with testing this.

I'm going to look into the linker warnings above and the illegal instruction on that comment.

@bjorn3 bjorn3 changed the title Attempting to compile bevy_reflect with cranelift causes STATUS_ACCESS_VIOLATION during compilation Miscompilation of Bevy with MSVC Oct 12, 2022
@Rodrigodd
Copy link

I was looking at this today for fun, and I notice that the panic observed in this thread happens is this check on winit:

if !attributes.any_thread && thread_id != main_thread_id() {
    panic!(
        "Initializing the event loop outside of the main thread is a significant \
         cross-platform compatibility hazard. If you absolutely need to create an \
         EventLoop on a different thread, you can use the \
         `EventLoopBuilderExtWindows::any_thread` function."
    );
}

That check the current thread id against this function:

/// Returns the id of the main thread.
///
/// Windows has no real API to check if the current executing thread is the "main thread", unlike
/// macOS.
///
/// Windows will let us look up the current thread's id, but there's no API that lets us check what
/// the id of the main thread is. We would somehow need to get the main thread's id before a
/// developer could spin off any other threads inside of the main entrypoint in order to emulate the
/// capabilities of other platforms.
///
/// We can get the id of the main thread by using CRT initialization. CRT initialization can be used
/// to setup global state within a program. The OS will call a list of function pointers which
/// assign values to a static variable. To have get a hold of the main thread id, we need to place
/// our function pointer inside of the `.CRT$XCU` section so it is called before the main
/// entrypoint.
///
/// Full details of CRT initialization can be found here:
/// <https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-initialization?view=msvc-160>
fn main_thread_id() -> u32 {
    static mut MAIN_THREAD_ID: u32 = 0;

    /// Function pointer used in CRT initialization section to set the above static field's value.

    // Mark as used so this is not removable.
    #[used]
    #[allow(non_upper_case_globals)]
    // Place the function pointer inside of CRT initialization section so it is loaded before
    // main entrypoint.
    //
    // See: https://doc.rust-lang.org/stable/reference/abi.html#the-link_section-attribute
    #[link_section = ".CRT$XCU"]
    static INIT_MAIN_THREAD_ID: unsafe fn() = {
        unsafe fn initer() {
            MAIN_THREAD_ID = GetCurrentThreadId();
        }
        initer
    };

    unsafe { MAIN_THREAD_ID }
}

Which involves using CRT initialization to get the main thread id. Considering that there is also a linker warning about CRT sections, this appears to be the problem.

In fact, wrapping the main_thread_id() call in a dbg!, and changing the default value of MAIN_THREAD_ID to something like 0xdeadbeef, we can see that MAIN_THREAD_ID is not being initialized.

Removing that panic check from winit, Bevy appears to compile and run correctly, at least all examples that I tried. So apparently there is no miscompilation in Bevy itself.

@bjorn3
Copy link
Member

bjorn3 commented Jan 13, 2023

Thanks for the investigation!

Considering that there is also a linker warning about CRT sections, this appears to be the problem.

That is very much possible. I will need to look into what the expected attributes are.

@afonso360
Copy link
Contributor

afonso360 commented Jan 14, 2023

I built a small example using the winit code above and we really are not emitting those symbols!

test.rs
#[link(name = "kernel32")]
extern "C" {
    fn GetCurrentThreadId() -> u32;
}

/// Returns the id of the main thread.
///
/// Windows has no real API to check if the current executing thread is the "main thread", unlike
/// macOS.
///
/// Windows will let us look up the current thread's id, but there's no API that lets us check what
/// the id of the main thread is. We would somehow need to get the main thread's id before a
/// developer could spin off any other threads inside of the main entrypoint in order to emulate the
/// capabilities of other platforms.
///
/// We can get the id of the main thread by using CRT initialization. CRT initialization can be used
/// to setup global state within a program. The OS will call a list of function pointers which
/// assign values to a static variable. To have get a hold of the main thread id, we need to place
/// our function pointer inside of the `.CRT$XCU` section so it is called before the main
/// entrypoint.
///
/// Full details of CRT initialization can be found here:
/// <https://docs.microsoft.com/en-us/dumpbin /all cpp/c-runtime-library/crt-initialization?view=msvc-160>
fn main_thread_id() -> u32 {
    static mut MAIN_THREAD_ID: u32 = 0;

    /// Function pointer used in CRT initialization section to set the above static field's value.

    // Mark as used so this is not removable.
    #[used]
    #[allow(non_upper_case_globals)]
    // Place the function pointer inside of CRT initialization section so it is loaded before
    // main entrypoint.
    //
    // See: https://doc.rust-lang.org/stable/reference/abi.html#the-link_section-attribute
    #[link_section = ".CRT$XCU"]
    static INIT_MAIN_THREAD_ID: unsafe fn() = {
        unsafe fn initer() {
            MAIN_THREAD_ID = GetCurrentThreadId();
        }
        initer
    };

    unsafe { MAIN_THREAD_ID }
}

fn main() {
    println!("thread id: {}", main_thread_id())
}

When we run it, we always get 0 with cg-clif

PS C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift> .\dist\rustc-clif.exe .\test.rs -o .\test-clif.exe                       
PS C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift> .\test-clif.exe
thread id: 0
PS C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift> rustc.exe .\test.rs -o test-llvm.exe                   
PS C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift> .\test-llvm.exe
thread id: 23920

Listing the symbol table for a rustc produced binary shows the CRT symbols. But a CLIF one does not have them!

PS C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift> rustc.exe .\test.rs --crate-type=staticlib -o test-llvm.lib
...
COFF SYMBOL TABLE
...
00E 00000000 SECT6  notype       Static       | .CRT$XCU
    Section length    8, #relocs    1, #linenums    0, checksum        0
...
201D 00000000 SECT875 notype       Static      | .CRT$XCT
    Section length    8, #relocs    1, #linenums    0, checksum        0
...
21BD 00000000 SECT900 notype       Static      | .CRT$XLB
    Section length    8, #relocs    1, #linenums    0, checksum        0

Doing a dumpbin, it looks like It's just 8bytes and a relocation:

PS C:\Users\Afonso\CLionProjects\rustc_codegen_cranelift> dumpbin /all /section:.CRT`$XCU .\test-llvm.lib 
...
SECTION HEADER #6
.CRT$XCU name
       0 physical address
       0 virtual address
       8 size of raw data
     185 file pointer to raw data (00000185 to 0000018C)
     18D file pointer to relocation table
       0 file pointer to line numbers
       1 number of relocations
       0 number of line numbers
40400040 flags
         Initialized Data
         8 byte align
         Read Only

RAW DATA #6
  00000000: 00 00 00 00 00 00 00 00                          ........

RELOCATIONS #6
                                                Symbol    Symbol
 Offset    Type              Applied To         Index     Name
 --------  ----------------  -----------------  --------  ------
 00000000  ADDR64            00000000 00000000         8  _ZN4test14main_thread_id19INIT_MAIN_THREAD_ID6initer17hb913f4b0668c149aE

The MS article does mention that multiple initializers are supported in the same section, but that should also be straightforward.

@bjorn3 I'm not too sure where the best place within cg_clif is to handle this, but it should be fairly easy to mimic this output! I'd be happy to do it with some guidance

@bjorn3
Copy link
Member

bjorn3 commented Jan 14, 2023

The section contents seem to be identical:

$ llvm-objdump --section='.CRT$XCU' -Dr rust_out_llvm.o rust_out_clif.o

rust_out_llvm.o:        file format coff-x86-64

Disassembly of section .CRT$XCU:

0000000000000000 <_ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID17ha69b266a3cc9fb7aE>:
       0: 00 00                         addb    %al, (%rax)
                0000000000000000:  IMAGE_REL_AMD64_ADDR64       _ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID6initer17hbca9ad6f02bc474eE
       2: 00 00                         addb    %al, (%rax)
       4: 00 00                         addb    %al, (%rax)
       6: 00 00                         addb    %al, (%rax)

rust_out_clif.o:        file format coff-x86-64

Disassembly of section .CRT$XCU:

0000000000000000 <_ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID17ha69b266a3cc9fb7aE>:
       0: 00 00                         addb    %al, (%rax)
                0000000000000000:  IMAGE_REL_AMD64_ADDR64       _ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID6initer17hbca9ad6f02bc474eE
       2: 00 00                         addb    %al, (%rax)
       4: 00 00                         addb    %al, (%rax)
       6: 00 00                         addb    %al, (%rax)

The symbol table is indeed missing .CRT$XCU. Not only that, it is missing all sections:

$ llvm-objdump --syms rust_out_llvm.o rust_out_clif.o

rust_out_llvm.o:        file format coff-x86-64

SYMBOL TABLE:
[ 0](sec  1)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
AUX scnlen 0x0 nreloc 0 nlnno 0 checksum 0x0 assoc 1 comdat 0
[ 2](sec  2)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .data
AUX scnlen 0x0 nreloc 0 nlnno 0 checksum 0x0 assoc 2 comdat 0
[ 4](sec  3)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
AUX scnlen 0x0 nreloc 0 nlnno 0 checksum 0x0 assoc 3 comdat 0
[ 6](sec  4)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .text
AUX scnlen 0x15 nreloc 2 nlnno 0 checksum 0x7eb011af assoc 4 comdat 1
[ 8](sec  4)(fl 0x00)(ty  20)(scl   3) (nx 0) 0x00000000 _ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID6initer17hbca9ad6f02bc474eE
[ 9](sec  7)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .xdata
AUX scnlen 0x8 nreloc 0 nlnno 0 checksum 0xfc539d1 assoc 4 comdat 5
[11](sec  5)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .bss
AUX scnlen 0x4 nreloc 0 nlnno 0 checksum 0x0 assoc 5 comdat 1
[13](sec  5)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 _ZN8rust_out14main_thread_id14MAIN_THREAD_ID17h433dee00498248d4E
[14](sec  6)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .CRT$XCU
AUX scnlen 0x8 nreloc 1 nlnno 0 checksum 0x0 assoc 6 comdat 0
[16](sec  8)(fl 0x00)(ty   0)(scl   3) (nx 1) 0x00000000 .pdata
AUX scnlen 0xc nreloc 3 nlnno 0 checksum 0x345b3f4f assoc 4 comdat 5
[18](sec -1)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 @feat.00
[19](sec  0)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 __imp_GetCurrentThreadId
[20](sec  6)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 _ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID17ha69b266a3cc9fb7aE
[21](sec -2)(fl 0x00)(ty   0)(scl  67) (nx 2) 0x00000000 .file
AUX rust_out.69a221d5-cgu.0

rust_out_clif.o:        file format coff-x86-64

SYMBOL TABLE:
[ 0](sec -2)(fl 0x00)(ty   0)(scl  67) (nx 2) 0x00000000 .file
AUX rust_out.69a221d5-cgu.0.o
[ 3](sec  3)(fl 0x00)(ty  20)(scl   3) (nx 0) 0x00000000 _ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID6initer17hbca9ad6f02bc474eE
[ 4](sec  1)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _ZN8rust_out14main_thread_id14MAIN_THREAD_ID17h433dee00498248d4E
[ 5](sec  2)(fl 0x00)(ty   0)(scl   2) (nx 0) 0x00000000 _ZN8rust_out14main_thread_id19INIT_MAIN_THREAD_ID17ha69b266a3cc9fb7aE
[ 6](sec  0)(fl 0x00)(ty  20)(scl   2) (nx 0) 0x00000000 GetCurrentThreadId
[ 7](sec  4)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .refptr.GetCurrentThreadId
[ 8](sec  5)(fl 0x00)(ty   0)(scl   3) (nx 0) 0x00000000 .refptr._ZN8rust_out14main_thread_id14MAIN_THREAD_ID17h433dee00498248d4E

I think a change to object will be necessary to add sections to the symbol table. Another divergence is:

$ llvm-readobj --section-headers rust_out_llvm.o rust_out_clif.o                      

File: rust_out_llvm.o
[...]
  Section {
    Number: 6
    Name: .CRT$XCU (2E 43 52 54 24 58 43 55)
    VirtualSize: 0x0
    VirtualAddress: 0x0
    RawDataSize: 8
    PointerToRawData: 0x185
    PointerToRelocations: 0x18D
    PointerToLineNumbers: 0x0
    RelocationCount: 1
    LineNumberCount: 0
    Characteristics [ (0x40400040)
      IMAGE_SCN_ALIGN_8BYTES (0x400000)
      IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
      IMAGE_SCN_MEM_READ (0x40000000)
    ]
  }
[...]

File: rust_out_clif.o
[...]
  Section {
    Number: 2
    Name: .CRT$XCU (2E 43 52 54 24 58 43 55)
    VirtualSize: 0x0
    VirtualAddress: 0x0
    RawDataSize: 8
    PointerToRawData: 0xE0
    PointerToRelocations: 0xE8
    PointerToLineNumbers: 0x0
    RelocationCount: 1
    LineNumberCount: 0
    Characteristics [ (0xC0400040)
      IMAGE_SCN_ALIGN_8BYTES (0x400000)
      IMAGE_SCN_CNT_INITIALIZED_DATA (0x40)
      IMAGE_SCN_MEM_READ (0x40000000)
      IMAGE_SCN_MEM_WRITE (0x80000000)
    ]
  }

With cg_clif .CRT$XCU is writable, but with LLVM it is not. This divergence seems to be the reason for the linker error.

@bjorn3
Copy link
Member

bjorn3 commented Jan 14, 2023

Both changes will need to be made in object I think.

@bjorn3
Copy link
Member

bjorn3 commented Feb 26, 2023

Does Bevy work on Windows with https://github.com/bjorn3/rustc_codegen_cranelift/actions/runs/4276291179? This updates Cranelift to the latest commit on the main branch which includes bytecodealliance/wasmtime#5619. This version will be released in ~3 weeks, at which point I will update the master branch of cg_clif to use it.

@Rodrigodd
Copy link

@bjorn3 Can confirm that winit and Bevy are working.

@bjorn3
Copy link
Member

bjorn3 commented Feb 26, 2023

Thanks for testing!

@PROMETHIA-27
Copy link
Author

I can also confirm it works! Got the first-person example in bevy_mod_wanderlust working. Seems to run into vulkan validation errors but that doesn't seem to be significant or consistent.

@PROMETHIA-27
Copy link
Author

Further good news! JIT mode works on windows!

  • Hello world runs on JIT/Lazy JIT
  • A bevy project with no-default-features runs in JIT/Lazy JIT
  • A bevy project w/ no-default-features + winit does not run, because winit demands the main thread and I suppose cranelift runs the application on a non-main thread?
  • I've been unable to successfully compile bevy w/ default features behind a dynamic wrapper. It produces 219993 symbols and the linker dies. Adding seemingly almost any default features back is just too much; assets alone works fine, but assets + audio is 67k+ symbols. If someone knows a workaround, that would be neat, but we can't test w/ winit anyway right now.

Also! This required some setup to convert bevy to dynamic. I don't think bevy's built-in dynamic feature would work, since I think that would statically link a crate in which dynamically links the rest. To do this, I created a crate in the same workspace called bevy_wrapper. It has [lib]\ncrate_type = ["dylib"] in the cargo.toml. The wrapper is simply pub use bevy;. This would work for all dependencies I believe, as long as you keep it <65k symbols.

There's one issue though; when the JIT compiler tries to resolve dependencies dynamically, it uses LoadLibraryExW on windows via libloading. It can load the stdlib just fine; that always works. But crates (always?) depend on the stdlib when compiled into their .dlls, When it tries to resolve their stdlib dependency, it can't (usually) find it. To fix this I was able to just copy the stdlib.dll into the target/debug/deps folder, which lets it find it. Some alternatives:

  • Use the AddDllDirectory function w/ LOAD_LIBRARY_SEARCH_USER_DIRS when on windows to add the stdlib directory as a search target
  • Copy the stdlib to the deps folder when building somehow
  • I think adding the stdlib path to PATH might work too.

I think copying the stdlib to deps automatically would probably be the most doable; has the least amount of non-portable code/assumptions involved.

@bjorn3
Copy link
Member

bjorn3 commented Feb 28, 2023

A bevy project w/ no-default-features + winit does not run, because winit demands the main thread and I suppose cranelift runs the application on a non-main thread?

Indeed. Rustc spawns a new thread to run on. For regular jit mode this thread is where the program runs. For lazy jit mode another thread is spawned to run the program and the main rustc thread is used for compiling new functions on the fly.

I believe winit has a function to allow the event loop on a different thread on platforms that support it (which at least Linux does). You can try modifying bevy_winit to use it.

I've been unable to successfully compile bevy w/ default features behind a dynamic wrapper. It produces 219993 symbols and the linker dies. Adding seemingly almost any default features back is just too much; assets alone works fine, but assets + audio is 67k+ symbols. If someone knows a workaround, that would be neat, but we can't test w/ winit anyway right now.

Right, I believe there is a variant of COFF with a higher limitation, but the object crate doesn't know how to write it afaik.

There's one issue though; when the JIT compiler tries to resolve dependencies dynamically, it uses LoadLibraryExW on windows via libloading. It can load the stdlib just fine; that always works. But crates (always?) depend on the stdlib when compiled into their .dlls, When it tries to resolve their stdlib dependency, it can't (usually) find it. To fix this I was able to just copy the stdlib.dll into the target/debug/deps folder, which lets it find it. Some alternatives:

You figured it out. I expected that cargo would take care of adding libstd to the dynamic linker search path, but maybe it only does when running an executable and not when running rustc as is done in jit mode?

Use the AddDllDirectory function w/ LOAD_LIBRARY_SEARCH_USER_DIRS when on windows to add the stdlib directory as a search target

I can try this.

I think copying the stdlib to deps automatically would probably be the most doable; has the least amount of non-portable code/assumptions involved.

I don't like messing with the target dir behind the back of cargo.

@PROMETHIA-27
Copy link
Author

Guaranteeing that stdlib is loaded first would also fix it, I missed that possibility. That would be best I think. I was able to accomplish it for my setup by simply .rev()'ing the dependencies, but I'm not sure if stdlib always shows up last, or what happens in more complex setups.

bjorn3 added a commit that referenced this issue Feb 28, 2023
@bjorn3
Copy link
Member

bjorn3 commented Feb 28, 2023

I was able to accomplish it for my setup by simply .rev()'ing the dependencies, but I'm not sure if stdlib always shows up last, or what happens in more complex setups.

Thanks for the idea! That is actually correct. used_crates is in reverse postorder and reversing this turns it into postorder, which will cause deps to be loaded before the dependent dylib. Implemented in bjorn3@162365e and force pushed a rebase of the update_cranelift branch.

@PROMETHIA-27
Copy link
Author

Cool! Wrt this:

Indeed. Rustc spawns a new thread to run on. For regular jit mode this thread is where the program runs. For lazy jit mode another thread is spawned to run the program and the main rustc thread is used for compiling new functions on the fly.

Could this be reversed, and have rustc be split off into the new thread, and have the program run on main? I feel like this would probably be a more optimal answer than using a dubious feature + patching to get winit to not complain.

@PROMETHIA-27
Copy link
Author

I tested it myself- works perfectly. Would this be a good candidate to PR?

@bjorn3
Copy link
Member

bjorn3 commented Feb 28, 2023

Yes, but it did require re-introducing a custom rustc driver which broke sccache and -Zbuild-std support and was it bit hard to handle in the build system. As such I removed it in https://github.com/bjorn3/rustc_codegen_cranelift/pull/1225.

@PROMETHIA-27
Copy link
Author

Isn't it already using a custom driver? driver/jit.rs?

@bjorn3
Copy link
Member

bjorn3 commented Feb 28, 2023

That is a different kind of driver. The driver/ directory is for driving just the codegen backend as part of the codegen_crate call by rustc_driver. For running user code on the main thread, I did need to create an executable which invokes rustc_driver itself. Currently cg_clif is loaded using dlopen (or windows equivalent) by rustc_driver after the main thread is already blocking on the rustc thread finishing.

@PROMETHIA-27
Copy link
Author

Ah, I see the issue. Greedy JIT mode works fine by just swapping the loop/call from the thread spawn but lazy jit dies because some TLS stuff is no longer available.

@bjorn3
Copy link
Member

bjorn3 commented Feb 28, 2023

Huh, I wouldn't expect lazy jit to break tls accesses any more than jit mode in general. That is I did expect tls accesses made by any jitted code to result in an error (or was it a panic?) for both modes but tls accesses made by code in the dylibs to work just fine in both modes. Lazy jit mode is even more experimental than regular jit mode, but if you have a somewhat minimal reproducing example I can take a look.

@Hellzbellz123
Copy link

Hellzbellz123 commented Mar 5, 2023

im tried compiling my bevy project with bjorn3/rustc_codegen_cranelift/actions/runs/4276291179 but it crashes with a weird error. i am unsure of the meaning and if its possible/how to fix it, curious if anyone else has seen this before

i also compiled from source and tried using that and it resulted in the same error so im assuming this is something related to my project or one of my dependencies

Details

   Compiling itertools v0.10.5
   Compiling spin_sleep v1.1.1
   Compiling reorder v2.1.3
   Compiling rand v0.8.5
   Compiling smallvec v1.10.0
   Compiling glam v0.22.0
error: VerifierErrors([VerifierError { location: inst5, context: Some("v5 = extractlane.i128 v3, 0"), message: "has an invalid controlling type i128" }, VerifierError { location: inst6, context: Some("v6 = extractlane.i128 v4, 0"), message: "has an invalid controlling type i128" }, VerifierError { location: inst8, context: Some("v9 = insertlane.i128 v8, v7, 0"), message: "has an invalid controlling type i128" }])

error: cranelift verify error:
       function u0:83(i64 sret, i64, i64) system_v {
                                       block0(v0: i64, v1: i64, v2: i64):
                                           v12 = iconst.i64 0
                                           v13 = uextend.i128 v12  ; v12 = 0
                                           v8 -> v13
                                           v11 -> v13
                                           nop 
                                           jump block1
       
                                       block1:
                                           nop 
       @0001                               v3 = load.i128 notrap v1
       @0002                               v4 = load.i128 notrap v2
                                           v5 = extractlane v3, 0
       ;                                   ^~~~~~~~~~~~~~~~~~~~~~
       ; error: inst5 (v5 = extractlane.i128 v3, 0): has an invalid controlling type i128
       
                                           v6 = extractlane v4, 0
       ;                                   ^~~~~~~~~~~~~~~~~~~~~~
       ; error: inst6 (v6 = extractlane.i128 v4, 0): has an invalid controlling type i128
       
                                           v7 = bor v5, v6
                                           v9 = insertlane.i128 v8, v7, 0
                                           v10 -> v9
       ;                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       ; error: inst8 (v9 = insertlane.i128 v8, v7, 0): has an invalid controlling type i128
       
                                           jump block2
       
                                       block2:
                                           nop 
       @0004                               store.i128 notrap v10, v0
       @0006                               return
       }
       
       ; 3 verifier errors detected (see above). Compilation aborted.

fn packed_simd_2::v128::<impl std::ops::BitOr for packed_simd_2::Simd<[packed_simd_2::m128; 1]>>::bitor(_1: packed_simd_2::Simd<[packed_simd_2::m128; 1]>, _2: packed_simd_2::Simd<[packed_simd_2::m128; 1]>) -> packed_simd_2::Simd<[packed_simd_2::m128; 1]> {
    debug self => _1;                    // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:35:22: 35:26
    debug other => _2;                   // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:35:28: 35:33
    let mut _0: packed_simd_2::Simd<[packed_simd_2::m128; 1]>; // return place in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:35:44: 35:48
    let mut _3: packed_simd_2::codegen::v128::m128x1; // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:55
    let mut _4: packed_simd_2::codegen::v128::m128x1; // in scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:39: 37:45
    let mut _5: packed_simd_2::codegen::v128::m128x1; // in scope 0 at /home/hellzbellz/.cargo/regist
ry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:47: 37:54
    scope 1 {
    }

    bb0: {
        StorageLive(_3);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:55
        StorageLive(_4);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:39: 37:45
        _4 = (_1.0: packed_simd_2::codegen::v128::m128x1); // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:39: 37:45
        StorageLive(_5);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:47: 37:54
        _5 = (_2.0: packed_simd_2::codegen::v128::m128x1); // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:47: 37:54
        _3 = packed_simd_2::codegen::llvm::simd_or::<packed_simd_2::codegen::v128::m128x1>(move _4, move _5) -> bb1; // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:55
                                         // mir::Constant
                                         // + span: /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:31: 37:38
                                         // + literal: Const { ty: unsafe extern "platform-intrinsic" fn(packed_simd_2::codegen::v128::m128x1, packed_simd_2::codegen::v128::m128x1) -> packed_simd_2::codegen::v128::m128x1 {packed_simd_2::codegen::llvm::simd_or::<packed_simd_2::codegen::v128::m128x1>}, val: Value(<ZST>) }
    }

    bb1: {
        StorageDead(_5);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:54: 37:55
        StorageDead(_4);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:54: 37:55
        _0 = packed_simd_2::Simd::<[packed_simd_2::m128; 1]>(move _3); // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:26: 37:56
        StorageDead(_3);                 // scope 1 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:37:55: 37:56
        return;                          // scope 0 at /home/hellzbellz/.cargo/registry/src/index.crates.io-6f17d22bba15001f/packed_simd_2-0.3.8/src/api/ops/vector_mask_bitwise.rs:38:14: 38:14
    }
}

error: could not compile `simba` due to 2 previous errors
warning: build failed, waiting for other jobs to finish...

@bjorn3
Copy link
Member

bjorn3 commented Mar 5, 2023

Could you open a separate issue for that? This is unrelated to the MSVC trouble OP has. I will dig into what exactly causes this issue as soon as I have time. I'm busy for the next few days unfortunately.

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. O-windows Operating system: Windows
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants