Add -Z direct-access-external-data · Issue #707 · rust-lang/compiler-team (original) (raw)

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:

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:

You can read more about Major Change Proposals on forge.

Comments