rust-lang / rust-lang/rust-bindgen

RISC-V target not passed on correctly to clang

Open
#1,555 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Bindgen fails with hard-to-debug erros (see example) when invoked cargo's target riscv32imac-unknown-none-elf. I can pass a --target=riscv32 flag explicitly passed in via a CFLAG -- but the code for that is described as only a workaround for a long-closed clang issue.

The platform passed in as TARGET from cargo is riscv32imac-unknown-none-elf in those cases, but needs to be passed to clang as riscv32-unknown-none-elf (or riscv32).

I'm not sure whether bindgen is the right place to fix the mismatch between riscv32imac and riscv32, but the workaround I have to use seems to indicate that the TARGET used from cargo is not exactly the value --target needs.

Minimal example (would expect the output of the lower command for the higher command too)

$ touch null.h
$ TARGET=riscv32imac-unknown-none-elf bindgen ./null.h
thread 'main' panicked at 'libclang error; possible causes include:
- Invalid flag syntax
- Unrecognized flags
- Invalid flag arguments
- File I/O errors
If you encounter an error missing from this list, please file an issue or a PR!', src/libcore/option.rs:1036:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.
$ TARGET=riscv32imac-unknown-none-elf bindgen ./null.h -- --target=riscv32-unknown-none-elf
/* automatically generated by rust-bindgen */

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the target-handling code in src/ir/context.rs around the referenced line, then reproduce the failure using TARGET=riscv32imac-unknown-none-elf and the null.h commands in the issue. Compare that result with the explicit --target=riscv32-unknown-none-elf invocation; done means the implicit target produces the same generated header without the workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.