-
Notifications
You must be signed in to change notification settings - Fork 339
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
Compiling with clang, possible? Too much work for it? #194
Comments
I had a quick (1h) look. This is current state of my research and I definitely approve the idea of having a Clang build for static analysis. Do you used Clang on embedded projects before (without STM32-cmake) ? If yes maybe you could share and example project or past experience ? |
I had spent some hours yesterday on the topic. Just out of curiosity I made some small changes to the blinky example to check if it could compile. The changes to the blinky example are here: https://github.com/andyinno/stm32-cmake/tree/clang_test Basically I can compile the project. The problem is on the linking. I read online that a lot of people are using the gnu linker for linking the final executable. I did not understand how yet. Using the clang linker I can link the c and math libraries passing to the linker the path to the GNU libraries. One change that is needed is to remove the hardcoded toolchain file present in the cmake example. I do not think that they are really "modern cmake" style. Second change is just the toolchain file. In the toolchain file I hardcoded the paths present on my system. The resulting error that linker outputs is:
I read online that the library is not shipped with clang but everybody needs to compile it on its own. Regarding your last questions:
I followed a different approach on it in my own projects. For static analysis I isolated the arm only code in files that are only built when the target is arm. Otherwise I link mocked functions and I perform ctests on the host computer using cmocka.
Never used clang on embedded. I just understand that the ARM toolchain is a patched version of CLANG. What I see compiling parts of my embedded programs for X64 is that clang analyzer is a bit more picky than the gnu gcc one. Therefore I would like to see also the rest of the code (the one that I cannot compile for X64) how behave with CLANG. The binary file, I am not sure if I could use it in production yet. |
Cool :) Thank you for your feedback. I notice that Also I know that setting I agree that hardcoded toolchain path is not modern cmake but I'm not comfortable enough with cmake to propose a fix. I fell like this toolchain file thing always becomes a bit tricky when coming to embedded cross-compilation and many of the old information is masking the modern cmake approach on the web. |
It was just an apt install clang, everything went on my pc automagically. Except the clang_rt.builtins-arm file. The fix on the hardcoded toolchain is just to explicit it with the cmake invocation. Nothing more than that. :) |
Ok, I compiled the clang_rt.builtins-arm file for arm cortex 4. for reference and credits I followed the instruction that are present in this blog post: https://interrupt.memfault.com/blog/arm-cortexm-with-llvm-clang#cross-compiling-with-clang
cloned the LLVM project
then the compilation completes correctly. |
I would just know if anybody here has already tried to compile using this project and clang.
If some modification is needed, could it be possible to share?
thank you in advance
Andrea
The text was updated successfully, but these errors were encountered: