Build Freertos code using xt-clang

Hi Team,

I am using xt-xcc compiler(from Xtensa) for building FreeRTOS code and it is working fine on our lx6 core platform. But I want to build same code using xt-clang.

Is there any change related to compiler? Or it should be worked straight forward. Because I saw compiler related directories is in (FreeRTOS/Source/portable)


On arm at least you use the GCC port with both clang and GCC. Is xcc compatible with GCC syntax? If so you may be able to build the port you are already using with clang. If not you may have to adapt the xcc port to clang syntax - which should be straight forward for the c code, and require a bit of fiddling if there is assemble code too.

I can able to build code using xt-clang without facing any compilation issue, but binary is not booting well and it crashed from the below code.

__asm__ __volatile__ (
"movi a5,  0x4\n"
"idtlb a5\n"
"iitlb  a5\n"

Even, Source/portable/ThirdParty/XCC/Xtensa directory contains many of the assembly files. I am not much aware about assembly programming. Can you point out what are the assembly code changes required for clang?

If its compiling/assembling then probably no changes are required to the assembly code. The assembly instructions themselves would not have to change, just the syntax used by the assembly directives, such as the following sequence I’ve just looked at in xtensa_context.S:

    .global _xt_context_save
    .type   _xt_context_save,@function
    .align  4

Which looks like valid GCC/Clang code too.

Yes, you are correct, assembly is valid for clang. But, I still something missing in compilation of the code. I am not sure, what compilation flags should be enabled when use clang. Because i am using below compilation flag for xt-xcc and same flags are used for clang.

CSTD = -std=c11 -O2 -Wall -Wextra
CFLAGS = $(CSTD) -mno-coproc -mlongcalls -fno-delete-null-pointer-checks -mno-l32r-flix -mtext-section-literals

Is there any above cflags creating an issue here to boot the code? If so, can you please guide me?
Thanks in advance!!.

I’m not familiar with that port - can you post the compiler errors you are getting? Is your linker script and startup code correct for Clang?

Do you have a bare metal project to start with? I’d suggest to get a project working without FreeRTOS first and then add FreeRTOS.

@aggarg your idea is good. we have tried with bare metal code initially. It was working fine. Now, i am working on huge code. So it is difficult to figure out with clang. same code works fine with XCC.

Are you saying that the bare metal worked fine with clang?

Yes Gaurav. It is working fine. I have resolved the issue in FreeRTOS kernel with clang. Looks like xclib was creating a problem.
Thank you.

Thank you for taking time to report back.