[cfe-dev] Clang Cross Compiler - I'm almost there!

David Mirabito david.mirabito at gmail.com
Wed Aug 15 01:26:14 PDT 2012


Hello List,

I know there's been much conversations about Clang and building for ARM recently, and as far as I can tell I won't be repeating anything already on the list. I'm really close now :)

So I am interested in using Clang to build for our own RTOS-like environment where today we use an arm-none-eabi-* toolchain from codesourcery/mentor. My understanding is that this comes with a generic newlib implementation (hence 'none' in the triple), which boils down to a few fundamental functions (sbrk, write, exit, ...) which are implemented in a os-specific lib which is pulled in to all apps via the LD script. This works just fine.

So I placed a symlink in 
	/home/davidm/bin/arm-2009q/bin/arm-none-eabi-clang 
(next to arm-none-eabi-gcc & co.) pointing to 
	/home/davidm/myinstall/bin/clang 
and set up my PATH appropriately.

(I've unpacked the codesourcery tarball into ~/bin, hence the two bins in the toolchain path)

This kind of works, in that I can build ARM ELFs for the OS which work just by replacing gcc with clang in one appropriately prefix'd place in my makefile

However some corner cases (like using assert()) indicated that incorrect headers were being pulled in, and it just so happened that my linux system headers matched the newlib definitions well enough (for the simple uses in my codebase) that there were no [obvious] issues. Assert.h breaks this, and honestly I'm surprised it got as far as it did :)

So I experimented with -sysroot and strace'd some invocations. With --sysroot, it seems that arm-none-eabi-clang always looks in  <sysroot>/usr/include and <sysroot>/usr/local/include for the headers and then barfs when stdio.h is not found. 

For me, it seems clang should be looking at  /home/davidm/bin/arm-2009q/arm-none-eabi/include/stdio.h, i.e:
	$ arm-none-eabi-gcc -print-sysroot
	/home/davidm/bin/arm-2009q/bin/../arm-none-eabi

So I see two potential solutions:
	* Clang  knows to look in <compiler_invocation_path>/../<triple>/include  (is this a standard location, or a codesourery piece of magic?)
	* Clang looks in non 'usr' paths based on <sysroot>

Could/should Clang be doing something like this, or am I misconfigured?

If not, I could probably kludge various Makefiles with -isysroot, -I and friends to make it work,  but it wouldn't be ideal. (drop-in replacements ease adoption).

This is with SVN tip, as of yesterday - configured, built (make) and installed with nothing special (other than setting release+asserts, c,c++,obj-c only, and the install prefix)

Thanks,
David M



More information about the cfe-dev mailing list