Inquiry about how Clang supports the kernel
A message that is not in the archive (sent off-list or not yet received): [email protected]
+ our public mailing list
Quoted 3 lines · 孙铖
Hello,I am a graduate student at Lanzhou University in China, Sun Cheng. We now have a small RTOS that is compiled with GCC by default, and we want to get the Clang/LLVM compiler to support it as well. But I don't have any idea about how to implement it, so I am sending you an email and hope I can get some advice from you. I would be very grateful for your help!
Hi and thanks for reaching out!
Clang is designed to be a drop in replacement for GCC (and CL.exe) in terms of command line arguments and supported language extensions. It's not a perfect substitute, but it does rely on LLVM for competitive codegen and compile time with contemporary compilers. LLVM also features substitutes for most of GNU Binutils command line utilities, which we generally use when building the Linux kernel.
One of the first things to check for your RTOS is see if the build system allows you to specify the compiler that's invoked. For instance, rather than hardcoding gcc in a bunch of places, if your build system uses a placeholder or variable with default value that can be overridden, then you would be able to specify clang perhaps. From there, you might find that some command line arguments are not supported by clang, or some code might have portability issues and won't compile. Once it builds, code reliant on UB or unspecified behavior might not run as expected. But being to build+run code built from 2 different toolchains generally leads to higher quality implementations.
Another thing you can to to verify that you've wired up your build system correctly is to see if you can build with clang in an environment that does not have GCC installed. We call that a hermetic build system, in which build dependencies have to be fully specified, and aren't implicit based on the host. That also helps improve portability of the build.
Signature · 2 lines
Thanks, ~Nick Desaulniers