See also my posts in this thread
https://groups.google.com/a/groups.riscv.org/d/msg/sw-dev/8dae3T-fS8A/z2NHToMlBgAJ
On Wed, 29 Mar 2017 10:14:57 PDT (-0700),
tommy_...@hotmail.com wrote:
> OK - here goes and hopefully this makes sense and somebody can advise me
> ... :-)
>
> Is it possible to build a single (bare metal) toolchain for RV32* & RV64*
> Where * means all possible combinations of extensions - e.g. I, M, A, G, C,
> F, D, Q etc.
Depends on what "bare metal" means.
> At the moment when I build with, say, --with-arch=rv32im and
> --with-arch=rv64im then I get two separate toolchains -
> riscv32-unknown-elf-* and riscv64-unknown-elf-*.
> Is it possible to build a single toolchain (either riscv64-unknown-elf-* or
> riscv-unknown-elf-*) that supports both 32 and 64 bit?
Regardless of the configure-time arguments passed to
riscv-gnu-toolchain/configure, binutils and GCC always support all -march/-mabi
combinations. All passing "--with-arch" to riscv-gnu-toolchain/configure does
is:
* Set the default values for -march and -mabi for both GCC and binutils.
* Choose the tuple (as riscv32 or riscv64).
So if you're not worried about libraries then you're all set. If "bare metal"
means you want libraries (either libc or libgcc), then there's some more work
you have to do...
> If not is this due to limitations of the build process or something
> inherent in the tools?
> Similarly is it possible to have a single toolchain that supports all
> possible extensions so that the single toolchain can be called with, say,
> -march=rv32im or -march=rv32g or -march=64imafdq etc.?
> Again, if not, why not?
> Lastly I presume that --enable-multilib when configuring the tools is
> relevant here but does it work and if so what exactly does it do?
Passing "--enable-multilib" to riscv-gnu-toolchain/configure changes how GCC
and libc (either glibc or newlib) are built. This also has two effects:
* GCC gets an additional make fragment, this one for the ELF (newlib)
toolchain <
https://github.com/riscv/riscv-gcc/blob/riscv-next/gcc/config/riscv/t-elf-multilib>.
* The C library gets built multiple times. newlib has internal support for
this, so that's a bit magic. glibc is explicitly configured and built
multiple times based on this list
<
https://github.com/riscv/riscv-gnu-toolchain/blob/master/configure.ac#L100>.
We chose the set of multilibs to encompass systems that seemed reasonable to
build, so they're different between the embedded (newlib/ELF) and Linux (glibc)
targets -- our view is that picking this list is really a distribution problem,
so we just picked a sensible default.
If you're OK with the default lists, then simply passing "--enable-multilib" to
riscv-gnu-toolchain/configure should be sufficient to get everything working.
If you're not, then you'll have to change the lists.
I'd be amenable to allowing some sort of "--with-multilib-list=..." flag to
riscv-gnu-toolchain/configure that lets users pick which multilibs should be
configured, but there'd also need to be some support in GCC for this. It's not
trivial because of the fallback mechanism for multilibs, but it's mostly
scripted so it shouldn't be too hard.