[llvm-dev] How do I generate a combined .ll file from makefile or configure file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[llvm-dev] How do I generate a combined .ll file from makefile or configure file?

George Karpenkov via llvm-dev

I wrote a module pass to generate a call graph. I want to generate call graph which would consist of all the functions like the functions in the user code as well as the functions in the libraries.

To be more specific, I am working with binutils 2.26 https://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz

I want to generate the call graph for 'objdump'. The code of the objdump would call some functions in the library 'libiberty' these called functions in the library can call more internal functions inside the library.

I want a call graph which will include all such functions.

One way to do is that I can emit llvm code for all the files in the library as well as the user code in separate .ll files. And then finally combine them using llvm-link. But this may fail if there are dependencies here and there. So can I do this systematically by making some changes in configure file or makefile without disturbing any dependencies.

Any help is highly appreciated.

Thanks and regards
-Ketan Patil

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] How do I generate a combined .ll file from makefile or configure file?

George Karpenkov via llvm-dev
On 13 August 2017 at 11:57, Ketan Patil via llvm-dev
<[hidden email]> wrote:

> I wrote a module pass to generate a call graph. I want to generate call
> graph which would consist of all the functions like the functions in the
> user code as well as the functions in the libraries.
>
> To be more specific, I am working with binutils 2.26
> https://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz
>
> I want to generate the call graph for 'objdump'. The code of the objdump
> would call some functions in the library 'libiberty' these called functions
> in the library can call more internal functions inside the library.
>
> I want a call graph which will include all such functions.
>
> One way to do is that I can emit llvm code for all the files in the library
> as well as the user code in separate .ll files. And then finally combine
> them using llvm-link. But this may fail if there are dependencies here and
> there. So can I do this systematically by making some changes in configure
> file or makefile without disturbing any dependencies.
>
> Any help is highly appreciated.

You could try using whole-program-llvm (wllvm) [1]. It's a nifty
little hack that will let you get the LLVM bitcode of an application
fully linked
(provided you build the program's libraries as static libraries). You
just use it as a drop-in replacement for your C and/or
C++ compiler.

What wllvm does is it invokes clang twice. Once to build native code
and once to emit LLVM bitcode. The motivation for building native
code too is that some projects need to run freshly built tools to
successfully complete the build.

When the native object files are built a special section is added that
contains the path the corresponding LLVM bitcode. When the native
system
linker links object files together to build executables it
concatenates all the special sections together. The result is each
built executable contains
the paths to all the corresponding LLVM bitcode files that were used
to build the executable. The `extract-bc` tool which comes with wllvm
scans
the special section in an executable and calls `llvm-link` on all LLVM
bitcode files to give you the linked LLVM bitcode file.


[1] https://github.com/travitch/whole-program-llvm

HTH,
Dan.
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [llvm-dev] How do I generate a combined .ll file from makefile or configure file?

George Karpenkov via llvm-dev
In reply to this post by George Karpenkov via llvm-dev
Hi Ketan,

Using LLVM gold plugin is a fast way to generate a whole-program.bc after make.

Here is a great article guiding you how to do this:

(Compiling autotooled projects to LLVM bitcode )

The git repo for binutils doesn't work, but you can grab a version here: http://ftp.gnu.org/gnu/binutils/ I believe I used 2.26, but latest 2.27 should also work. 
When building binutils make sure to follow http://llvm.org/docs/GoldPlugin.html for configuring and building. Once this is complete you will have the binutils gold linker installed. 

Some key operations are as follows:

$ export CC=clang
$ export CXX=clang++
$ export RANLIB=llvm-ranlib
$ export CFLAGS=" -flto -std=gnu99 "
$ export LDFLAGS=" -flto -fuse-ld=gold "
$ ./configure
LDFLAGS =  -flto -fuse-ld=gold -Wl,-plugin-opt=emit-llvm
Usually I don't change .configure too much, instead, I will change these options in Makefile because I clearly know what I am doing.

You can also change clang source code to enable "also-emit-llvm", which can generate .bc together with the executable. 

LDFLAGS = -flto -fuse-ld=gold -Wl,-plugin-opt=also-emit-llvm

Good Luck!

On Sun, Aug 13, 2017 at 6:57 AM, Ketan Patil via llvm-dev <[hidden email]> wrote:

I wrote a module pass to generate a call graph. I want to generate call graph which would consist of all the functions like the functions in the user code as well as the functions in the libraries.

To be more specific, I am working with binutils 2.26 https://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz

I want to generate the call graph for 'objdump'. The code of the objdump would call some functions in the library 'libiberty' these called functions in the library can call more internal functions inside the library.

I want a call graph which will include all such functions.

One way to do is that I can emit llvm code for all the files in the library as well as the user code in separate .ll files. And then finally combine them using llvm-link. But this may fail if there are dependencies here and there. So can I do this systematically by making some changes in configure file or makefile without disturbing any dependencies.

Any help is highly appreciated.

Thanks and regards
-Ketan Patil

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev



_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Loading...