[LLVMdev] Using LLVM as cross-compiler to C

Bill Wendling isanbard at gmail.com
Wed Jan 21 16:51:28 PST 2009


On Wed, Jan 21, 2009 at 3:40 PM, Dave Nadler <Dave.Nadler at nadler.com> wrote:
> Hi All - Newbie warning... I am developing for a target that does not have
> a functioning C++ environment, and need to use C++. It was suggested that I
> could use LLVM to compile to C (using llc -march=c), then run the resulting
> C-code through the working C-cross-compilation tools. So, some newbie
> questions:
>
> (1) Is this crazy ?

It depends on you definition of "crazy". It will turn it into C code.
However, you'll still need to link in the libstdc++ library.

> (2) What happens to all the C++ RTL ? Is it statically linked as LLVM code,
> then translated back into C ?
> (3) Where does the LLVM RTL come from - newlib ? glibc ? other ?

LLVM doesn't use RTL. It has its own IR.

> (4) Is it manageable to create a small number of intrinsics to allow access
> to the C runtime functions on the target, or is this difficult ? In the
> mailing list archive I saw some unresolved question with warnings about
> type conversions for someone trying this...
>
I'm not sure I understand your question. The program will have a call
to the C runtime functions (like strtof), and those are compiled into
calls in the assembly language. (Of course, the libc library needs to
be linked in to get the executable.) There are a few C runtime calls
that LLVM handles specially -- like memset, memcpy, etc. But it's not
necessary to have *all* C runtime calls be builtins or intrinsics for
LLVM to handle them.

-bw



More information about the llvm-dev mailing list