`__nvqpp_vectorCopyCtor` gets external linkage, breaking links with >1 device translation unit
Maintainers usually reply within 1 day
Nobody has claimed this yet.
- #5200 by @cabreraam — closed without merging
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 52/100
Research direction
Start with the intrinsic handling in ConvertStmt.cpp and the definitions in Intrinsics.cpp, then reproduce the duplicate symbol by compiling the two provided kernel translation units and linking them together. Check how the generated __nvqpp_vectorCopyCtor linkage is lowered; done means the multi-translation-unit link succeeds and the helper is no longer emitted as a public strong symbol.
Written by the indexing model from the issue text.
Description
Summary
Since #5044 (a2f58465), __nvqpp_vectorCopyCtor is marked no_inline. It therefore
survives codegen into every object file that needs it, but it is emitted with
external linkage — so linking two or more separately-nvq++-compiled translation
units into one library or executable now fails with duplicate symbols.
Any __qpu__ kernel returning a std::vector pulls in the intrinsic
(ConvertStmt.cpp loads it for span-like return types), so this is easy to hit.
Reproducer
// a.cpp
#include <cudaq.h>
__qpu__ std::vector<cudaq::measure_result> kern_a() {
cudaq::qvector q(2);
h(q[0]);
return mz(q);
}
b.cpp is identical with kern_a renamed to kern_b.
$ nvq++ -c -fPIC a.cpp -o a.o
$ nvq++ -c -fPIC b.cpp -o b.o
$ nm -g a.o | grep vectorCopyCtor
00000000000000e0 T __nvqpp_vectorCopyCtor # strong global, in both objects
$ nvq++ -shared a.o b.o -o libtwo.so
ld.lld: error: duplicate symbol: __nvqpp_vectorCopyCtor
>>> defined at a.cpp
>>> a.o:(__nvqpp_vectorCopyCtor)
>>> defined at b.cpp
>>> b.o:(.text+0xe0)
clang++: error: linker command failed with exit code 1
(GNU ld reports the same as multiple definition of '__nvqpp_vectorCopyCtor'.)
Linking either object alone succeeds. Note that the helper is also exported from the
resulting library's dynamic symbol table:
$ nvq++ -shared a.o -o libone.so && nm -D libone.so | grep vectorCopyCtor
000000000000f800 T __nvqpp_vectorCopyCtor
Before #5044 the helper was inlined and DCE'd, so no
object carried a definition and the link succeeded.
The emitted definition is dead code
In the object above, the duplicated definition is never referenced — the call site is
inlined anyway, and only the external linkage forces the body to be emitted:
$ nm a.o | grep vectorCopyCtor
00000000000000e0 T __nvqpp_vectorCopyCtor # defined ...
$ objdump -r a.o | grep -c vectorCopyCtor
0 # ... but zero relocations reference it
$ objdump -dr a.o --disassemble='__nvqpp__mlirgen__function_kern_a._Z6kern_av' | grep -o malloc
malloc # helper was inlined into the kernel
So on this path no_inline does not prevent LLVM from inlining the helper; it only
forces an unreferenced copy into every object, which then collides at link time.
(The attribute presumably still does useful work on the Quake/QIR device path that
#5044 targeted.)
Expected
Compiler-generated per-TU helpers should be mergeable or TU-local, and should not
land in a library's public ABI. nm should show W (weak/linkonce_odr) or t
(internal), not T.
Candidate fixes (all verified to fix the link)
Rebuilt main locally with each of these and re-ran the reproducer:
| variant | attribute on @__nvqpp_vectorCopyCtor |
link |
|---|---|---|
A (current main) |
{no_inline} |
fails |
| B | (attribute removed) | passes |
| C | {no_inline, llvm.linkage = #llvm.linkage<linkonce_odr>} |
passes |
| D | {no_inline, llvm.linkage = #llvm.linkage<internal>} |
passes |
C and D keep no_inline and so preserve whatever #5044 needs on the device path,
which makes them preferable to B. In all three the symbol disappears from the object
entirely (inlined, then the discardable definition dropped).
Worth applying at the mechanism level: other intrinsics in Intrinsics.cpp are
exposed to the same hazard the moment they stop being inlined, since func.func private there does not lower to internal LLVM linkage.
Notes
In-tree tests likely miss this because they link one translation unit at a time.
CUDA-QX is a downstream example: libcudaq-qec.so links four device objects and has
failed to build against CUDA-Q main since 2026-08-18.
Environment
- CUDA-Q
main, first bad commit a2f58465 (#5044, merged 2026-08-17) - Last known good: 383c736f
- Reproducer verified on
main@ 3d450c3e73, amd64; CI shows the same on arm64 and CUDA 12.6/13.0
- Dominant language
- C++
- Stars
- 1.2k
- Forks
- 508
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 100
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/cuda-quantum
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
NVIDIA/cuda-quantum#6035 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 77/100
NVIDIA/cuda-quantum#6034 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-quantum#6033 ·
Maintainers usually reply within 1 day
-
Point the CUDA-Q Pulse research preview docs to the released cudaq-pulse packagePossibly taken @fedonman claimed this 2 days ago. Open
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
NVIDIA/cuda-quantum#6031 ·
Maintainers usually reply within 1 day
-
Realtime fnv1a_hash sign-extends char, so a non-ASCII handler name gets a platform-dependent function idPossibly taken @fedonman claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
NVIDIA/cuda-quantum#6029 ·
Maintainers usually reply within 1 day
All issues in NVIDIA/cuda-quantum
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 2 days
-
bug data-types
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ClickHouse/clickhouse-cpp#645 ·
Maintainers usually reply within 1 day
-
bug compatibility difficulty:easy prio:normal
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NatronGitHub/openfx-misc#524 ·
Maintainers usually reply within 1 day
-
documentation enhancement help wanted P0
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Awesome-Embedded-Learning-Studio/Tutorial_AwesomeModernCPP#359 ·
Maintainers usually reply within 1 day
-
Type: Bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
openscad/openscad#7360 · 2 comments ·
Maintainers usually reply within 1 day