Skip to content

Rust + MSVC + LLD = Segfault on attempt to access TLS #76398

Closed
@petrochenkov

Description

@petrochenkov

How to reproduce:

"<build>\x86_64-pc-windows-msvc\stage1\bin\rustc.exe" -Clinker=lld hello.rs

where hello.rs is

// The important thing here is accessing thread-local `static LOCAL_STDERR` in libstd.
fn main() {
    eprint!("Hello");
}
  • rustc must be built locally, the issue doesn't reproduce on nightly rustc, I don't know due to which differences.
  • lld can be either rust-lld shipped with rustc, or lld from a msys2 package, the issue reproduces on both, and it doesn't happen without lld.
  • the produced executable must be run using a path, not just an executable name, an absolute path like "C:\msys64\home\me\hello.exe" works for sure. UPD: The program invocation string should just be long enough, not necessarily a path.
  • libstd must be build with opt-level = 3 (the default), lowering the opt level to improve debugging removes the issue :( but full debuginfo can still be enabled.
  • The exception and backtrace look like this - rustbuild: Remove one LLD workaround #76127 (comment)

I'll try to step through disassembly and look what happens in more detail tomorrow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-thread-localsArea: Thread local storage (TLS)C-bugCategory: This is a bug.O-windows-msvcToolchain: MSVC, Operating system: Windows

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions