如何使用 tpidr1 作为线程本地寄存器编译 rust

How to compile rust with tpidr1 as thread local register

在裸机 AArch64 中,rust 生成 tpidr0 作为 thread_local 计算的默认寄存器。对于内核这样的场景,应该使用tpidr1而不是tpidr0。 如何让 Rust 编译器生成代码以使用 tpidr1 而不是默认值?

LLVM 支持 custom attribute -mattr=tipdr-el[1|2|3] 来覆盖线程本地寄存器。

默认情况下,tipdr0 用于此目的。这可以通过执行以下操作在 Rust 中被覆盖

rustc -C target-feature=tpidr-el1 --target=aarch64-unknown-none