Description
We're running into an issue on Fuchsia where we fail to compile tip-of-tree rust targeting riscv32imc-unknown-none-elf
while using a nightly build of clang 19.0.0git, which is at the moment:
clang --version
Fuchsia clang version 19.0.0git (https://llvm.googlesource.com/llvm-project 1e7d5871eed1bdf1eeb4b50eb9b911774f420ca1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/google/home/etryzelaar/src/fuchsia-rust/clang/bin
Rust compilation will fail trying to compile compiler-builtins
with this error:
Building stage2 library artifacts (aarch64-unknown-linux-gnu -> riscv32imc-unknown-none-elf)
Compiling core v0.0.0 (/b/s/w/ir/x/w/fuchsia-third_party-rust/library/core)
Compiling compiler_builtins v0.1.108
The following warnings were emitted during compilation:
warning: [email protected]: error: unknown target triple 'riscv32imc-unknown-none-elf'
error: failed to run custom build command for `compiler_builtins v0.1.108`
Caused by:
process didn't exit successfully: `/b/s/w/ir/x/w/staging/build/fuchsia-build/aarch64-unknown-linux-gnu/stage2-std/release/build/compiler_builtins-67cabcbd74a02cc3/build-script-build` (exit status: 1)
...
running: "/b/s/w/ir/x/w/cipd/bin/clang" "-O3" "-ffunction-sections" "-fdata-sections" "-g" "-fno-omit-frame-pointer" "--target=riscv32imc-unknown-none-elf" "-ffunction-sections" "-fdata-sections" "--target=riscv32imc-unknown-none-elf" "-fno-builtin" "-fvisibility=hidden" "-ffreestanding" "-DVISIBILITY_HIDDEN" "-o" "/b/s/w/ir/x/w/staging/build/fuchsia-build/aarch64-unknown-linux-gnu/stage2-std/riscv32imc-unknown-none-elf/release/build/compiler_builtins-70bd6bc9d3d89298/out/fdce3f58404f6d87-absvdi2.o" "-c" "/b/s/w/ir/x/w/fuchsia-third_party-rust/src/llvm-project/compiler-rt/lib/builtins/absvdi2.c"
cargo:warning=error: unknown target triple 'riscv32imc-unknown-none-elf'
The full build logs can be seen here, with the compilation logs, our config.toml, and our environment variables.
According to that target's spec, it should be using the riscv32
target with llvm and clang.
Tracing through the commits, it appears the compilation failure was introduced in rust-lang/compiler-builtins#563, when compiler-builtins
added support to fall back to compiler-rt
for riscv for some intrinsics. However I'm not sure if it's a compiler-builtins
issue. According to the build logs and my investigation, it looks like the rustc build system is explicitly setting setting the environment variable that's being used by compiler-builtins
when it tries to compile the intrinsics:
CFLAGS_riscv32imc_unknown_none_elf = Some("-ffunction-sections -fdata-sections --target=riscv32imc-unknown-none-elf")
Unfortunately I haven't been able to figure out yet why rust is using the wrong llvm target here. However, we've figured out a workaround in this patch where we're setting the environment variable to this to use the --target=riscv32
.
Meta
This was compiled against the rust-lang/rust commit 2b43e75.