Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
saethlin opened this issue Dec 30, 2024 · 1 comment
Labels
A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. F-thread_local `#![feature(thread_local)]` O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@saethlin
Copy link
Member

saethlin commented Dec 30, 2024

#![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 #134777

@saethlin saethlin added A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. F-thread_local `#![feature(thread_local)]` O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 30, 2024
@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 30, 2024
@bjorn3
Copy link
Member

bjorn3 commented Dec 31, 2024

Without #[no_mangle] this produces:

@_ZN7example3FOO17h7f7f943ccbcbfc68E = thread_local constant <{ [4 x i8] }> <{ [4 x i8] c"\03\00\00\00" }>, align 4
@"\01__imp__ZN7example3FOO17h7f7f943ccbcbfc68E" = global ptr @_ZN7example3FOO17h7f7f943ccbcbfc68E

; example::FOO{{tls.shim}}
; Function Attrs: nounwind uwtable
define align 4 ptr @"_ZN7example31FOO$u7b$$u7b$tls.shim$u7d$$u7d$17he869035d025446a1E"() unnamed_addr #0 !dbg !6 {
start:
  ret ptr @_ZN7example3FOO17h7f7f943ccbcbfc68E, !dbg !11
}

My guess would be that #[no_mangle] disables mangling not just for _ZN7example3FOO17h7f7f943ccbcbfc68E, but also for \01__imp__ZN7example3FOO17h7f7f943ccbcbfc68E and/or _ZN7example31FOO$u7b$$u7b$tls.shim$u7d$$u7d$17he869035d025446a1E.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-thread-locals Area: Thread local storage (TLS) C-bug Category: This is a bug. F-thread_local `#![feature(thread_local)]` O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants