Skip to content

Incorrect behavior on Windows with dylibs and ThinLTO #127979

Open
@janhohenheim

Description

@janhohenheim
Contributor

edit by @Noratrieb: MCVE: https://github.com/bash/rust-dylib-crash

I tried this code:
Clone https://github.com/TheBevyFlock/bevy_quickstart and run cargo run --release on Windows

I expected to see this happen: Literally anything else than the standard library hitting unreachable code.

Instead, this happened: We hit this line of unreachable code: https://github.com/rust-lang/rust/blob/22a5267c83a3e17f2b763279eb24bb632c45dc6b/library/std/src/sys/sync/once/futex.rs

Meta

rustc --version --verbose:

rustc 1.81.0-nightly (5affbb171 2024-07-18)
binary: rustc
commit-hash: 5affbb17153bc69a9d5d8d2faa4e399a014a211e
commit-date: 2024-07-18
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7

image

Backtrace

thread 'main' panicked at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e\library\std\src\sync\once.rs:217:20:
internal error: entered unreachable code: state is never set to invalid values
stack backtrace:
   0:     0x7ffae5f03e3d - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffae5f03e3d - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffae5f03e3d - std::sys::backtrace::_print_fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\sys\backtrace.rs:65
   3:     0x7ffae5f03e3d - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\sys\backtrace.rs:40
   4:     0x7ffae5f34639 - core::fmt::rt::Argument::fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\core\src\fmt\rt.rs:173
   5:     0x7ffae5f34639 - core::fmt::write
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\core\src\fmt\mod.rs:1182
   6:     0x7ffae5efa941 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\io\mod.rs:1827
   7:     0x7ffae5f06ed7 - std::panicking::default_hook::closure$1
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:269
   8:     0x7ffae5f06ac9 - std::panicking::default_hook
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:296
   9:     0x7ffae5f076e2 - std::panicking::rust_panic_with_hook
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:800
  10:     0x7ffae5f074ef - std::panicking::begin_panic_handler::closure$0
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:667
  11:     0x7ffae5f047af - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\sys\backtrace.rs:168
  12:     0x7ffae5f07106 - std::panicking::begin_panic_handler
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:665
  13:     0x7ffae5f5d6b4 - core::panicking::panic_fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\core\src\panicking.rs:74
  14:     0x7ff7dfc60e01 - main
  15:     0x7ff7dfc5e391 - main
  16:     0x7ff7dfc5cc95 - main
  17:     0x7ffade9fe3e2 - bevy_app::app::App::add_boxed_plugin::he4742dca059e0ec1
  18:     0x7ff7dfc42aff - main
  19:     0x7ff7dfc4104f - main
  20:     0x7ff7dfc4103e - main
  21:     0x7ffae5eeb969 - std::rt::lang_start_internal::closure$2
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\rt.rs:141
  22:     0x7ffae5eeb969 - std::panicking::try::do_call
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:557
  23:     0x7ffae5eeb969 - std::panicking::try
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:521
  24:     0x7ffae5eeb969 - std::panic::catch_unwind
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panic.rs:350
  25:     0x7ffae5eeb969 - std::rt::lang_start_internal
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\rt.rs:141
  26:     0x7ff7dfc42cec - main
  27:     0x7ff7dfcd5ba0 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  28:     0x7ff7dfcd5ba0 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  29:     0x7ffc426a257d - BaseThreadInitThunk
  30:     0x7ffc4366af28 - RtlUserThreadStart
error: process didn't exit successfully: `target\release\bevy_quickstart.exe` (exit code: 101)

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 19, 2024
workingjubilee

workingjubilee commented on Jul 19, 2024

@workingjubilee
Member

@janhohenheim Can you bisect this to a specific commit?

https://github.com/rust-lang/cargo-bisect-rustc

added
O-windowsOperating system: Windows
T-libsRelevant to the library team, which will review and decide on the PR/issue.
on Jul 19, 2024
workingjubilee

workingjubilee commented on Jul 19, 2024

@workingjubilee
Member

Also, can you specify your Windows version? Just in case.

janhohenheim

janhohenheim commented on Jul 19, 2024

@janhohenheim
ContributorAuthor

@workingjubilee sure, will do later. First, I'm trying to narrow the example a bit down.

tgross35

tgross35 commented on Jul 19, 2024

@tgross35
Contributor

For future reference, permalink at that version https://github.com/rust-lang/rust/blob/22a5267c83a3e17f2b763279eb24bb632c45dc6b/library/std/src/sys/sync/once/futex.rs

You should try the nightly too, @ChrisDenton recently did some changes there that may have happened to fix things

janhohenheim

janhohenheim commented on Jul 19, 2024

@janhohenheim
ContributorAuthor

@tgross35 thanks for the hint, updated the description :)
Nightly is hitting the same thing

janhohenheim

janhohenheim commented on Jul 19, 2024

@janhohenheim
ContributorAuthor

Alright, added my Windows system information and linked to a smaller example. Will run cargo-bisect now.

tgross35

tgross35 commented on Jul 19, 2024

@tgross35
janhohenheim

janhohenheim commented on Jul 19, 2024

@janhohenheim
ContributorAuthor

@tgross35 oh sorry, I have "simplified" the example too much. That's my bad. Can you try with https://github.com/TheBevyFlock/bevy_quickstart ? Just running cargo run --release should produce the described result.

tgross35

tgross35 commented on Jul 19, 2024

@tgross35
Contributor

Ah, yeah reproduced with the quickstart

tgross35

tgross35 commented on Jul 19, 2024

@tgross35
Contributor

Are you running a bisect, or still trying to minimize? Unfortunate that this takes almost 3 minutes to compile

48 remaining items

added
regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jul 20, 2024
added
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jul 20, 2024
removed
T-libsRelevant to the library team, which will review and decide on the PR/issue.
on Jul 20, 2024
apiraino

apiraino commented on Jul 22, 2024

@apiraino
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-high

added
P-highHigh priority
and removed
I-prioritizeIssue: Indicates that prioritization has been requested for this issue.
on Jul 22, 2024
Zoxc

Zoxc commented on Aug 12, 2024

@Zoxc
Contributor

#122790 fixes @bash's minimized example by reverting #103353.

Zoxc

Zoxc commented on Aug 15, 2024

@Zoxc
Contributor

I see that Cargo was incorrectly passing -C linker-plugin-lto when using ThinLTO. That doesn't work with dylibs and we apparently don't correctly check that no dylibs are involved. With that addressed and #122790 and #129079 applied the bevy-template repo works with both rust-lld and link.

Noratrieb

Noratrieb commented on May 25, 2025

@Noratrieb
Member

@janhohenheim can you confirm that the issue is now fixed?

changed the title [-] unreachable!("state is never set to invalid values") is reached[/-] [+]Incorrect behavior on Windows with dylibs and ThinLTO[/+] on May 25, 2025
janhohenheim

janhohenheim commented on May 26, 2025

@janhohenheim
ContributorAuthor

@Noratrieb I can try over the next few days, but from a quick glance at the discussion, it certainly looks fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-windowsOperating system: WindowsP-highHigh priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Zoxc@rparrett@ChrisDenton@bash@apiraino

        Issue actions

          Incorrect behavior on Windows with dylibs and ThinLTO · Issue #127979 · rust-lang/rust