Skip to content

Add -Z direct-access-external-data #707

Closed
@heiher

Description

@heiher

Proposal

Some architectures, such as LoongArch, do not support copy relocation and are not expected to support it in the future. Consequently, regardless of whether the relocation model is static or pic, direct access to external data should be avoided, and indirect access through the GOT is recommended. However, certain special cases, such as the Linux kernel, require different approaches for accessing external data in vmlinux and modules. Therefore, I propose introducing the Clang's direct-access-external-data option into Rustc.

Option -Z direct-access-external-data controls how to access symbols of external data.

Supported values for this option are:

  • yes - Don't use GOT indirection to reference external data symbols.
  • no - Use GOT indirection to reference external data symbols.

If the option is not explicitly specified, different targets have different default values. (Equivalent to the default behavior before this)

For example:

extern "C" {
    static VAR: i32;
}

#[no_mangle]
pub fn get() -> i32 {
    unsafe { VAR }
}

direct-access-external-data=yes

@VAR = external dso_local {{.*}} global i32

direct-access-external-data=no

@VAR = external {{.*}} global i32

Mentors or Reviewers

Process

The main points of the Major Change Process are as follows:

  • File an issue describing the proposal.
  • A compiler team member or contributor who is knowledgeable in the area can second by writing @rustbot second.
    • Finding a "second" suffices for internal changes. If however, you are proposing a new public-facing feature, such as a -C flag, then full team check-off is required.
    • Compiler team members can initiate a check-off via @rfcbot fcp merge on either the MCP or the PR.
  • Once an MCP is seconded, the Final Comment Period begins. If no objections are raised after 10 days, the MCP is considered approved.

You can read more about Major Change Proposals on forge.

Comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-compilerAdd this label so rfcbot knows to poll the compiler teammajor-changeA proposal to make a major change to rustcmajor-change-acceptedA major change proposal that was accepted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions