[cfe-users] Cross compiling a bare metal Cortex M4 Application with LTO

Dan Čermák via cfe-users cfe-users at lists.llvm.org
Thu Jan 4 02:11:43 PST 2018


Hello everyone,

I am developing bare metal applications on a Cortex M4 CPU mostly with
gcc but wanted to also use clang, as I do for all my programs targeting
an OS-environment.

After a lot of fiddling around I finally managed to get clang to
successfully compile & link my projects. I have achieved that by using
my ordinary cross compiler (arm-none-eabi-gcc):
- provide clang with all the include paths of arm-none-eabi-gcc
- setting --sysroot to the installation root of arm-none-eabi-gcc
- set the gcc name using the option '-ccc-gcc-name' to
  arm-none-eabi-gcc, otherwise clang would try to link the application
  using the ordinary gcc (which obviously won't work)

This works pretty well, but has one big downside: link time optimization
does not work, as gcc is linking the object files and not clang. (And it
has a "cosmetic" downside of relying on the gcc cross compiler.)

Does anyone know how I could setup a "pure" clang build environment,
that would not have to rely on the gcc cross compiler? I guess I would
have to also build the libc for arm-none-eabi for that and tell clang
about the ARM headers, but I have little experience with that (and I did
not find a lot of useful information as most embedded Devs seem to use
the vendor supplied IDEs with the bundled compilers on Windows instead).


Thanks in advance,

Dan



More information about the cfe-users mailing list