Open Elabajaba opened 1 year ago
After checking out the same commit and ensuring I was running thin LTO with lld-link (CARGO_TARGET_X86_64_PX_WINDOWS_MSVC_LINKER="lld-link" cargo +nightly-x86_64-pc-windows-msvc run --bin cube --config 'lto="thin"'
) I can't seem to reproduce this on latest nightly -- was this already fixed perhaps?
I've run all of the examples with the exception of the imgui
one (it panics on imgui-winit-support
not being upgraded and this is taking enough time already). Are there any other environment-specific things that could've caused this?
I'm still able to reproduce it both on the earlier commit listed in my original post and on the latest rend3 commit (d7806f584468c4ed974a2ff5e1eea547d26478db) on rustc stable 1.74.0 (79e9716c9 2023-11-13), stable 1.74.1, and 1.76.0-nightly (3340d49d2 2023-12-12) by running the cube example with lto="thin"
set in Cargo.toml
(both for debug builds and release builds).
Based on how long it takes to build the final cube.exe
, cargo run --bin cube --config 'lto="thin"'
doesn't appear to be working on stable or nightly for me. --timings
shows 0.87s to build the cube binary with --config 'lto="thin"'
, vs 15.75s if I add it to the Cargo.toml
[profile.dev]
lto = "thin"
That seemed long so I checked by setting lto = "fat"
in Cargo.toml
and it took 52.24s and the binary worked.
I removed everything in my global ~\.cargo\config.toml
except
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
I also tested linker = "lld-link.exe"
using the version of LLD included with the scoop installer llvm package (LLD 17.0.6), and it has the same issue.
Would you happen to have an MinGW env lying around? I used the lld-link.exe
from there for my testing. I'll rerun things tomorrow with rust-lld
to see if I can reproduce. If not, I wonder if there's some optimization step going wrong considering the system I ran this with is rather outdated
This still reproduces. Steps I took...
Firstly download the repo in the OP and switch to the indicated commit:
git clone https://github.com/BVE-Reborn/rend3.git
cd rend3
git switch --detach 4d107951a3ba62a58a7be1849eb670d05f269e20
Then I edited .cargo/config.toml
to add the following (x86_64-pc-windows-msvc
is both the host and target):
[target.x86_64-pc-windows-msvc]
linker = "rust-lld"
Finally run an example to see the crash:
cd examples/animation
cargo run --release
This fails with STATUS_ACCESS_VIOLATION
.
I then edited the Cargo.toml
in the root of the repo so to turn off optimizations but still keep lto=thin
. This allowed me to capture a more detailed backtrace.
This points to using atomic_compare_exchange
from once_cell
but I think things start going wrong earlier in winit. Specifically: https://github.com/rust-windowing/winit/blob/2ebbfab6a47f93f76841553dcb3cc53683e4955c/src/platform_impl/windows/event_loop.rs#L700
lpszClassName: THREAD_EVENT_TARGET_WINDOW_CLASS.as_ptr(),
THREAD_EVENT_TARGET_WINDOW_CLASS
is defined as:
static THREAD_EVENT_TARGET_WINDOW_CLASS: Lazy<Vec<u16>> =
Lazy::new(|| util::encode_wide("Winit Thread Event Target"));
So my assumption is the static isn't getting linked correctly for some reason.
Maybe.... @lqd do you have any ideas?
Ok I've minimized it a bit more and realised that the crate-type
in Cargo.toml seems to play a role. I need both "lib" and "cdylib" for this problem to occur.
[lib]
crate-type = ["lib", "cdylib"]
My minimization so far:
# Cargo.toml
[package]
name = "winit_test"
version = "0.1.0"
edition = "2021"
[[bin]]
name = "animation"
path = "src/main.rs"
[lib]
crate-type = ["lib", "cdylib"]
[profile.dev]
lto = "thin"
[dependencies]
winit = "0.28"
# .cargo/config.toml
[target.x86_64-pc-windows-msvc]
linker = "rust-lld
// src/main.rs
fn main() {
winit_test::main();
}
// src/lib.rs
use winit::event_loop::{EventLoop, EventLoopBuilder};
pub fn main() {
let _event_loop: EventLoop<u8> = EventLoopBuilder::with_user_event().build();
}
Doing cargo run
results in:
error: process didn't exit successfully: `target\debug\animation.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
I need both "lib" and "cdylib" for this problem to occur.
I also believe this is the key factor, we have other similar issues (involving LTO and PGO, creating invalid LLVM modules; I’ll find them when I’m back at a computer) triggered by this cargo setting/behavior.
(I do wonder if this issue reproduces with zoxc’s recent PRs though (a revert and an _imp fix that lld needs but not link.exe))
Thanks! It seems like https://github.com/rust-lang/rust/pull/129079/commits/713a006d4b8983bd8b246255542cacc073bc8590 fixes it on my local machine.
I'm getting a crash when running the rend3 examples
in --release modewith lto=thin and using LLD. (edit: Happens in both dev builds and release builds when using thinLTO)Rend3 repo: https://github.com/BVE-Reborn/rend3 Tested commit: 4d107951a3ba62a58a7be1849eb670d05f269e20
I expected to see this happen: It doesn't crash instantly when attempting to run it.
Instead, this happened: It crashes instantly when attempting to run the examples.
Meta
rustc --version --verbose
:tested nightly:
There's no backtrace, but running it in windbg it just loops these errors: