Using Clang instead of GCC?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Using Clang instead of GCC?

Post by Owen »

berkus wrote:LLVM bitcode is in essence assembly language. Haven't seen a portable assembly yet.
LLVM bitcode is. However, post preprocessing, [standard] C isn't :P
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Using Clang instead of GCC?

Post by JamesM »

quanganht wrote:What's happening right now is output object files from clang is not recognized by gnu ld

Code: Select all

~clang -c -nostdlib -nodefaultlibs -mcmodel=large Kernel.cpp -o Kernel.o
~nasm -f elf loader.asm -o loader.o
~i586-elf-ld -T link.ld -o Kernel .bin loader.o Kernel.o
Kernel.o: file not recognized: File format not recognized
Edit: Maybe something is wrong with my toolchain. Like JamesM said, I used llc to get an assembly file (Kernel.s) then compile it with gnu as

Code: Select all

as Kernel.s -o Kernel.o
But when I try to link, the same error appears.

Edit2: found it. llc emitted 64-bit asm code. But adding "-march=x86" to llc makes it spit out broken code
Doesn't 'as' normally default to a.out output, not ELF? Run;

Code: Select all

file Kernel.o
and see what you get.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Using Clang instead of GCC?

Post by Solar »

JamesM wrote:Run;

Code: Select all

file Kernel.o
and see what you get.
+ {INF}.

Whenever your toolchain complains about formats, use "file" to figure out what the format in question actually is, instead of guessing...
Every good solution is obvious once you've found it.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Using Clang instead of GCC?

Post by JamesM »

"file" is one of the most useful and seemingly underused utilities in the UNIX operating system.
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

Re: Using Clang instead of GCC?

Post by fronty »

JamesM wrote:Doesn't 'as' normally default to a.out output, not ELF?
Don't know about Linux, but on every system I'm familiar with as outputs same format that is used by other parts of toolchain. ELF that is these days.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Using Clang instead of GCC?

Post by JamesM »

fronty wrote:
JamesM wrote:Doesn't 'as' normally default to a.out output, not ELF?
Don't know about Linux, but on every system I'm familiar with as outputs same format that is used by other parts of toolchain. ELF that is these days.
Just checked, you're quite right.
User avatar
Mohanty
Member
Member
Posts: 28
Joined: Fri Jul 30, 2010 9:15 am
Location: India
Contact:

Re: Using Clang instead of GCC?

Post by Mohanty »

Though Clang and llvm have good documentation, Still it is not well known till now as like GCC. and till now it is not accepted by most user.

so If u find some bug in OS development using Clang then There is no one to help u. So there will be delay in Development.

So In my view it is better to work through GCC. Otherwise Improved version of GCC is also very faster...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Using Clang instead of GCC?

Post by Solar »

SatyaNarayan wrote:so If u find some bug in OS development using Clang then There is no one to help u. So there will be delay in Development.
Good luck getting support from the GCC team if your bug is specific to OS development...
Every good solution is obvious once you've found it.
User avatar
NickJohnson
Member
Member
Posts: 1249
Joined: Tue Mar 24, 2009 8:11 pm
Location: Sunnyvale, California

Re: Using Clang instead of GCC?

Post by NickJohnson »

@SatyaNarayan: I use Clang (compiling directly to x86 machine code; I haven't tried LLVM LTO or anything), and it compiles my whole project just fine. The Clang project seems a lot cleaner than GCC - I wouldn't be surprised if bug reports were processed faster for Clang, despite the fact that not as many people use it. Clang's -O3 is also noticeably faster than GCC's -O3, both for compile time and run time, and most benchmarks confirm that.

If only I could get Gentoo to use it as a system compiler...
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Using Clang instead of GCC?

Post by Love4Boobies »

Thought I'd make a small correction...
JamesM wrote:LLVM isn't as hard-tied to the platform's glibc, so you don't need a cross compiler.
The standard library isn't the reason for which people build GCC cross-compilers. If they don't want to link it in, they can just use -ffree-standing. There are two reasons for building a cross-compiler: (1) the target(s) and (2) the ABI (i.e., any initialization prior to main, calling conventions, etc.).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
fronty
Member
Member
Posts: 188
Joined: Mon Jan 14, 2008 5:53 am
Location: Helsinki

Re: Using Clang instead of GCC?

Post by fronty »

SatyaNarayan wrote:so If u find some bug in OS development using Clang then There is no one to help u. So there will be delay in
Clang has many active developers who will be very willing to fix bugs. There's a big company with paid developers working on it, I think it cares about bugs in clang and llvm, because they have it in production use.
xyzzy
Member
Member
Posts: 391
Joined: Wed Jul 25, 2007 8:45 am
Libera.chat IRC: aejsmith
Location: London, UK
Contact:

Re: Using Clang instead of GCC?

Post by xyzzy »

SatyaNarayan wrote:so If u find some bug in OS development using Clang then There is no one to help u. So there will be delay in Development.
I've reported a couple of Clang bugs before, and had very fast fixes to them.
Post Reply