Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to compile rust for riscv32imc-unknown-none-elf with clang 19.0.0git #121371

Open
erickt opened this issue Feb 21, 2024 · 4 comments
Open
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. O-riscv Target: RISC-V architecture T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Comments

@erickt
Copy link
Contributor

erickt commented Feb 21, 2024

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: compiler_builtins@0.1.108: 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.

@erickt erickt added the C-bug Category: This is a bug. label Feb 21, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 21, 2024
@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. O-riscv Target: RISC-V architecture labels Feb 21, 2024
@jieyouxu jieyouxu added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 7, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 8, 2024
@workingjubilee
Copy link
Member

@rakicaleksandar1999
Copy link

This bug doesn't exist if Rust is compiled against the commit 6be7b0c7d2b085474f9f2f9323c2266f4df105d8.

@workingjubilee workingjubilee added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Aug 1, 2024
@lrettig
Copy link

lrettig commented Aug 9, 2024

This bug doesn't exist if Rust is compiled against the commit 6be7b0c7d2b085474f9f2f9323c2266f4df105d8.

I'm still seeing the same issue with this commit.

@lrettig
Copy link

lrettig commented Aug 9, 2024

we've figured out a workaround in this patch where we're setting the environment variable to this to use the --target=riscv32.

@erickt could you kindly share this patch publicly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. O-riscv Target: RISC-V architecture T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)
Projects
None yet
Development

No branches or pull requests

7 participants