[llvm-dev] Cross compiling for Baremetal ARM without using GCC

Jonathan Roelofs via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 1 04:48:10 PDT 2017


+clm


On 10/31/17 5:55 PM, Daniel Kang via llvm-dev wrote:
> Dear LLVM developers,
> 
> Hello,
> 
> I’m trying to find a way of cross-compiling my c code against Baremetal 
> Cortex-M device (so target triple will be arm-none-eabi) only using 
> LLVM/Clang, and not using anything from GNU (ld or libc).

Exciting!

> 
> I’m doing this to know which one of LLVM/clang and GCC produces smaller 
> flash image size because saving flash is a big deal in our projects.
> 

I'd be interested to hear about your findings.

 >

snip

> 
> arm-none-eabi toolchain doesn’t contain libatomic, but I need to build 
> compiler_rt using this tool to get the runtime for ARM, so it’s 
> confusing. Or building compiler_rt using arm-none-eabi toolchain is 
> completely wrong idea in the first place.

You could use an existing arm-none-eabi toolchain to build the builtins, 
but it would be better to build it with the just-built clang that you're 
going to build anyway.

> 
> 3) Then I found this mail thread 
> http://lists.llvm.org/pipermail/llvm-dev/2017-August/116134.html which 
> seems very close to the thing I’m trying, but the mail thread is unfinished.
> 
> So, my question is,
> 
> Is there a way of cross-compiling c code against Baremetal Cortex-M 
> device only using LLVM/Clang, and not using anything from GNU (ld or libc)?

Yes. The biggest hurdle at this point is probably going to be weird 
corner cases in lld's linker script support. Other than that, it is 
definitely possible to build & use a full llvm (+ newlib) toolchain that 
supports baremetal arm.

> 
> If so, do I have to build LLVM/Clang source code to get 
> clang_rt.builtins-armv6m.a or libc, libm for ARM?

The notes in that thread you found should get you a working C toolchain. 
Extending that to C++ is where things are "unfinished".


Jon

> 
> If so, the method 2) or 3) above is the right approach? Or are there any 
> other instruction?
> 
> Any advice would be a great help for me.
> 
> Thank you
> 
> Daniel
> 
> 
> This message and any attachments may contain confidential information 
> from Cypress or its subsidiaries. If it has been received in error, 
> please advise the sender and immediately delete this message.
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> 

-- 
Jon Roelofs
jonathan at codesourcery.com
CodeSourcery / Mentor Embedded / Siemens


More information about the llvm-dev mailing list