rust-lang / rust-lang/rust

#[thread_local] + #[no_mangle] produces a "symbol already defined" error on Windows targets

Open
#134,939 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

#![feature(thread_local)]

#[no_mangle]
#[thread_local]
pub static FOO: u32 = 3;

Does not compile on x86_64-pc-windows-msvc and x86_64-pc-windows-gnu, due to:

error: symbol `FOO` is already defined
 --> lib.rs:5:1
  |
5 | pub static FOO: u32 = 3;
  | ^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Found this while working on https://github.com/rust-lang/rust/pull/134777

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 with the lib.rs reproducer and compile it for x86_64-pc-windows-msvc and x86_64-pc-windows-gnu. Investigate how the compiler handles the combined #[thread_local] and #[no_mangle] attributes on those targets. The work is done when the example no longer produces the duplicate-symbol error.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.