rust-lang / rust-lang/rust

#[used(linker)] does not prevent section removal on x86_64-pc-windows-gnu

Open
#145,362 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkers C-bug F-used_with_arg O-windows-gnu O-x86_64 T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(used_with_arg)]

#[used(linker)]
#[link_section = ".things"]
static HEJ: u32 = 123;

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

I expected to see this happen:
That the .things section is kept in the binary by the linker. This feels like a reasonable expectation since this is the behavior on x86_64-unknown-linux-gnu

Instead, this happened:
The HEJ variable is kept in the binary but not the .things section.

The command

readpe -S target/x86_64-pc-windows-gnu/debug/rs-mingw32-test.exe | grep things

gives no output.

Meta

rustc --version --verbose:

rustc 1.91.0-nightly (8e62bfd31 2025-08-12)
binary: rustc
commit-hash: 8e62bfd311791bfd9dca886abdfbab07ec54d8b4
commit-date: 2025-08-12
host: x86_64-unknown-linux-gnu
release: 1.91.0-nightly
LLVM version: 21.1.0

x86_64-w64-mingw32-gcc --version:

x86_64-w64-mingw32-gcc (GCC) 15.1.0
Copyright (C) 2025 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Backtrace

<backtrace>

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

Start by reproducing the minimal Rust example on x86_64-pc-windows-gnu and inspecting the output with the reported readpe command. Compare the result with x86_64-unknown-linux-gnu; the work is done when the .things section is retained on Windows as expected.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.