<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 8, 2018 at 2:59 PM <<a href="mailto:ben_fu1@utexas.edu">ben_fu1@utexas.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_6080464909565280066WordSection1"><p class="MsoNormal">The goal is to create a function call graph with the names of the functions, and the graph should include indirect calls too.</p></div></div></blockquote><div><br></div><div>That's not possible in general - functions being called could come from external code, for example. (dlsym, for instance)</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_6080464909565280066WordSection1"><p class="MsoNormal"> I looked and saw that LLVM supports a metadata type called ‘callees’, but I don’t see that it’s currently being implemented by clang. Will this eventually be used?</p></div></div></blockquote><div><br>Not sure - I guess maybe if there were a constrained set of callees - but that's not true of a polymorphic class hierarchy (there could always be another derived class in some external code - it's not a closed group/set/collection/thing).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div class="m_6080464909565280066WordSection1"><p class="MsoNormal"><u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal">Ben<u></u><u></u></p><p class="MsoNormal"><u></u> <u></u></p><p class="MsoNormal"><b>From:</b> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> <br><b>Sent:</b> Friday, June 8, 2018 1:06 PM<br><b>To:</b> <a href="mailto:ben_fu1@utexas.edu" target="_blank">ben_fu1@utexas.edu</a><br><b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><b>Subject:</b> Re: [llvm-dev] Retrieving the name of a indirect virtual method call in LLVM pass<u></u><u></u></p></div></div><div lang="EN-US" link="blue" vlink="purple"><div class="m_6080464909565280066WordSection1"><p class="MsoNormal"><u></u> <u></u></p><div><p class="MsoNormal">Sounds like maybe you're trying to do something at a level where it's not going to be practical - what's your overall goal?<br><br>But no, at the LLVM IR level you can't get the name of a virtual function being called - as you've seen, it's a dynamic call through a table of function pointers & at LLVM's level, those functions could have any names (or none at all - or at least none that makes sense in this translation unit/module because it's a local symbol in some other module).<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal">On Thu, Jun 7, 2018 at 9:40 AM via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p></div><blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in"><div><div><p class="MsoNormal">Hi,<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I have been implementing a CallGraphSCCPass that analyzes each function invocation. Direct calls are not a problem, but currently I also need to retrieve the name of the function in the case of virtual method calls. For example:<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">struct A {<u></u><u></u></p><p class="MsoNormal">    A() {}<u></u><u></u></p><p class="MsoNormal">    virtual foo() {}<u></u><u></u></p><p class="MsoNormal">    virtual ~A() {}<u></u><u></u></p><p class="MsoNormal">};<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">int main() {<u></u><u></u></p><p class="MsoNormal">    A* a = new A;<u></u><u></u></p><p class="MsoNormal">    a->foo();<u></u><u></u></p><p class="MsoNormal">}<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">In the pass, I can determine the name of the indirect call by using CallInst::getCalledValue(), but that doesn’t give any information on the actual method that is being called, which should be foo(). The only “name” I can get is the type of the class, in which this case is class.A.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Is there any way I can get the name of the virtual method (foo) that is being invoked? It isn’t in the bitcode except for when it is defined. I tried taking a look at the whole-program-devirt source but can’t find where they are actually finding the names of the functions when building the virtual tables for each class.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">I would greatly appreciate any help on this and if it is possible at all.<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Thanks,<u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p><p class="MsoNormal">Ben Fu <u></u><u></u></p><p class="MsoNormal"> <u></u><u></u></p></div></div><p class="MsoNormal">_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><u></u><u></u></p></blockquote></div></div></div></blockquote></div></div>