Clang/LLVM

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome. This forum is NOT for support.
davidji
Posts: 12
Joined: Wed Dec 12, 2012 9:48 pm
Been thanked: 1 time

Clang/LLVM

Postby davidji » Sun May 18, 2014 12:06 pm

It seems to be the case that clang on any platform can generate code for any target platform supported by LLVM. That means that of you install clang from your favourite Linux distribution, you will have a cross compiler for cortex-m3, for example.

It seems to me that using that is vastly simpler and more convenient than building a gcc cross compiler.

- Has anyone tried doing this?
- What problems do you foresee?
- Are there any plans to support CLang in the future?

Cheers
David

User avatar
Giovanni
Site Admin
Posts: 12950
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 733 times
Been thanked: 609 times
Contact:

Re: Clang/LLVM

Postby Giovanni » Sun May 18, 2014 1:28 pm

It would be interesting, especially in order to compare the result.

The problem I can see is that there is no real support except for Linux, I cannot find a maintained toolchain based on LLVM while there are several based on GNU.

Giovanni

JetForMe
Posts: 99
Joined: Mon Jan 31, 2011 8:12 am

Re: Clang/LLVM

Postby JetForMe » Mon Oct 06, 2014 9:43 am

http://ellcc.org just made OS X binaries available (they had Linux ones already). The project contains everything you need (clang/LLVM in the form of "ecc"), binutils, and a C library.

I tried building my SAM7X (arm7tdmi) project with it. I had to change a couple of assembler files to use the ARM standard syntax, and I had to add an include path to ellcc/libecc/include/arm, but it mostly compiles.

Unfortunately, clang does not support anything but asm statements inside naked functions, and so the PORT_IRQ_HANDLER() fails to compile. I think this is a limitation of clang, but it's a deliberate choice made by the the developers (http://comments.gmane.org/gmane.comp.co ... scm/107562), so it's unlikely to change any time soon. Changing "naked" to "interrupt" seems to allow it to compile, but I don't know what impact this might have on performance or what other problems it will cause.

There are some warnings about r13 being uninitialized when used:

Code: Select all

ecc -c -target arm-none-eabi -O2 -ggdb -fomit-frame-pointer -mabi=apcs-gnu --sysroot=/Users/rmann/Desktop/ellcc -ffunction-sections -fdata-sections -std=gnu99 -Wall -Wextra -Wstrict-prototypes -DSTDOUT_SD=SD1 -DSTDIN_SD=SD1 -DCHPRINTF_USE_FLOAT=1   -MD -MP -MF .dep/chschd.o.d  -I. -I../../os/ports/GCC/ARM -I../../os/ports/GCC/ARM/AT91SAM7 -I../../os/kernel/include -I../../test -I../../os/hal/include -I../../os/hal/platforms/AT91SAM7 -I../../boards/LZBalloonController -I../../ext/fatfs/src -I../../os/various -I/Users/rmann/Desktop/ellcc/libecc/include/arm -Ilib ../../os/kernel/src/chschd.c -o build/obj/chschd.o
../../os/kernel/src/chschd.c:128:3: warning: variable 'r13' is uninitialized when used here [-Wuninitialized]
  chSysSwitch(currp, otp);
  ^~~~~~~~~~~~~~~~~~~~~~~
../../os/kernel/include/chsys.h:91:3: note: expanded from macro 'chSysSwitch'
  port_switch(ntp, otp);                                                    \
  ^~~~~~~~~~~~~~~~~~~~~
../../os/ports/GCC/ARM/chcore.h:460:22: note: expanded from macro 'port_switch'
  if ((stkalign_t *)(r13 - 1) < otp->p_stklimit)                            \
                     ^~~
../../os/kernel/src/chschd.c:128:3: note: variable 'r13' is declared here
../../os/kernel/include/chsys.h:91:3: note: expanded from macro 'chSysSwitch'
  port_switch(ntp, otp);                                                    \
  ^
../../os/ports/GCC/ARM/chcore.h:459:3: note: expanded from macro 'port_switch'
  register struct intctx *r13 asm ("r13");                                  \
  ^


I also ran into a problem wherein syscalls.c include <sys/reent.h>, which does not appear to exist in ELLCC's standard library. I'm currently investigating this issue.

faisal
Posts: 260
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 35 times
Been thanked: 34 times

Re: Clang/LLVM

Postby faisal » Sun Jan 07, 2018 8:31 pm

Any updates on this topic? Would be really nice to have Clang/LLVM support. I'm interested in using the clang static analyzer, I've read good things about it.

User avatar
Giovanni
Site Admin
Posts: 12950
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 733 times
Been thanked: 609 times
Contact:

Re: Clang/LLVM

Postby Giovanni » Sun Jan 07, 2018 9:11 pm

Hi,

No progress on this, anyway, PORT_IRQ_HANDLER is no more a naked function so it should work now.

About the static analyzer, I think it can be used regardless if the compiled code works or not. Is there a guide to get started?

Giovanni

faisal
Posts: 260
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 35 times
Been thanked: 34 times

Re: Clang/LLVM

Postby faisal » Tue Jan 09, 2018 1:20 am

Giovanni wrote:Hi,

No progress on this, anyway, PORT_IRQ_HANDLER is no more a naked function so it should work now.

About the static analyzer, I think it can be used regardless if the compiled code works or not. Is there a guide to get started?

Giovanni


I've been using this today: http://clang.llvm.org/get_started.html , but ran out of disk space when attempting to link :D . Will expand the drive of my VM, and try again some time ...

faisal
Posts: 260
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 35 times
Been thanked: 34 times

Re: Clang/LLVM

Postby faisal » Tue Jan 09, 2018 5:01 pm

Here's how to get the latest clang version without compiling from sources. I'm having some trouble expanding the drive on my VM, so I went ahead with this. I've tried it on some PC applications so far and it works. I haven't tried targeting embedded yet ..

https://blog.kowalczyk.info/article/k/h ... l-wsl.html

User avatar
Giovanni
Site Admin
Posts: 12950
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 733 times
Been thanked: 609 times
Contact:

Re: Clang/LLVM

Postby Giovanni » Tue Jan 09, 2018 5:03 pm

Thanks, I could give it a try over weekend.

Giovanni

faisal
Posts: 260
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 35 times
Been thanked: 34 times

Re: Clang/LLVM

Postby faisal » Sun May 27, 2018 5:02 am

Have anyone been able to give Clang/LLVM a try yet? I'm looking forward to being able to use the various clang tools out there (static analyzer, tidy, formatter, etc ..).

apmorton
Posts: 36
Joined: Fri Sep 29, 2017 10:26 am
Been thanked: 16 times

Re: Clang/LLVM

Postby apmorton » Sun May 27, 2018 12:32 pm

clang will build chibios and pretty much most any general code that will build in modern GCC compilers.

For the record, at least for ARM, clang is not generating better code than gcc-arm-none-eabi. In most cases it is reported to be on par, and in others it is worse.

That being said, I think the main benefit to clang is, as faisal mentioned, the static analyzer, tidy, formatter, etc.
Those tools can be used already with varying degrees of fiddling.

To use clang-format on its own (without automatic support from say an IDE plugin) you can effectively run the tool manually from a shell script - the command line flags are fairly intuitive.

To use clang-tidy is a bit more involved, since you need to actually get your code to compile with clang, but it can be done.

I continue to compile my code with gcc in the end, but leverage tools from clang where possible.


Return to “Development and Feedback”

Who is online

Users browsing this forum: No registered users and 5 guests