David Glanzman
2014-Jun-11 20:45 UTC
[LLVMdev] How do clang & clang++ choose function names for LLVM IR?
Hello all, I'm getting started on a project using LLVM's opt tool to do static analysis, printing call graphs and such. When compiling C programs to IR (and eventually to call graphs), function names remain the same (main, function1, function2 etc.), but when compiling the same program as C++, the function names often have cruft added to them (_Z9function1v, _Z9function2v etc.) which doesn't make for a very pretty graph. Why are these extra characters added when going to IR from C++, but not C? I'm interested in what they're for and if there's anyway to avoid them for the sake of making nice graphs. Thanks, David Glanzman -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140611/9af8f589/attachment.html>
Alex L
2014-Jun-12 16:02 UTC
[LLVMdev] How do clang & clang++ choose function names for LLVM IR?
Hi David, Function names for C++ have to be mangled for various reasons - see http://en.wikipedia.org/wiki/Name_mangling for more details. You can use a function called __cxa_demangle from libcxxabi to get the demangled function name. 2014-06-11 13:45 GMT-07:00 David Glanzman <davidglanzman at yahoo.com>:> Hello all, > > I'm getting started on a project using LLVM's opt tool to do static > analysis, printing call graphs and such. When compiling C programs to IR > (and eventually to call graphs), function names remain the same (main, > function1, function2 etc.), but when compiling the same program as C++, the > function names often have cruft added to them (_Z9function1v, _Z9function2v > etc.) which doesn't make for a very pretty graph. > > Why are these extra characters added when going to IR from C++, but not > C? I'm interested in what they're for and if there's anyway to avoid them > for the sake of making nice graphs. > > Thanks, > David Glanzman > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140612/9e67b43f/attachment.html>
Hans Wennborg
2014-Jun-12 16:14 UTC
[LLVMdev] How do clang & clang++ choose function names for LLVM IR?
On Wed, Jun 11, 2014 at 1:45 PM, David Glanzman <davidglanzman at yahoo.com> wrote:> Hello all, > > I'm getting started on a project using LLVM's opt tool to do static > analysis, printing call graphs and such. When compiling C programs to IR > (and eventually to call graphs), function names remain the same (main, > function1, function2 etc.), but when compiling the same program as C++, the > function names often have cruft added to them (_Z9function1v, _Z9function2v > etc.) which doesn't make for a very pretty graph. > > Why are these extra characters added when going to IR from C++, but not C?It's called name mangling. See http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B> I'm interested in what they're for and if there's anyway to avoid them for > the sake of making nice graphs.If you can declare your functions as 'extern "c"', they will not get mangled. But this won't work for member functions, namespaces, etc. If you just want nicer names for your graph, you can run the names through a demangler. For example: $ echo _Z9function1v | c++filt function1() Thanks, Hans
David Glanzman
2014-Jun-12 18:37 UTC
[LLVMdev] How do clang & clang++ choose function names for LLVM IR?
Thanks, much appreciated! -David On Thu, Jun 12, 2014 at 12:14 PM, Hans Wennborg <hans at chromium.org> wrote:> On Wed, Jun 11, 2014 at 1:45 PM, David Glanzman <davidglanzman at yahoo.com> > wrote: > > Hello all, > > > > I'm getting started on a project using LLVM's opt tool to do static > > analysis, printing call graphs and such. When compiling C programs to IR > > (and eventually to call graphs), function names remain the same (main, > > function1, function2 etc.), but when compiling the same program as C++, > the > > function names often have cruft added to them (_Z9function1v, > _Z9function2v > > etc.) which doesn't make for a very pretty graph. > > > > Why are these extra characters added when going to IR from C++, but not > C? > > It's called name mangling. See > http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B > > > I'm interested in what they're for and if there's anyway to avoid them > for > > the sake of making nice graphs. > > If you can declare your functions as 'extern "c"', they will not get > mangled. But this won't work for member functions, namespaces, etc. > > If you just want nicer names for your graph, you can run the names > through a demangler. For example: > > $ echo _Z9function1v | c++filt > function1() > > > Thanks, > Hans >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140612/9b82e427/attachment.html>