Name Decoration and ABI

July 19, 2002, 12:00 AM —  ITworld — 

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

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
Resources
White Paper

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.

Webcast

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.

White Paper

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.

Free stuff

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

Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

More Resources