Page 1 of 2

clang cross compiler

Posted: Thu Sep 20, 2012 4:03 pm
by kr651129
Has anyone made a howto for this yet? I compiled and tested my clang/llvm cross compiler this afternoon.

Re: clang cross compiler

Posted: Thu Sep 20, 2012 11:57 pm
by Kazinsal
I don't believe so.

Does your cross compiler work? If so, why don't you write a how-to yourself?

Re: clang cross compiler

Posted: Fri Sep 21, 2012 1:27 am
by dozniak

Re: clang cross compiler

Posted: Fri Sep 21, 2012 1:39 am
by JamesM
Clang/LLVM is inherently a cross compiler; you don't need to build it again.

Re: clang cross compiler

Posted: Fri Sep 21, 2012 9:08 am
by Kazinsal
dozniak wrote:http://wiki.osdev.org/LLVM_Cross-Compiler
I stand corrected, thank you. It does seem that the page could use a lot of work (perhaps this is where kr651129 could come in.)
JamesM wrote:Clang/LLVM is inherently a cross compiler; you don't need to build it again.
That's interesting. I've never looked very far into Clang/LLVM, so I assumed it worked more like GCC in terms of portability.

Re: clang cross compiler

Posted: Sat Sep 22, 2012 9:00 am
by JamesM
pitfall wrote:CLang is a native cross-compiler, I've only used it for some cross-compiling tests targeting ARM chips on my x86-64 laptop (don't even remember why, just remember I did it... -_-). For my OS I use an x86-64 GCC cross compiler so I can compile my kernel on my laptop and on my old Pentium 3 running Crunchbang-Linux, using an external drive for storage and two build directories on it, switching just one line in my makefile when switching from one computer to one another. And compiling GCC is an interesting piece of software-learning experience !

As far as I know, you can use -ccc-host-triple <your target output format> option with -march=<your target architecture> to cross-compile with LLVM. It's been a while since I used LLVM/CLang, but I think this'll work with some investigation.

EDIT
----------------------------------------------------------------------------
Here's an example quoted for some obscure mailing lists illustrating what I wrote :

Code: Select all

-march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf
Or since 3.1 you can just shorten this to:

Code: Select all

-target armv7--eabi -mcpu=cortex-a9

Re: clang cross compiler

Posted: Sun Sep 23, 2012 2:58 am
by JamesM
pitfall wrote:Ok I didn't know about this way of shortening the command-line. I'll note it somewhere ;)
-target replaced -ccc-host-triple, I believe either in 3.1 or shortly thereafter.

Re: clang cross compiler

Posted: Fri Oct 05, 2012 2:04 pm
by OSwhatever
The LLVM project download pages are nice enough to provide binaries for those who do not want to spend time compiling the compilers. However, these are provided without any libraries. The question is how to compile the libraries like newlib and libstd++.

Is there any progress compiling these libraries with or any libraries as at all? Do we we just have to use libraries created with GCC?

Re: clang cross compiler

Posted: Fri Oct 05, 2012 4:07 pm
by JamesM
OSwhatever wrote:The LLVM project download pages are nice enough to provide binaries for those who do not want to spend time compiling the compilers. However, these are provided without any libraries. The question is how to compile the libraries like newlib and libstd++.

Is there any progress compiling these libraries with or any libraries as at all? Do we we just have to use libraries created with GCC?
libc++ is a separate project, as is the compiler-rt project (which replaces libgcc). Newlib is a C library and so is nothing to do with the compiler.

Re: clang cross compiler

Posted: Fri Oct 05, 2012 4:28 pm
by OSwhatever
JamesM wrote:libc++ is a separate project, as is the compiler-rt project (which replaces libgcc). Newlib is a C library and so is nothing to do with the compiler.
The build systems of the libraries are usually done for GCC and hacking the configuration can be very tricky. Can you in any way compile these libraries with a pure clang compiler or do you need the GCC front end?

Re: clang cross compiler

Posted: Sat Oct 06, 2012 8:08 am
by Owen
OSwhatever wrote:
JamesM wrote:libc++ is a separate project, as is the compiler-rt project (which replaces libgcc). Newlib is a C library and so is nothing to do with the compiler.
The build systems of the libraries are usually done for GCC and hacking the configuration can be very tricky. Can you in any way compile these libraries with a pure clang compiler or do you need the GCC front end?
libc++ and compiler-rt are both LLVM libraries and use the LLVM build system...

newlib can be built standalone and should just work if you specify CC=clang to configure. That said, newlib is a horrid mess.

Re: clang cross compiler

Posted: Sat Oct 06, 2012 12:29 pm
by OSwhatever
Owen wrote:libc++ and compiler-rt are both LLVM libraries and use the LLVM build system...

newlib can be built standalone and should just work if you specify CC=clang to configure. That said, newlib is a horrid mess.
How easy is it to get libc++ running on your own OS or even compile? Is it lot of work or just in the case of newlib create functions or stubs for a bunch of POSIX calls?

Also one thing I notice is that the llvm-ld linker doesn't support linker script which is quite essential for OS developers. Do you use the GCC linker instead or are there other ways?

Re: clang cross compiler

Posted: Sat Oct 06, 2012 1:49 pm
by Owen
OSwhatever wrote:Also one thing I notice is that the llvm-ld linker doesn't support linker script which is quite essential for OS developers. Do you use the GCC linker instead or are there other ways?
LLVM-ld is for linking bitcode and currently depends upon the system linker.

The linker replacement is lld, which is still immature. In the meantime, use Binutils.

Re: clang cross compiler

Posted: Sat Oct 06, 2012 7:16 pm
by OSwhatever
I managed to compile my kernel with LLVM Clang and I must say it was much easier than I thought it would be. Compiling LLVM is much easier than compiling GCC to begin with, where GCC is just a myriad of configuration options and tinkering. Compling LLVM is pretty much straight forward, you compile it and that's it. Apparently, LLVM clang still needs gcc in order to create object files which I didn't have installed, only the ARM cross compiler and clang couldn't find it without adding a few options.

I'm amazed how little effort there was in order to make clang accept my code even with several what I thought was GCC compiler dependent. Newlib was from a GCC compiled build though.

The OS started up and was running on the first try.

I think I continue with LLVM from here on as it seems like this compiler was quite nice to work with. As I see it this compiler with be choice for many developers in the future.

Re: clang cross compiler

Posted: Sun Oct 07, 2012 1:33 am
by dozniak
OSwhatever wrote:How easy is it to get libc++ running on your own OS or even compile? Is it lot of work or just in the case of newlib create functions or stubs for a bunch of POSIX calls?
Was fairly easy for me. That said, I disabled iostreams and use only parts of libc++ that don't need any syscalls at all.