rust-lang / rust-lang/rustc_codegen_cranelift

Access to global variable metadata?

Open
#1,646 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
157
Avg merge
1d 19h
Merged PRs (30d)
3

Description

Hello, I am writing an extension for Cranelift, for which at one point I need to determine the size of static global data.

When compiling an example codebase, with the following buffer declaration and --emit=llvm-ir enabled, I get the expected IR output:

static BUFFER: [i32; 5] = [1, 2, 3, 4, 0];
gv0 = symbol userextname0 ; DefId(0:4 ~ extension_test_example[f5b4]::BUFFER)

I discovered that the above comment is generated in the codegen_fn_body function, but failed to further narrow it down. Is it possible to determine the exact spot where DefId is converted into a GlobalValueData object?

Contributor guide

No contributing guide indexed for this repository

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 in the codegen_fn_body function and trace how the DefId shown in the emitted LLVM IR becomes a GlobalValueData object. The issue names no file or test; done would be identifying the conversion point and establishing how the static global's size metadata could be obtained.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.