From e3f198ec05bdae302caf792cb4ab2e07d834d7d9 Mon Sep 17 00:00:00 2001 From: WANG Rui Date: Tue, 20 Jan 2026 16:18:56 +0800 Subject: [PATCH 1/2] LoongArch: Fix direct-access-external-data test On LoongArch targets, `-Cdirect-access-external-data` defaults to `no`. Since copy relocations are not supported, `dso_local` is not emitted under `-Crelocation-model=static`, unlike on other targets. --- .../direct-access-external-data.rs | 1 + .../loongarch/direct-access-external-data.rs | 47 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 tests/codegen-llvm/loongarch/direct-access-external-data.rs diff --git a/tests/codegen-llvm/direct-access-external-data.rs b/tests/codegen-llvm/direct-access-external-data.rs index 73dc08dc2b57..a151bb6012e1 100644 --- a/tests/codegen-llvm/direct-access-external-data.rs +++ b/tests/codegen-llvm/direct-access-external-data.rs @@ -1,3 +1,4 @@ +//@ ignore-loongarch64 (handles dso_local differently) //@ ignore-powerpc64 (handles dso_local differently) //@ ignore-apple (handles dso_local differently) diff --git a/tests/codegen-llvm/loongarch/direct-access-external-data.rs b/tests/codegen-llvm/loongarch/direct-access-external-data.rs new file mode 100644 index 000000000000..de495d7fe9a7 --- /dev/null +++ b/tests/codegen-llvm/loongarch/direct-access-external-data.rs @@ -0,0 +1,47 @@ +//@ only-loongarch64 + +//@ revisions: DEFAULT PIE DIRECT INDIRECT +//@ [DEFAULT] compile-flags: -C relocation-model=static +//@ [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"] +#![feature(linkage)] + +unsafe extern "C" { + // CHECK: @VAR = external + // DEFAULT-NOT: dso_local + // PIE-NOT: dso_local + // DIRECT-SAME: dso_local + // INDIRECT-NOT: dso_local + // CHECK-SAME: global i32 + safe static VAR: i32; + + // When "linkage" is used, we generate an indirection global. + // Check dso_local is still applied to the actual global. + // CHECK: @EXTERNAL = external + // DEFAULT-NOT: dso_local + // PIE-NOT: dso_local + // DIRECT-SAME: dso_local + // INDIRECT-NOT: dso_local + // CHECK-SAME: global i8 + #[linkage = "external"] + safe static EXTERNAL: *const u32; + + // CHECK: @WEAK = extern_weak + // DEFAULT-NOT: dso_local + // PIE-NOT: dso_local + // DIRECT-SAME: dso_local + // INDIRECT-NOT: dso_local + // CHECK-SAME: global i8 + #[linkage = "extern_weak"] + safe static WEAK: *const u32; +} + +#[no_mangle] +pub fn refer() { + core::hint::black_box(VAR); + core::hint::black_box(EXTERNAL); + core::hint::black_box(WEAK); +} From d977471ce22c379cd7f8a53d907aecab67d05195 Mon Sep 17 00:00:00 2001 From: WANG Rui Date: Tue, 20 Jan 2026 17:09:52 +0800 Subject: [PATCH 2/2] LoongArch: Fix call-llvm-intrinsics test --- tests/codegen-llvm/loongarch-abi/call-llvm-intrinsics.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/codegen-llvm/loongarch-abi/call-llvm-intrinsics.rs b/tests/codegen-llvm/loongarch-abi/call-llvm-intrinsics.rs index 9a50f7b8e3a5..36eb2dde7afb 100644 --- a/tests/codegen-llvm/loongarch-abi/call-llvm-intrinsics.rs +++ b/tests/codegen-llvm/loongarch-abi/call-llvm-intrinsics.rs @@ -23,9 +23,7 @@ pub fn do_call() { unsafe { // Ensure that we `call` LLVM intrinsics instead of trying to `invoke` them - // CHECK: store float 4.000000e+00, ptr %{{.}}, align 4 - // CHECK: load float, ptr %{{.}}, align 4 - // CHECK: call float @llvm.sqrt.f32(float %{{.}} + // CHECK: call float @llvm.sqrt.f32(float 4.000000e+00) sqrt(4.0); } }