Sandeep K Chaudhary
2014-May-27 21:04 UTC
[LLVMdev] Getting LLVM bit-code for programs using a couple of libraries
Thank you so much for the reply, Tim ! I have some follow up questions (in the inline replies), it would be great if you can answer those. On Tue, May 27, 2014 at 1:36 PM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi Sandeep, > > On 27 May 2014 02:58, Sandeep K Chaudhary <babbusandy2006 at gmail.com> wrote: >> My aim is to get the bitcode for these programs but if I try to >> generate the bitcode with -emit-llvm option, it produces linking >> issues as follows : (also at - http://pastebin.com/zkmL2SAH) > > You shouldn't really expect "-emit-llvm" to work well with an existing > build system. That flag means the normal .o files produced by clang > will be LLVM bitcode *instead* of ELF (or whatever). This happens to > be the norm with "-flto" compilations, but that needs a compatible > linker and really it needs clang to know that's what it's doing (i.e. > -flto at *all* stages of compilation).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?> > 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?> > Mostly I find I want it just for one file occasionally. So I just > copy/paste the command-line and add -emit-llvm manually (usually with > "-S -o-" because I want to see it *now*).Yeah, getting the bit-code for just one file is straight forward as you mentioned. :)> > Cheers. > > Tim.-- Thanks and regards, Sandeep K Chaudhary.
Tim Northover
2014-May-28 06:07 UTC
[LLVMdev] Getting LLVM bit-code for programs using a couple of libraries
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.
Sandeep K Chaudhary
2014-May-29 18:05 UTC
[LLVMdev] Getting LLVM bit-code for programs using a couple of libraries
Hi Tim, Thanks a lot for the replies, and the clarification ! I can now try these things. Thanks and regards, Sandeep. On Wed, May 28, 2014 at 2:07 AM, Tim Northover <t.p.northover at gmail.com>wrote:> 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. >-- Thanks and regards, Sandeep K Chaudhary. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140529/c0e39cbd/attachment.html>