[LLVMdev] How to get the original function name in C++?

Bill Seurer seurer at linux.vnet.ibm.com
Thu Dec 11 07:36:38 PST 2014


On 12/11/2014 5:52 AM, zy jj wrote:
> Hi, everyone!
>      I'm new here trapped by a simple problem for days.
>      When LLVM translates C++ source code to IR, it will add a prefix to
> the function name. For example:
> source code:
> int foo(){
> return 1;
> }
> IR form:
> define i32 @_Z3foov() #0 {
> entry:
>    ret i32 1, !dbg !20
> }
>      The getName() method returns _Z3foov, then how can I get foo? I
> know the debugging information is contained in metadata, but I've no
> idea on using it.
>      Thanks a lot for any help.
>

In C++ names are "mangled" when translated to machine instructions. 
This allows for function overloading and such.

Are you looking for something you can call inside of llvm to get the 
demangled name?  At the command line you can use C++flit to get the 
demangled name.  For example:

~$ c++filt _Z3foov
foo()

-- 

-Bill Seurer




More information about the llvm-dev mailing list