[LLVMdev] Getting LLVM bit-code for programs using a couple of libraries

Tim Northover t.p.northover at gmail.com
Tue May 27 23:07:06 PDT 2014


Hi Sandeep,

> Does it mean that I need to give -flto option for compilation while
> building the libraries that I am using i.e. lttng-ust and libdl?

No, you can mix and match lto and non-lto files & libraries.

>> If you just want the LLVM IR for a reasonably large project, you
>> should probably setup a parallel set of "build" steps that produce the
>> IR but aren't involved in the actual compilation.
>
> So, does it mean adding -flto option in each build step? Can you
> please explain this a bit? I mean - how to set up such a parallel set
> of builds in my case?

You need a compatible linker (which means ld.gold or a recent ld.bfd,
I don't know the version off the top of my head). You then need to add
"-flto" to both compile and link steps. With luck, that will just
work. For example, with a trivial single file:

$ clang -c -O3 -flto hello.c
$ clang -flto hello.o -ohello

But I realise I didn't say what -flto was: it's link-time
optimization. Generally the code you get out is better, but it incurs
significant memory and build time overheads. It may not be practical,
depending on the size of your project.

Cheers.

Tim.



More information about the llvm-dev mailing list