Name Decoration and ABI
Signatures
Functions in C/C++ have signatures. A signature consists of a function's
name, the types, ordering, and const/volatile qualification of the
function's parameters, and the argument passing mechanism the function
uses. Although the following three functions have the same name, they
have different signatures:
int f(void);
int f(char *);
int f(const char *);
Whether a function belongs to a class or a namespace is also encoded in
its signature. Therefore, the following two functions have distinct
signatures, too:
namespace A
{
int f(int n); //same name and parameter list as f() below
}
int f(int n); // but the namespaces differ
Encoding Signatures
The function overloading mechanism of C++ enables you to call f() and
let the compiler decide which overloaded version is to be called, based
on its arguments. For example, the following call:
int n=f("hello");
is resolved to:
int f(const char *);
This happens because the quoted literal string "hello" is of type "const
char *." The secret lies in a technique called "name mangling," or "name
decoration."
Name Decoration
Name decoration is hardly a new concept. FORTRAN, Pascal, and Kerrigan
and Ritchie C used to decorate function names with special characters to
encode various pieces of information. In C, for example, functions'
arguments are passed on the stack by default; but in some cases, they
are passed on CPU registers. Furthermore, the order of arguments can be
either from right to left or vice versa. All these facts need to be
accessible to the linker and the loader without the need to look at the
source file. The solution was to encode these bits of information by
adding special characters to the original function name. For instance,
the compiler could append two underscores at each side of a function's
name (e.g., __func__) to indicate that the function's arguments are
passed on CPU registers. Likewise, to indicate that the order of
arguments is reversed, the implementation could capitalize the
function's name (e.g., FUNC).
Name Decoration and ABI
Interestingly, most programming languages, save C++, define standard
name decorating rules with which all compilers and linkers comply.
Consequently, different C++ compilers -- and in some cases, different
versions of the same compiler -- use disparate name decorating schemes.
Thus, each compiler might produce a different decorated name for the
same function. Now you can see why it's usually impossible to link
modules that were produced by different compilers. Standardizing name
decoration rules is one of the preconditions for a Linux ABI.
» posted by ITworld staff
ITworld
Symantec Backup Exec 12 and Backup Exec System Recovery 8 deliver industry leading Windows data protection and system recovery. Download this whitepaper to find out the top reasons to upgrade and how to get continuous data protection and complete system recovery.
Data and system loss — from a hard drive failure, malicious attack, natural disaster, or simple human error — can happen anytime. Don’t leave your business vulnerable. Make sure you have a secure recovery strategy in place. Symantec's latest backup and system recovery technology can efficiently restore critical applications, individual emails and documents and even restore your entire system in minutes in the event of a loss.
Businesses face a growing challenge to ensure that the IT environment is properly protected. Backup Exec 12 integrates with other applications in the Symantec family of products, to complement your current data protection strategy, keep your data securely backed up and make it recoverable when you need it most.
Crimeware: Understanding New Attacks and Defenses
By Markus Jakobsson, Zulfikar Ramzan
Published Apr 6, 2008 by Addison-Wesley Professional. Part of the Symantec Press series.
Enter now! | Official rules | Sample chapter
Securing VoIP Networks: Threats, Vulnerabilities, and Countermeasures
By Peter Thermos, Ari Takanen
Published Aug 1, 2007 by Addison-Wesley Professional.
Enter now! | Official rules | Sample chapter







