[LLVMdev] Using LLVM with clang for a homebrew kernel

585 views
Skip to first unread message

Andreas Galauner

unread,
Apr 7, 2010, 8:07:12 PM4/7/10
to llv...@cs.uiuc.edu
Hello everybody,
I'm currently developing my own small operating system as a hobby
project in my free time.
Until now, I'm using gcc and the binutils to compile my C++ code.

I want to try something new and try to use llvm with clang as a C(++)
frontend as a compiler.
Unfortunately I couldn't find any information about how I can use clang
and llvm in a freestanding environment without a libc, so I thought
about asking on this mailing list. I hope this is the right place for
such things.

When using gcc, I just added "-nostdlib -nostdinc -fno-builtin
-ffreestanding" to the parameters and everythin was fine. How can I do
that with llvm?

The next thing is the architecture. I'm currently writing code for i686,
but there will be support for ia64 and arm in the future. Regardless of
the host platform, I need to cross compile my binaries for a given
architecture. How can I specify that? With gcc I needed to create a
complete cross compiling toolchain (target i686-elf for example) which
shouldn't be necessary with llvm since I can just translate the bitcode
to any native architecture I want. But how can I select it?
Another thing inside the target string (this i686-elf thingy) is the
binary format. I though about using Mach-O instead of ELF and llvm seems
to support that, since it created perfect Mach-O files when I tested it
with a hello world on my Mac OS. Where can I set this output format?

Can somebody push me into the right direction or towards the right
documentation about this?

Thanks,
Andreas Galauner
_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Dan Gohman

unread,
Apr 7, 2010, 9:05:56 PM4/7/10
to Andreas Galauner, llv...@cs.uiuc.edu
On Apr 7, 2010, at 5:07 PM, Andreas Galauner wrote:
>
> shouldn't be necessary with llvm since I can just translate the bitcode
> to any native architecture

http://llvm.org/docs/FAQ.html#platformindependent

Dan

Jochen Wilhelmy

unread,
Apr 8, 2010, 9:27:20 AM4/8/10
to llv...@cs.uiuc.edu
Hi!

In the llvm-doc is the following:

Also, since many platforms define their ABIs in terms of C, and since
LLVM is lower-level than C, front-ends currently must emit
platform-specific IR in order to have the result conform to the platform
ABI.

Can you give an example for this except system calls (which e.g. on
windows use
a different calling convention)?
If you write your own operating system then how does llvm-IR depend on
the ABI?

-Jochen

David Greene

unread,
Apr 8, 2010, 10:55:46 AM4/8/10
to llv...@cs.uiuc.edu
On Thursday 08 April 2010 08:27:20 Jochen Wilhelmy wrote:
> Hi!
>
> In the llvm-doc is the following:
>
> Also, since many platforms define their ABIs in terms of C, and since
> LLVM is lower-level than C, front-ends currently must emit
> platform-specific IR in order to have the result conform to the platform
> ABI.
>
> Can you give an example for this except system calls (which e.g. on
> windows use
> a different calling convention)?
> If you write your own operating system then how does llvm-IR depend on
> the ABI?

varargs is the poster boy. Right now llvm proper only has support for
some pieces of varargs translation on x86_64. Frontends handle the bulk of
the work.

I hope to add some more code in this area relatively soon.

Of course, anything having to do with Fortran is done completely by
the frontend as there is no standard ABI for that language.

-Dave

and...@galauner.de

unread,
Apr 8, 2010, 7:27:34 PM4/8/10
to Jochen Wilhelmy, llv...@cs.uiuc.edu
It's no problem for me to write platform specific code. In fact I have to.
I also don't bother recompiling my code for another target platform.

The only thing I need is to select the target platform, LLVM should emit
binary code for.
I'm going to place my HAL (so all of the platform dependent stuff in terms
of code written in C(++) and ASM) in some static library that can be linked
with my kernel code, but that's just to put a line between those two layers
for me as a programmer.
The platform specific code is written in C++ and some Assembly. It's the
compiler's job to create correct C(++) code for the platform and mine to
create correct assembler code which conforms to the ABI of my platform.

Currently I don't have much code. It's just a small kernel with some
memory management and half of a scheduler.
I just wanted to play with LLVM a bit and thought about compiling this
code with LLVM instead of GCC. That's all.
I don't even want to use any LLVM Bitcode in it. I just want to use LLVM
as a compiler.

The only reason why I'm asking on this mailing list is that I didn't find
any documentation about how to use LLVM as a standalone cross-compiler in
terms of "compile this code for ARM and put it into a mach-o file, please."

Andreas

On Thu, 08 Apr 2010 15:27:20 +0200, Jochen Wilhelmy <j.wil...@arcor.de>
wrote:
--
Subscription settings: http://groups.google.com/group/llvm-dev/subscribe?hl=en

Tom Prince

unread,
Apr 7, 2010, 10:05:26 PM4/7/10
to Dan Gohman, llv...@cs.uiuc.edu
On Wed, Apr 07, 2010 at 06:05:56PM -0700, Dan Gohman wrote:
> On Apr 7, 2010, at 5:07 PM, Andreas Galauner wrote:
> >
> > shouldn't be necessary with llvm since I can just translate the bitcode
> > to any native architecture
>
> http://llvm.org/docs/FAQ.html#platformindependent

Except that in this case there is no ABI to deal with, so it should be
possible to write code with care such that the generated bitcode is platform
independent.

Tom

Reply all
Reply to author
Forward
0 new messages