riscv-collab / riscv-gnu-toolchain

GNU toolchain for RISC-V, including GCC
Other
3.41k stars 1.13k forks source link

`README.md` is misleading on Linux/musl toolchain capabilities #1279

Open TommyMurphyTM1234 opened 1 year ago

TommyMurphyTM1234 commented 1 year ago

The musl compiler (riscv64-unknown-linux-musl-) will only be able to target 64-bit systems due to limitations in the upstream musl architecture support.

This is not strictly correct. Any RISC-V toolchain can compile code for any XLEN (and combination of ratified/formalised extensions). This remains the case for the Linux/musl toolchain - it can also compile code for rv32 and is not restricted to rv64. However musl support is indeed currently restricted to rv64 so when linking with the standard library/startup code this will only work when targeting rv64 (and the relevant rv64 multilib is available). If targeting rv32 then link errors will occur given the lack of musl rv32 support. But it is not correct to say that the Linux/musl toolchain "will only be able to target 64-bit systems".

The --enable-multilib flag therefore does not actually enable multilib support for musl libc.

This is also not strictly correct. Yes - the default set of multilibs defined by the default t-linux-multilib contains both rv64 and rv32 arch/abi libs so a toolchain build using that will fail on the attempted compilation of musl for rv32 (musl code contains rv64 specific instructions - for example here). But it is perfectly feasible to override the default t-link-multilib with a custom one that, for example, contains only rv64 arch/abi libs and this sort of multilib toolchain build will succeed for Linux/musl.

Also refer to this crosstool-NG issue where I first encountered the issue:

A tangential issue - how and why was the default set of Linux multilibs arrived at - namely:

Other than the fact that it encompasses rvXXgc it seems slightly arbitrary. And why both 32 and 64 bit when there are few, if any (?), RISC-V Linux systems that can support code for both XLENs?

cmuellner commented 2 weeks ago

I am happy to merge a PR that improves the description in the readme.

I would probably add a simple statement that clearly states that "musl + rv32 => does not work and is not supported." on top. Below, I would add the details you listed above and the effects that can be observed if one still attempts to go this route.