<div dir="ltr"><div>Thanks, much appreciated!<br><br></div>-David<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 12, 2014 at 12:14 PM, Hans Wennborg <span dir="ltr"><<a href="mailto:hans@chromium.org" target="_blank">hans@chromium.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Wed, Jun 11, 2014 at 1:45 PM, David Glanzman <<a href="mailto:davidglanzman@yahoo.com">davidglanzman@yahoo.com</a>> wrote:<br>

> Hello all,<br>
><br>
> I'm getting started on a project using LLVM's opt tool to do static<br>
> analysis, printing call graphs and such.  When compiling C programs to IR<br>
> (and eventually to call graphs), function names remain the same (main,<br>
> function1, function2 etc.), but when compiling the same program as C++, the<br>
> function names often have cruft added to them (_Z9function1v, _Z9function2v<br>
> etc.) which doesn't make for a very pretty graph.<br>
><br>
> Why are these extra characters added when going to IR from C++, but not C?<br>
<br>
</div>It's called name mangling. See<br>
<a href="http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B" target="_blank">http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B</a><br>
<div class=""><br>
> I'm interested in what they're for and if there's anyway to avoid them for<br>
> the sake of making nice graphs.<br>
<br>
</div>If you can declare your functions as 'extern "c"', they will not get<br>
mangled. But this won't work for member functions, namespaces, etc.<br>
<br>
If you just want nicer names for your graph, you can run the names<br>
through a demangler. For example:<br>
<br>
$ echo _Z9function1v | c++filt<br>
function1()<br>
<br>
<br>
Thanks,<br>
Hans<br>
</blockquote></div><br></div>