[LLVMdev] Compile a project into LLVM Bitcode

John Criswell criswell at illinois.edu
Fri May 20 08:39:29 PDT 2011


On 5/20/11 10:25 AM, Julien Henry wrote:
>> You can use Clang to compile source to bitcode:
>>
>> clang -c hello.c -emit-llvm -o hello.bc
>>
> Yes.
> My problem is to automatically create .bc files with ./configure&&
> make. Ideally, when compiling a project like "grep", I'd like to obtain
> a single .bc file containing all the project's functions, instead of the
> grep binary executable.

There are two approaches that you can take:

1) You can modify libLTO so that it saves into a file the entire bitcode 
that it analyzes.  By default, it just creates the bitcode file in 
memory, optimizes it, and then generates native code.  A small addition 
can get it to save its results right before it generates native code.

2) If you're doing whole-program analysis or transformation, you can 
build your analysis/transform directly into libLTO.

-- John T.
> I already tried things like
> CC=clang CFLAGS=-emit-llvm ./configure
>
> But the ./configure fails (indeed, .bc files are not executable, so
> configure says the C compiler doesn't work)
>
> checking for a BSD-compatible install... /usr/bin/install -c
> checking whether build environment is sane... yes
> checking for a thread-safe mkdir -p... /bin/mkdir -p
> checking for gawk... gawk
> checking whether make sets $(MAKE)... yes
> checking build system type... i686-pc-linux-gnu
> checking host system type... i686-pc-linux-gnu
> checking for gawk... (cached) gawk
> checking for gcc... clang
> checking whether the C compiler works... no
> configure: error: in `/local/jhenry/examples/grep-2.8':
> configure: error: C compiler cannot create executables
> See `config.log' for more details
> _______________________________________________
> 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