OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 9:42 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: clang cross compiler
PostPosted: Thu Sep 20, 2012 4:03 pm 
Offline

Joined: Fri Dec 02, 2011 11:02 pm
Posts: 18
Has anyone made a howto for this yet? I compiled and tested my clang/llvm cross compiler this afternoon.


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Thu Sep 20, 2012 11:57 pm 
Offline
Member
Member
User avatar

Joined: Wed Jul 13, 2011 7:38 pm
Posts: 558
I don't believe so.

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


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Fri Sep 21, 2012 1:27 am 
Offline
Member
Member
User avatar

Joined: Thu Jul 12, 2012 7:29 am
Posts: 723
Location: Tallinn, Estonia
http://wiki.osdev.org/LLVM_Cross-Compiler

_________________
Learn to read.


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Fri Sep 21, 2012 1:39 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
Clang/LLVM is inherently a cross compiler; you don't need to build it again.

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Fri Sep 21, 2012 9:08 am 
Offline
Member
Member
User avatar

Joined: Wed Jul 13, 2011 7:38 pm
Posts: 558
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.


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sat Sep 22, 2012 9:00 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
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:
-march=armv7-a -mfloat-abi=soft -ccc-host-triple arm-elf


Or since 3.1 you can just shorten this to:

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

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sun Sep 23, 2012 2:58 am 
Offline
Member
Member
User avatar

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

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Fri Oct 05, 2012 2:04 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Fri Oct 05, 2012 4:07 pm 
Offline
Member
Member
User avatar

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

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Fri Oct 05, 2012 4:28 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sat Oct 06, 2012 8:08 am 
Offline
Member
Member
User avatar

Joined: Fri Jun 13, 2008 3:21 pm
Posts: 1700
Location: Cambridge, United Kingdom
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.


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sat Oct 06, 2012 12:29 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sat Oct 06, 2012 1:49 pm 
Offline
Member
Member
User avatar

Joined: Fri Jun 13, 2008 3:21 pm
Posts: 1700
Location: Cambridge, United Kingdom
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.


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sat Oct 06, 2012 7:16 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: clang cross compiler
PostPosted: Sun Oct 07, 2012 1:33 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 27 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group