-
Notifications
You must be signed in to change notification settings - Fork 135
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
Clang/LLVM Toolchain Support #777
Comments
FYI @carlescufi @tejlmand |
@stephanosio are there expected to be Zephyr specific changes to the LLVM build? If so, would it make sense to include libclang to allow developers to build extensions on it? |
Not right now; but, it is foreseeable that we will need to carry some local patches in the future.
That is an interesting topic -- if it does not add too much to the build time or the distribution archive size, I think libclang would be a reasonable addition. |
Architecture WG:
|
I'm super excited to see this--thank you @stephanosio for creating this! This looks great to me, though I do have a few questions I'm hoping to run by you:
|
Yes, I am planning to also include the AArch64 support if there is no major obstacle in doing so (AFAICS, there should be none).
I am planning to start with LLVM 18 for now, mainly because that is what the latest release of LLVM Embeeded Toolchain for Arm has and I will be implementing the SDK build script based on that.
At first glance, writing a patch to support the additional variants required by the Zephyr SDK (especially, the RV32E variants) looks like it should be fairly simple -- we can carry that patch in the Zephyr fork of LLVM until a new LLVM release with more robust RISC-V multi-lib support is available. If that turns out to be not so simple for whatever reason, I will have to look into upgrading to a newer LLVM codebase or even brute-forcing the Zephyr build system to manually handle the RISC-V multi-lib variants ...
crosstool-ng is a very popular tool for building embedded cross compiler toolchains, and that is what Zephyr SDK build system currently uses to build the GNU toolchains. crosstool-ng is nice because it abstracts away all the tedious processes involved in building cross-compiler toolchains (e.g. builder OS -specific dependencies, host OS-specific dependencies, target dependencies ...) and allows one to build a toolchain from a Kconfig-based "recipe." While it may not sound like much at first, it can be very useful when you are setting up a complex toolchain build environment such as one for a Canadian cross compiler (e.g. building While "LLVM Embedded Toolchain for RISC-V" that comes with custom scripts to build general purpose RISC-V LLVM toolchain sounds interesting, IMHO, having the ability to build any flavour of LLVM you want from a Kconfig-based recipe using crosstool-ng would be nicer. |
Awesome! Apologies if I overlooked that somewhere.
Sounds good!
Also sounds good! I think you're right that it should be fairly simple to add a patch to support additional variants but I also can't say I've tried it.
I see, makes sense! I don't have any particular objection here, it had just come up in LLVM's community a few times recently so I thought I would ask 🙂 Thank you again for proposing this and I'm excited to see this happen! |
Great initiative, @stephanosio, to add on to @jonathonpenix's list, do you plan to include RISC-V 64 bit targets as well? Including Arm 32 and 64-bit targets, and RISC-V 32 and 64-bit targets will be useful. Also, any plans to also include hard float support? |
I'm working on llvm toolchain support in picolibc by building with the LLVM embedded toolchain for Arm. I've found a few compatibility issues with clang and llvm-as, along with some differences in behavior between compiler-rt and libgcc (some look like bugs in compiler-rt to me). In any case, picolibc will be using that toolchain in CI going forward. Once there's a Zephyr clang toolchain, I'll add that to picolibc CI as well. picolibc/picolibc#856 |
A preliminary test build from To test, follow the steps below:
|
I'm having some adventures getting this toolchain to build picolibc with --multilib=true. I looked at how sdk-ng is building picolibc and it's using --multilib=false and then hand-coding all of the multilib variants and directory paths. I think that is masking some bugs in the current llvm setup... The multilib configuration file is supposed to map compiler args to library directories, but I'm seeing a difference between what that file contains and where the libraries are getting installed for risc-v:
The /opt/zephyr-sdk-0.18.0-alpha1-3-g0476815/llvm/lib/clang/19/lib exists, but it is completely empty. Instead, the library is installed way over in llvm/lib/clang-runtimes/riscv32-none-elf/rv32i_zicsr_zifencei/lib/libclang_rt.builtins.a:
There's also some weirdness when using Here's the riscv32 set using
and here's the riscv32 set using
Picolibc doesn't (yet) support building for multiple targets in the same |
You need this patch to get RISC-V multilib from UPDATE: Done. #839 should pull that LLVM patch and also add the RISC-V multi-libs. |
This enhancement issue describes the Clang/LLVM toolchain support plan in the Zephyr SDK.
Goals
Specifications
LLVM Binary Utilities
Clang Compiler
Pre-built Libraries
Zephyr Build System Integration
ZEPHYR_TOOLCHAIN_VARIANT=zephyr-llvm
.ZEPHYR_TOOLCHAIN_VARIANT=zephyr
(aka. GCC) shall be renamed toZEPHYR_TOOLCHAIN_VARIANT=zephyr-gnu
.ZEPHYR_TOOLCHAIN_VARIANT=zephyr
shall map toZEPHYR_TOOLCHAIN_VARIANT=zephyr-gnu
for the foreseeable in order to ensure compatibility.zephyr-llvm
toolchain shall invoke Clang compiler with LLVM Linker [4]:COMPILER=clang
,BINTOOLS=llvm
,LINKER=lld
SDK Distribution
The existing "GNU toolchain distribution archive" (Binutils and GCC will be kept in the same "GNU" archive since Zephyr SDK LLVM support will default to using LLVM lld, not GNU ld.toolchain_HOST-TARGET
) shall be split into "GNU Binutils distribution archive" (toolchain_gnu-binutils_OS-TARGET
) and "GCC distribution archive" (toolchain_gcc_HOST-TARGET
) [5].toolchain_llvm-binutils_HOST
) shall be added.toolchain_clang-base_HOST
) shall be added.toolchain_clang-lib_HOST-TARGET
) shall be added.zephyr-sdk-VER_HOST
) shall be renamed tozephyr-sdk-VER-gcc_HOST
.zephyr-sdk-VER-clang_HOST
) shall be added.Clang/LLVM Toolchain Build Process
[1] Based on the "LLVM Binary Utilities" included in LLVM Embedded Toolchain for Arm.
[2] Based on the pre-built multi-libs included in LLVM Embedded Toolchain for Arm.
[3] Based on the pre-built 32-bit RISC-V multi-libs currently included in the SDK GCC.
[4]
LLVM Linker (lld) support is currently very limited and it is desirable to use GNU Linker (ld) for maximum compatibility. Note that GNU Linker is used by default forlld support seems to be sufficiently mature now.ZEPHYR_TOOLCHAIN_VARIANT=llvm
as well.[5] This ensures that GNU Linker, which is part of GNU Binutils, can be installed alongside Clang/LLVM toolchain without installing GCC.
[6] Ideally, we would implement Clang/LLVM toolchain support in crosstool-ng and upstream it; but, doing so will likely delay this task too much for our liking -- we will see.
Tasks
Phase 1
Inclusion of Clang/LLVM toolchain binaries and pre-built compiler-rt library for Arm-M-profile cores and RISC-V RV32I and RV32E cores in the SDK
Phase 2
Addition of pre-built C/C++ libraries for Arm M-profile cores and RISC-V RV32I and RV32E cores to the SDK
Future
(Nothing concrete about these ...)
Resources
The text was updated successfully, but these errors were encountered: