[LLVMdev] clang change function name

John Criswell jtcriswel at gmail.com
Sun Mar 1 21:12:34 PST 2015


On 3/2/15 12:07 AM, Haopeng Liu wrote:
> Got it, thanks. But in my pass, I use function name to locate. Can I 
> disable mangling in clang?

No, but you can probably fine a library that can either mangle the 
original name or demangle the name you're seeing in the LLVM bitcode.

As an FYI, on Unix, the c++filt program will demangle names (although 
sometimes you have to remove an extra '_' from the front of the name to 
get it to work).

Regards,

John Criswell

>
> Best,
> Haopeng
>
> On 3/1/15 10:44 PM, John Criswell wrote:
>> On 3/1/15 11:38 PM, Haopeng Liu wrote:
>>> Hi,
>>>
>>> I compile a .cpp with cmd:
>>> clang++ -emit-llvm -c -g -O0 -w pbzip2.cpp -o pbzip2.bc -lbz2
>>> llvm-dis pbzip2.bc
>>>
>>> One function in .cpp is consumer_decompress. However, I look inside 
>>> pbzip2.ll. The function name is changed to "define i8* 
>>> @_Z19consumer_decompressPv(i8* %q) #0 {"
>>>
>>> Why clang adds a "_Z19" prefix and "Pv" suffix?
>>
>> Clang mangles the name so that the function's name encodes the name 
>> and the function's type; this helps the linker link C++ object files 
>> together correctly.  See 
>> http://en.wikipedia.org/wiki/Name_mangling#Name_mangling_in_C.2B.2B 
>> for more details.
>>
>> Regards,
>>
>> John Criswell
>>
>>>
>>> Thanks,
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>>
>


-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
http://www.cs.rochester.edu/u/criswell




More information about the llvm-dev mailing list