[LLVMdev] Compiling whole programs to bitcode

Nick Lewycky nicholas at mxc.ca
Fri Jun 3 21:39:54 PDT 2011


Russell Wallace wrote:
> On Sat, Jun 4, 2011 at 5:21 AM, Charles Davis<cdavis at mymail.mines.edu>  wrote:
>> You can link your bitcode together with glibc's bitcode by using the
>> llvm-link utility. Then you can run DCE over the bitcode with "opt -dce"
>> and cull all the functions you don't need.
>
> Right, that's still a reasonably straightforward solution for C... I
> think what I'm more concerned about is C++, where templates break the
> simple model of source to object to linking. Trying to wrap my head
> around what the pipeline would look like in the C++ case.

Exactly the same as in C. Before we ever get to LLVM IR, the templates 
are instantiated and the names are mangled.

If a program uses a templated function from a C++ library, either the 
C++ library provides an implementation of the template instantiated to 
that type, or else the whole implementation was available in the header 
and ends up in the TU of the program, not the library ((or else you'd 
get a link error when building normally)). Either way, the rest proceeds 
the same as it would in C.

Nick

>
>> But why are you trying to do this at all?
>
> I've got some ideas for automatic detection of bugs in C/C++ code,
> looking into the feasibility of using Clang as a front-end in the hope
> of only having to write a parser for the ASCII version of bitcode
> (dead easy) instead of C (somewhat easy) and C++ (hard).
> _______________________________________________
> 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