On Mon, Mar 02, 2015 at 12:12:34AM -0500, John Criswell wrote:> 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).there's also a __cxa_demangle function in http://llvm.org/svn/llvm-project/libcxxabi/trunk/include/cxxabi.h
Depending on what you want to achieve, one possibility is wrapping function declaration with extern "C" void somefunction(void); or extern "C" { void somefunction(); int otherfunction(); } will make those functions have their name unmangled - this is used when interfacing between C and C++ functions, since the C compiler will NOT name-mangle. This does however also affect some other aspects of the code e.g. linker can't check parameter passing and you can't have more than one function with the same name, with different function argument types - like you can in C++ [in fact these are the two main reasons for using name-mangling]. I can't remember if it also affects the ability for example to handle exceptions from C++. -- Mats On 2 March 2015 at 09:03, serge guelton <sguelton at quarkslab.com> wrote:> On Mon, Mar 02, 2015 at 12:12:34AM -0500, John Criswell wrote: >> 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). > > there's also a __cxa_demangle function in > > http://llvm.org/svn/llvm-project/libcxxabi/trunk/include/cxxabi.h > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Thanks for all your help. "__cxa_demangle" can decode the mangled function name as expected. Another question is that given an unmangled function name, how to get the corresponding mangled name in llvm? Best, Haopeng On 3/2/15 3:22 AM, mats petersson wrote:> Depending on what you want to achieve, one possibility is wrapping > function declaration with > > extern "C" void somefunction(void); > > or > > extern "C" { > void somefunction(); > int otherfunction(); > } > > will make those functions have their name unmangled - this is used > when interfacing between C and C++ functions, since the C compiler > will NOT name-mangle. > > This does however also affect some other aspects of the code e.g. > linker can't check parameter passing and you can't have more than one > function with the same name, with different function argument types - > like you can in C++ [in fact these are the two main reasons for using > name-mangling]. I can't remember if it also affects the ability for > example to handle exceptions from C++. > > -- > Mats > > On 2 March 2015 at 09:03, serge guelton <sguelton at quarkslab.com> wrote: >> On Mon, Mar 02, 2015 at 12:12:34AM -0500, John Criswell wrote: >>> 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). >> there's also a __cxa_demangle function in >> >> http://llvm.org/svn/llvm-project/libcxxabi/trunk/include/cxxabi.h >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev