Skip to content

Commit 9988806

Browse files
committed
arch: loongarch64_nosimd: Pass -mattr=-lsx to the linker plugin for Rust
The "Rust + linker-plugin = LSX in main" issue may haunt all Rust binaries, even a "hello world" program is proven to be affected. So aosc-os-abbs/.../oma is just not the correct location to work it around. And disabling LTO is overly aggressive, we just need to pass an option to the linker plugin to disable LSX. FWIW I'm unsure if we should report this as a Rustc issue. Signed-off-by: Xi Ruoyao <[email protected]>
1 parent bd84bd2 commit 9988806

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/loongarch64_nosimd.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ fi
2424
# - https://github.com/rust-lang/rust/blob/a932eb36f8adf6c8cdfc450f063943da3112d621/compiler/rustc_target/src/spec/targets/loongarch64_unknown_linux_gnu.rs#L18
2525
# - https://github.com/llvm/llvm-project/blob/98b895da30c03b7061b8740d91c0e7998e69d091/clang/lib/Driver/ToolChains/Arch/LoongArch.cpp#L133
2626
RUSTFLAGS_COMMON_ARCH=('-Ctarget-cpu=generic-la64' '-Ctarget-feature=-lsx,+d' '-Clink-arg=-mabi=lp64d')
27+
28+
# Rustc does not apply -Ctarget-feature as an attribute to the main function
29+
# (the function that __libc_start_call_main calls, not crate::main). So
30+
# during LTO, the linker plugin may inline some code into main and vectorize
31+
# them. Tell lld to disable LSX unless it's explicitly enabled in the
32+
# function attribute, so main won't be vectorized.
33+
RUSTFLAGS_COMMON_ARCH_LTO=('-Clink-arg=-Wl,-plugin-opt,-mattr=-lsx')

0 commit comments

Comments
 (0)