Linking C++ objects from multiple compilers

It is relatively well known that you can not link c++ objects files compiled with different compilers on various Unix platforms. But quite a few people don't seem to know exactly why that is the case, and I've recently seen quite a few emails and usenet postings on this, so let me give a shot at explaining thie issue.

Unix System V has a specification called "application binary interface", in short, ABI. The System V ABI has usually two parts - generic, platform-independent part called gABI and platform-specific part called psABI. gABI documentation can be found here. psABI is defined for each platform that system V is ported, and for SPARC, it can be found here. The ABI as a whole dicates the calling convention, the linkage convention, the object file format and any other information that's necessary to produce all tools - compiler, linker, dynamic linker, program loader, etc - necessary to produce conforming object files (including executables and shared libraries).

The problem is that the ABI does not specify things that compilers, linkers and runtime libraries to follow, to make C++ objects compatible. Various aspect of C++ - object model, exception handling, runtime type information and name mangling - have to be common for compilers and runtimes to be compatible with each other. Since the ABI does not specify all those aspect, each implementation of compilers and runtime libraries decided to do it in their own way.

The end result of lack of ABI specification is that two dominant compilers on Solaris, namely Sun compiler and gcc, are not compatible with each other for C++, whereas they are compatible for C objects. This causes all kinds of headaches, and the biggest one is that if you have a C++ shared library, you have to provide two version, one compiled by Sun compiler and the other compiled by gcc if you're to allow users of the library to pick any compiler s/he wants.

Two obvious ways to fix this issue: change gcc to follow Sun model, or change Sun compiler to follow gcc. The first simply won't happen - gcc is cross platform and won't change their portable way to accomodate a particular platform. The second is also problematic because gcc's c++ ABI hasn't been exactly stable - it's been revised couple of times in incompatible ways and Sun as a company regards the backward compatibility quite seriously.

Untill this issue is resolved and a common ABI is defined and agreed upon, all the people using C++ - the users, the developers, and the compilers and tools developers - will have to suffer from this C++ object file incompatibility.

Comments:

Couldn't Sun come up with an ABI wrapper that would allow gcc objects to compile? or since Sun now ships gcc w/ S10, create an ABI module for Forte that targets the Sun shipped gcc?

Posted by Bob on June 29, 2005 at 02:29 AM PDT #

Post a Comment:
Comments are closed for this entry.
About

seongbae

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today