<div dir="ltr"><div>Hi Ketan,</div><div><br></div><div>Using LLVM gold plugin is a fast way to generate a whole-program.bc after make.</div><div><br></div><div>Here is a great article guiding you how to do this:</div><div><br></div><div>(Compiling autotooled projects to LLVM bitcode )</div><div><a href="http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html">http://gbalats.github.io/2015/12/10/compiling-autotooled-projects-to-LLVM-bitcode.html</a><br></div><div><br></div><div><div style="font-size:12.8px">The git repo for binutils doesn't work, but you can grab a version here: <a href="http://ftp.gnu.org/gnu/binutils/" target="_blank">http://ftp.gnu.org/gnu/<wbr>binutils/</a> I believe I used 2.26, but latest 2.27 should also work. </div><div style="font-size:12.8px">When building binutils make sure to follow <a href="http://llvm.org/docs/GoldPlugin.html" target="_blank">http://llvm.org/docs/<wbr>GoldPlugin.html</a> for configuring and building. Once this is complete you will have the binutils gold linker installed. </div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Some key operations are as follows:</div><div><br></div><div><pre class="gmail-highlight" style="box-sizing:border-box;overflow-x:scroll;overflow-y:auto;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;padding:8px 12px;margin-top:0px;margin-bottom:15px;line-height:1.42857;color:rgb(51,51,51);word-break:break-all;word-wrap:break-word;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;border:1px solid rgb(232,232,232);border-radius:3px"><code style="box-sizing:border-box;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;padding:0px;color:inherit;background-color:transparent;border-radius:0px;border:0px;white-space:pre-wrap"><span class="gmail-gp" style="box-sizing:border-box;color:rgb(85,85,85)">$ </span><span class="gmail-nb" style="box-sizing:border-box;color:rgb(0,134,179)">export </span><span class="gmail-nv" style="box-sizing:border-box;color:teal">CC</span><span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span>clang
<span class="gmail-gp" style="box-sizing:border-box;color:rgb(85,85,85)">$ </span><span class="gmail-nb" style="box-sizing:border-box;color:rgb(0,134,179)">export </span><span class="gmail-nv" style="box-sizing:border-box;color:teal">CXX</span><span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span>clang++
<span class="gmail-gp" style="box-sizing:border-box;color:rgb(85,85,85)">$ </span><span class="gmail-nb" style="box-sizing:border-box;color:rgb(0,134,179)">export </span><span class="gmail-nv" style="box-sizing:border-box;color:teal">RANLIB</span><span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span>llvm-ranlib
<span class="gmail-gp" style="box-sizing:border-box;color:rgb(85,85,85)">$ </span><span class="gmail-nb" style="box-sizing:border-box;color:rgb(0,134,179)">export </span><span class="gmail-nv" style="box-sizing:border-box;color:teal">CFLAGS</span><span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span><span class="gmail-s2" style="box-sizing:border-box;color:rgb(221,17,68)">" -flto -std=gnu99 "</span>
<span class="gmail-gp" style="box-sizing:border-box;color:rgb(85,85,85)">$ </span><span class="gmail-nb" style="box-sizing:border-box;color:rgb(0,134,179)">export </span><span class="gmail-nv" style="box-sizing:border-box;color:teal">LDFLAGS</span><span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span><span class="gmail-s2" style="box-sizing:border-box;color:rgb(221,17,68)">" -flto -fuse-ld=gold "</span>
<span class="gmail-gp" style="box-sizing:border-box;color:rgb(85,85,85)">$ </span>./configure</code></pre></div><div class="gmail_extra"><pre class="gmail-highlight" style="box-sizing:border-box;overflow-x:scroll;overflow-y:auto;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;padding:8px 12px;margin-top:0px;margin-bottom:15px;line-height:1.42857;color:rgb(51,51,51);word-break:break-all;word-wrap:break-word;background-image:initial;background-position:initial;background-size:initial;background-repeat:initial;background-origin:initial;background-clip:initial;border:1px solid rgb(232,232,232);border-radius:3px"><code style="box-sizing:border-box;font-family:Menlo,Monaco,Consolas,"Courier New",monospace;padding:0px;color:inherit;background-color:transparent;border-radius:0px;border:0px;white-space:pre-wrap"><span class="gmail-nv" style="box-sizing:border-box;color:teal">LDFLAGS</span> <span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span>  -flto -fuse-ld<span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span>gold -Wl,-plugin-opt<span class="gmail-o" style="box-sizing:border-box;font-weight:bold">=</span>emit-llvm</code></pre></div><div class="gmail_extra">Usually I don't change .configure too much, instead, I will change these options in Makefile because I clearly know what I am doing.</div><div class="gmail_extra"><br></div><div class="gmail_extra">You can also change clang source code to enable "also-emit-llvm", which can generate .bc together with the executable. </div><div class="gmail_extra"><br></div><div class="gmail_extra">LDFLAGS = -flto -fuse-ld=gold -Wl,-plugin-opt=also-emit-llvm<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Good Luck!</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 13, 2017 at 6:57 AM, Ketan Patil via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="m_6774559835563402862gmail-post-text">

<p>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.    </p>

<p>To be more specific, I am working with binutils 2.26     <a href="https://ftp.gnu.org/gnu/binutils/binutils-2.26.tar.gz" rel="nofollow noreferrer" target="_blank">https://ftp.gnu.org/gnu/<wbr>binutils/binutils-2.26.tar.gz</a> </p>

<p>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.     </p>

<p>I want a call graph which will include all such functions. </p>

<p>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 <strong>configure file</strong> or <strong>makefile</strong> without disturbing any dependencies. </p>

<p>Any help is highly appreciated.</p>
    </div><div><div class="m_6774559835563402862gmail_signature"><div dir="ltr"><span>Thanks and regards<span class="HOEnZb"><font color="#888888"><div>-Ketan Patil</div></font></span></span></div></div></div>
</div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>