[LLVMdev] Using LLVM as cross-compiler to C

Bill Wendling isanbard at gmail.com
Fri Jan 23 13:04:35 PST 2009


On Fri, Jan 23, 2009 at 7:37 AM, Dave Nadler <Dave.Nadler at nadler.com> wrote:
> At 09:03 PM 1/21/2009, John Criswell wrote:
>>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.
>
> Its an bare-metal embedded target, so there is no use of any headers
> other than the C and C++ library functions. As long as the versions
> with LLVM are standards-compliant, no problem, right ?
>
Yes.

>> >> (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.
>
> Sorry I wasn't clear, yes I meant the C++ runtime library.
> Its a two-part question:
> - the compiler internals library (for example, exception handling), and
> - the "standard" library (for example printf)
>
We don't convert libstdc++ or libc into LLVM code. It's linked in
as-is from the system. For exception handling, we create ABI-compliant
code. So it's usable by the normal C++ RTL.

>> >> (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.
>
> Do I understand correctly from above: LLVM provides a version of
> the runtime library, of which some routines are converted to "external"
> calls already ? So, there's already a printf binding to an external ?
> For the standard-C library, my question is:
> - how much of this has already been implemented (mapping to external),
> - how hard will it be to add additional bindings ?
>
> newlib makes it relatively easy by using common IO routines that
> you replace with platform-specific implementations; is there something
> analogous in the LLVM library implementation ? Hope I was more
> clear this time...
>
Not really. LLVM doesn't provide the libc or libstdc++ libraries.
Those are expected to be on your system already. There are some C
calls that LLVM recognizes as standard C functions, and that LLVM can
generate efficient code for. It generates assembly code in these
cases, not a call to an external library. I don't know about "newlib",
but if it's a replacement for the normal libc library, there shouldn't
be a problem with using it.

-bw



More information about the llvm-dev mailing list