Questions tagged [name-mangling]

Name-mangling is a technique used by compilers (mainly C++ compilers) to encode information in strings that can be supported by linkers designed to handle C code.

Questions relating to the schemes used for name mangling, linking problems in the face of mangling, or the tools used to decode mangled names (like c++filt or dem) are appropriate for this tag.

In C++, name mangling is used to encode things like the symbol's namespace and/or function signature.

For example, given this C++ code:

namespace Foo {
namespace Bar {
    class A {
        public:
            A();
            ~A();
    };
}

int f(int i)
{
    Bar::A a;
}

int f(double d)
{
    Bar::A a;
}

}

the g++ compiler on a Linux box might generate the following "mangled" names for the 2 overloads of f() and A's constructor and destructor:

  • _ZN3Foo1fEd
  • _ZN3Foo1fEi
  • _ZN3Foo3Bar1AC1Ev
  • _ZN3Foo3Bar1AD1Ev

Using a tool like c++filt, we can decode these names:

$ echo _ZN3Foo1fEd | c++filt
Foo::f(double) 

$ echo _ZN3Foo3Bar1AC1Ev | c++filt
Foo::Bar::A::A() 

Of course, if you're not using g++ on Linux, the mangled form for your symbols may (likely WILL) be different. (The C++ FAQ lite subtly suggests that if two C++ compilers have different ABIs, even in small details, then they should intentionally have different name mangling schemes, so that things break in an obvious way and not a subtle way.)

316 questions
15
votes
2 answers

Why is the return type of C++ function template instantiations included in the mangled function name?

The Itanium ABI specifies that, with a couple uninteresting exceptions, the return type is included in the mangled names of template instantions but not non-templates. Why is this? In what case could you have two function template instantiations…
EvanED
  • 947
  • 6
  • 22
13
votes
3 answers

python How to create private class variables using setattr or exec?

I've just run into a situation where pseudo-private class member names aren't getting mangled when using setattr or exec. In [1]: class T: ...: def __init__(self, **kwargs): ...: self.__x = 1 ...: for k, v in…
chown
  • 51,908
  • 16
  • 134
  • 170
13
votes
2 answers

C++ Name Mangling Library for Python

I'd like to mangle and demangle C++ function names in a Python program. Is there anything like that available? I searched for hours now, perhaps I'm lucky here...
manuels
  • 1,511
  • 3
  • 14
  • 26
13
votes
1 answer

Perf shows mangled function names

I wanted to give perf a shot to profile some programs after I saw this talk from CppCon 2015. I downloaded the same Google benchmark library that the guy uses in the talk, compiled my program with the appropriate switches, linked it to it, then used…
notadam
  • 2,754
  • 2
  • 19
  • 35
13
votes
1 answer

Finding arguments that go with methods in C++ dll's

Ok, so I can use dumpbin.exe /exports library.dll to find all methods in the dll. ...but how do I find out which arguments to pass into them? Without a header file of course.
Presidenten
  • 6,327
  • 11
  • 45
  • 55
12
votes
3 answers

How to undecorate name from decorated name?

At a post of Raymond Chen, he seems to be able to know the function's undecorated name from the decorated name. I have no idea how could he do this. In this decorated name, ?GetName@PushButton@UILibrary@@UAEPB_WPAPAVStringHolder@2@@Z What does the…
Benjamin
  • 10,085
  • 19
  • 80
  • 130
12
votes
4 answers

x64 DLL export function names

I am trying to port a 32-bit dll (and application) to 64-bit and I have managed to build it without errors. When trying to load it with my 64-bit application I noticed that the exported function names differ. This is how I export the…
dbostream
  • 781
  • 2
  • 11
  • 27
12
votes
1 answer

Private name mangling function

Is there a function in the Python standard library to reproduce Python's name mangling scheme with a "private" attribute name? It seems like there would be, but I can't find it for the life of me. I wrote this, but if there's a better way I'm all…
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
11
votes
4 answers

C++ name mangling by hand

I am writing a script for the IDA Pro disassembler in Python using the idapython plugin. Using this, I am able to fill in the gaps where IDA's auto-analysis falls short. One area that has me stumped is naming locations/functions with (for want of a…
Aidan Steele
  • 10,999
  • 6
  • 38
  • 59
11
votes
4 answers

Delphi - unmangle names in BPL's

Is it possible to unmangle names like these in Delphi? If so, where do I get more information? Example of an error message where it cannot find a certain entry in the dbrtl100.bpl I want to know which exact function it cannot find (unit, class,…
Jeroen Wiert Pluimers
  • 23,965
  • 9
  • 74
  • 154
10
votes
5 answers

Difference in linkage between C and C++?

I have read the existing questions on external/internal linkage over here on SO. My question is different - what happens if I have multiple definitions of the same variable with external linkage in different translation units under C and C++? For…
KC.
  • 864
  • 1
  • 10
  • 11
9
votes
2 answers

Is there a way to use custom mangling in g++/clang++?

When using c++ template, and especially tuples, I often get very long mangled names like…
OznOg
  • 4,440
  • 2
  • 26
  • 35
9
votes
2 answers

Is the return type of a function part of the mangled name?

Suppose I have two functions with the same parameter types and name (not in the same program): std::string foo(int x) { return "hello"; } int foo(int x) { return x; } Will they have the same mangled name once compiled? Is the the return…
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
9
votes
2 answers

Getting parent private or protected values from the child class

Well, I have almost the same question, except one detail: I need to get private values of the base class. Code: class Parent(object): def __init__(self): self.__field = 13 class Child(Parent): def…
Montreal
  • 2,143
  • 5
  • 18
  • 28
9
votes
1 answer

Dynamic Loading Without extern "C"

I'd like to use libdl to dynamically load C++ in general. The problem is identifying symbols at runtime that have been name mangled. As described here, one solution is to remove name mangling by using extern…
Praxeolitic
  • 22,455
  • 16
  • 75
  • 126
1 2
3
21 22