rust-lang / rust-lang/rust

`#![windows_subsystem = "windows"]` overwrites entrypoint symbol name

Open
#147,746 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-attributes C-bug O-windows T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Description

Using #![windows_subsystem = "windows"] overwrites the default entrypoint symbol name WinMainCRTStartup with mainCRTStartup. This is by design, but can be unexpected in certain scenarios, for example when specifying #![no_main]. It should either be adapted for those scenarios, or mentioned in the user facing documentation.

Reproduction

  1. Create example.rs:
    #![no_main]
    #![no_std]
    
    #[cfg(not(test))]
    #[panic_handler]
    fn panic(_: &core::panic::PanicInfo) -> ! {
        loop {}
    }
    
    #[unsafe(no_mangle)]
    extern "system" fn WinMainCRTStartup() -> i32 {
        0
    }
    
  2. Linking succeeds via: rustc example.rs -C panic=abort -C link-arg=/Subsystem:Windows
  3. Add #![windows_subsystem = "windows"] to example.rs
  4. Linking fails via: rustc example.rs -C panic=abort

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two rustc commands with the provided example.rs, then inspect the linked logic in compiler/rustc_codegen_ssa/src/back/linker.rs and the Windows subsystem attribute documentation in the Rust Reference. Determine whether the behavior should change for no_main or be documented, and consider the issue done when the selected resolution is verified by the reproduction or clearly explained to users.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.