Fix and expand direct-access-external-data test

This test currently doesn't fulfill its purpose, as `external dso_local`
can still match `external {{.*}}`. Fix this by using CHECK-NOT directives.

Also, this test is expanded to all platforms where it makes sense, instead
of restricting to loongarch.
This commit is contained in:
Gary Guo 2025-12-29 19:23:26 +00:00
parent 7e7280f24b
commit 1ff953d63e

View file

@ -1,21 +1,25 @@
//@ only-loongarch64-unknown-linux-gnu
//@ ignore-powerpc64 (handles dso_local differently)
//@ ignore-apple (handles dso_local differently)
//@ revisions: DEFAULT DIRECT INDIRECT
//@ revisions: DEFAULT PIE DIRECT INDIRECT
//@ [DEFAULT] compile-flags: -C relocation-model=static
//@ [DIRECT] compile-flags: -C relocation-model=static -Z direct-access-external-data=yes
//@ [PIE] compile-flags: -C relocation-model=pie
//@ [DIRECT] compile-flags: -C relocation-model=pie -Z direct-access-external-data=yes
//@ [INDIRECT] compile-flags: -C relocation-model=static -Z direct-access-external-data=no
#![crate_type = "rlib"]
// DEFAULT: @VAR = external {{.*}} global i32
// DIRECT: @VAR = external dso_local {{.*}} global i32
// INDIRECT: @VAR = external {{.*}} global i32
extern "C" {
static VAR: i32;
unsafe extern "C" {
// CHECK: @VAR = external
// DEFAULT-SAME: dso_local
// PIE-NOT: dso_local
// DIRECT-SAME: dso_local
// INDIRECT-NOT: dso_local
// CHECK-SAME: global i32
safe static VAR: i32;
}
#[no_mangle]
pub fn get() -> i32 {
unsafe { VAR }
pub fn refer() {
core::hint::black_box(VAR);
}