Please explain what is name mangling, how it works, what problem it solves, and in which contexts and languages is used. Name mangling strategies (e.g. what name is chosen by the compiler and why) a plus.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the programming language of your choice, if an identifier is exported from a separately compiled unit, it needs a name by which it is known at link time. Name mangling solves the problem of overloaded identifiers in programming languages. (An identifier is “overloaded” if the same name is used in more than one context or with more than one meaning.)
Some examples:
In C++, function or method
getmay be overloaded at multiple types.In Ada or Modula-3, function
getmay appear in multiple modules.Multiple types and multiple modules cover the usual contexts.
Typical strategies:
Map each type to a string and use the combined high-level identifier and “type string” as the link-time name. Common in C++ (especially easy since overloading is permitted only for functions/methods and only on argument types) and Ada (where you can overload result types as well).
If an identifier is used in more than one module or namespace, join the name of the module with the name of the identifier, e.g.,
List_getinstead ofList.get.Depending on what characters are legal in link-time names, you may have to do additional mangling; for example, it may be necessary to use the underscore as an ‘escape’ character, so you can distinguish
List_my.get->List__my_getfrom
List.my_get->List_my__get(Admittedly this example is reaching, but as a compiler writer, I have to guarantee that distinct identifiers in the source code map to distinct link-time names. That’s the whole reason and purpose for name mangling.)