rust-lang / rust-lang/rust

MSVC: cannot link multiple staticlibs from the same workspace because of IMAGE_COMDAT_SELECT_NODUPLICATES

Open
#143,931 8 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I tried: linking the GStreamer Rust plugins gstaws and gstrswebrtc, both built statically.

I expected to see this happen: linking success

Instead, this happened: some 5k lines of function clashes from shared dependencies e.g.:

libgstrswebrtc.a(gstrswebrtc.h2-9527afd107b48849.h2.4898c1e7831a741c-cgu.0.rcgu.o.rcgu.o) : error LNK2005: ya se definió _ZN102_$LT$core..iter..adapters..map..Map$LT$I$C$F$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4fold17h30be9aebf26ab811E en libgstaws.a(gstaws.h2-9527afd107b48849.h2.4898c1e7831a741c-cgu.0.rcgu.o.rcgu.o)
libgstrswebrtc.a(gstrswebrtc.h2-9527afd107b48849.h2.4898c1e7831a741c-cgu.0.rcgu.o.rcgu.o) : error LNK2005: ya se definió _ZN111_$LT$core..iter..adapters..zip..Zip$LT$A$C$B$GT$$u20$as$u20$core..iter..adapters..zip..ZipImpl$LT$A$C$B$GT$$GT$3new17h21a4a1e578e1b030E en libgstaws.a(gstaws.h2-9527afd107b48849.h2.4898c1e7831a741c-cgu.0.rcgu.o.rcgu.o)

I believe this is caused by LLVM assuming IMAGE_COMDAT_SELECT_NODUPLICATES for all function COMDATS, which is too restrictive for MSVC: https://github.com/llvm/llvm-project/blob/llvmorg-20.1.5/llvm/lib/Transforms/Utils/Instrumentation.cpp#L102-L107.

This should perhaps be changed to IMAGE_COMDAT_SELECT_EXACT_MATCH on the Rust side; I tried it locally, but I got an impossibly long panic stacktrace which I attach below.

Meta

rustc --version --verbose:

rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-msvc
release: 1.87.0
LLVM version: 20.1.1

Backtrace: rustc-ice-2025-07-14T01_44_18-10920.txt

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 failure on x86_64-pc-windows-msvc by linking the statically built GStreamer Rust plugins gstaws and gstrswebrtc. Read LLVM's Instrumentation.cpp at the linked COMDAT-selection code, compare the attempted Rust-side change with the attached rustc ICE backtrace, and verify that linking succeeds without duplicate-symbol errors or a compiler panic.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.