rust-lang / rust-lang/rust

Remove extra indirection from statics with linkage?

Open
#156,468 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkage F-linkage needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I just learned from @bjorn3 that the way we represent statics with linkage, such as #[linkage = "extern_weak"], is kind of strange:

unsafe extern "C" {
    #[linkage = "extern_weak"]
    static test_symbol_that_does_not_exist: Option<unsafe extern "C" fn()>;
}

Here, test_symbol_that_does_not_exist will actually be a global variable local to this module that points to the weak symbol.

Now that we have the &raw address-of operator, we could avoid this extra indirection. Whether we should, I do not know.
Cc @bjorn3 @nikic @chorman0773

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 #[linkage = "extern_weak"] example and the &raw address-of operator mentioned in the issue. Determine whether statics with linkage can avoid the module-local pointer, then define the affected behavior and validation before proposing a change; no files or tests are named.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.