rust-lang / rust-lang/rust

nvptx64-nvidia-cuda target does not support self-referential statics

Open
#146,787 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When compiling this code for the nvptx64-nvidia-cuda target, an LLVM error will be thrown:

#![no_std]
struct Bar(&'static Bar);
static FOO: Bar = Bar(&FOO);
rustc-LLVM ERROR: Circular dependency found in global variable set
Compiler returned: 101

This appears to be a fundamental limitation of PTX(self-referential globals are not allowed). This issue seems to be present in all versions of rust which support this target(from the newest nightly back to at least 1.45.2).

I am opening this issue mostly to document this limitation, and I have no idea how it could get fixed.

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 no_std self-referential-static reproducer for the nvptx64-nvidia-cuda target and compare its behavior using the linked Godbolt example. Investigate the reported LLVM circular-dependency error and the target's documented limitations; done means recording a confirmed limitation or identifying a tested path to resolve it.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.