clang cross compiler

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
kr651129
Posts: 18
Joined: Fri Dec 02, 2011 11:02 pm

clang cross compiler

Post by kr651129 »

Has anyone made a howto for this yet? I compiled and tested my clang/llvm cross compiler this afternoon.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: clang cross compiler

Post by Kazinsal »

I don't believe so.

Does your cross compiler work? If so, why don't you write a how-to yourself?
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: clang cross compiler

Post by dozniak »

Learn to read.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: clang cross compiler

Post by JamesM »

Clang/LLVM is inherently a cross compiler; you don't need to build it again.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: clang cross compiler

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: clang cross compiler

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: clang cross compiler

Post 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.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: clang cross compiler

Post 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?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: clang cross compiler

Post 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.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: clang cross compiler

Post 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?
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: clang cross compiler

Post 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.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: clang cross compiler

Post 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?
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: clang cross compiler

Post 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.
OSwhatever
Member
Member
Posts: 595
Joined: Mon Jul 05, 2010 4:15 pm

Re: clang cross compiler

Post 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.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: clang cross compiler

Post 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.
Learn to read.
Post Reply