LLVM IR for a large C project

845 Views Asked by At

I'm new to LLVM, clang etc. My primary need is to convert C code to LLVM IR (.ll) then parse this to a assembly-like language. For this I was till now working with small length c codes (single file) and to get these converted to LLVM IR I used -

$ clang -emit-llvm -S multiply.c -o multiply.ll

To do this conversion with a large C project, I tried gllvm - https://github.com/SRI-CSL/gllvm and it was really easy & convenient but I am facing this issue with it - https://github.com/PLSysSec/sys/issues/16
which basically a bug in the llvm-hs repo essentially asking me to pull the commit which has the fix and build it. I'm trying to avoid doing this (is this a better way ?)

So I moved onto another solution of using the gold linker - http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html

I am now stuck on using this gold plugin to get .bc or .ll files - I want to use this gold plugin to convert a large C project into .ll or .bc files - but the steps only show how to use the linker to get optimised executable. Are there any command line options to only convert it till .bc files ?

Any help would be appreciated.

1

There are 1 best solutions below

0
On

The llvm-link tool combines multiple .bc files into a single .bc. It does not support native object files at all, nor does it work well with normal linker flags (it does not pretend to be ld).

If you do want changes to the llvm IR due to your native libraries on the system, the gold plugin to llvm also supports a emit-llvm flag. Run a clang or gcc link with -Wl,-plugin-opt=emit-llvm when linking with gold.