[LLVMdev] Using LLVM as cross-compiler to C

John Criswell criswell at cs.uiuc.edu
Wed Jan 21 18:03:53 PST 2009


Bill Wendling wrote:
> 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.
>   
One additional problem you may have a C header files.  Different
operating systems and C library implementations will implement the same
functions differently, so when cross-compiling, you need to make sure
your compiling against header files that work on your target platform.

>   
>> (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.
>   
I believe he means the C++ Run-Time Library and not GCC's RTL
Intermediate Representation.

Older versions of llvm-gcc compiled libstdc++ to LLVM bitcode and linked
it statically into the LLVM bitcode for your program.  I am not sure
what newer versions of llvm-gcc do.

I do know that libc functions and other system functions are not
compiled into LLVM bitcode.  They are (as Bill described below) either
converted into LLVM intrinsics (like memcpy) or become calls to external
functions (like printf).  After generation to native code, the program
is linked against the system libraries.

-- John T.

>   
>> (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
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>   




More information about the llvm-dev mailing list