Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do C++ mangled names stay consistent when compiled on different computers?

In general, what I've observed using nm on Linux is that T symbol names (which I'm interested in) stay consistent across different computers even when I'm not using extern "C". Is my observation correct?

Note I'm using gcc on all computers.

like image 369
MrD Avatar asked Mar 20 '11 17:03

MrD


People also ask

Why do compilers mangle names?

Name mangling is commonly used to facilitate the overloading feature and visibility within different scopes. The compiler generates function names with an encoding of the types of the function arguments when the module is compiled.

Is name mangling consistent?

A particular version of a compiler will mangle names consistently, otherwise it wouldn't be able to link with things it produced. Other than that, all bets are off.

Does C have name mangling?

Since C is a programming language that does not support name function overloading, it does no name mangling.

What is compiler mangling?

In compiler construction, name mangling (also called name decoration) is a technique used to solve various problems caused by the need to resolve unique names for programming entities in many modern programming languages.


1 Answers

It would be very unusual for the computer, the time of day, or the weather to affect name mangling.

What's more likely to cause deviations is differences in compiler version.

But many linux platforms define an ABI (application binary interface) for C++ which includes, among other things, the name mangling rules. On these platforms the same source code will compile to the same mangled names regardless of optimization levels, compiler versions, the hostname, the hard disk serial number, time of day, weather, whether your favorite sports team lost last week, or any factor not explicitly mentioned in the ABI.

like image 117
Ben Voigt Avatar answered Sep 22 '22 02:09

Ben Voigt