enjoy-digital / litex

Build your hardware, easily!
Other
2.89k stars 555 forks source link

Support newer/custom toolchain other than the one downloaded by litex #1272

Open xhebox opened 2 years ago

xhebox commented 2 years ago

I am on a musl-libc based machine. Thus instead of downloading a x86_64-unknown-linux-gnu toolchain by ./litex_setup.py --gcc=riscv, I prefer to compile a custom toolchain by myself. A summary of problems:

  1. xxx-pc-linux-musl triple in toolchain detection will block the usage of musl toolchain https://github.com/enjoy-digital/litex/blob/f46d1c190b9dc87ecfea43def69862ce99d99559/litex/soc/cores/cpu/__init__.py#L52-L68
  2. After a version of binutils(haven't looked into it), zicsr are separated from i, which implies -march=rv32i_zicsr to correct compile softwares. BTW, I am binutils-2.28. Maybe some post-processing to cflags with version detection.
  3. picolibc has some compiling problems with riscvXX-pc-linux-musl toolchain, refer picolibc/picolibc#277
  4. xxx-pc-linux-musl GCC compiled with --enable-default-pie and -flto will cause linking issues and will not boot bios prompt.
mithro commented 2 years ago

@xhebox - You need to be careful about the difference between the toolchain being used for the target and the toolchain you use for the host. I don't believe anyone is currently running musl on a LiteX based system (but I could be wrong).

xhebox commented 2 years ago

@xhebox - You need to be careful about the difference between the toolchain being used for the target and the toolchain you use for the host. I don't believe anyone is currently running musl on a LiteX based system (but I could be wrong).

I am clear about the target and the host. I am on x86_64-pc-linux-musl host, and have a cross compiler of riscv64-pc-linux-musl to target riscv64-pc-elf-picolibc. The latter will be used to compile software of litex.

Yeah, it is not musl on litex-based system, but litex on musl-based system. I'am currently running litex with my custom toolchain, with above problem addressed.

EDIT:

[xhe@PC ~]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/lib/gcc/x86_64-pc-linux-musl/11.2.0/lto-wrapper
Target: x86_64-pc-linux-musl
Configured with: /mnt/hdd2/noname-linux/ports/gcc/src/gcc-11.2.0/configure --target=x86_64-pc-linux-musl --prefix= --libexecdir=/lib --libdir=/lib --enable-languages=c,c++,lto --with-pkgversion=noname --enable-shared --enable-threads=posix --enable-checking=release --enable-libstdcxx-time --with-system-zlib --enable-__cxa_atexit --with-linker-hash-style=gnu --enable-linker-build-id --enable-cet=auto --enable-default-pie --enable-default-ssp --enable-clocale=generic --enable-gnu-indirect-function --enable-lto --enable-plugin --enable-nls --disable-vtable-verify --disable-target-libiberty --disable-fixed-point --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-libsanitizer --disable-libssp --disable-werror --disable-symvers --disable-multilib --disable-sjlj-exceptions --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (noname) 
[xhe@PC ~]$ riscv64-pc-linux-musl-gcc -v
Using built-in specs.
COLLECT_GCC=riscv64-pc-linux-musl-gcc
COLLECT_LTO_WRAPPER=/lib/gcc/riscv64-pc-linux-musl/11.2.0/lto-wrapper
Target: riscv64-pc-linux-musl
Configured with: /mnt/hdd2/noname-linux/ports/gcc/src/gcc-11.2.0/configure --target=riscv64-pc-linux-musl --with-sysroot=/riscv64-pc-linux-musl --prefix= --libexecdir=/lib --libdir=/lib --program-prefix=riscv64-pc-linux-musl- --enable-languages=c,c++ --enable-shared --enable-threads=posix --with-pkgversion=noname --enable-checking=release --enable-libstdcxx-time --with-system-zlib --enable-__cxa_atexit --with-linker-hash-style=gnu --enable-linker-build-id --enable-cet --disable-default-pie --enable-default-ssp --enable-clocale=generic --enable-gnu-indirect-function --enable-lto --enable-plugin --disable-nls --disable-vtable-verify --disable-target-libiberty --disable-fixed-point --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-libsanitizer --disable-libssp --disable-werror --disable-symvers --disable-multilib --disable-sjlj-exceptions --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (noname) 
xhebox commented 2 years ago

@enjoy-digital Could you reopen the issue? Since https://github.com/enjoy-digital/litex/commit/eab58ff0e9bc707c2809261b44d907e809057796 has reverted the working patch.

xhebox commented 2 years ago

ping @enjoy-digital