This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Sub lib compatibility with g++


Hi Eljay 

Many thanks for your note. Indeed does help! 

I am now considering an approach like this, since in my original deployment I was running with a C program which makes use of a C++ (g++ compiled library) via a dynamically loaded C++ (also g++ compiled) shared object module. This latter module provides the C external linkage via appropriate extern "C" usage to the primary C program. 

So something like this 

C program - myprog (compiled with gcc) 
dynamically loads MODULE A - C++ shared object (g++), with C ABI - which in turn links and uses a g++ compiled C++ lib - say libA.so 

So far ok, I guess. 

So from your note, I am now considering expanding this as follows - 

C program - myprog (compiled with gcc) 
dynamically loads MODULE A - C++ shared object (g++), with C ABI - which in turn links and uses a g++ compiled C++ lib. 
(same as before) 
but also will now dynamically load MODULE B - another C++ shared object (but this time sun compiled), and also with C ABI - which in turn uses the Sun compiled 3rd party C++ lib - say libB.so (libB.so is available only as Sun studio compiled lib) 

In both cases the C ABIs provides usage of the C++ modules (one g++ compiled and the other sun compiled) from the C prog - myprog (gcc compiled) 

I am forced to do this, as you say since I can't use MODULE B in g++, since it will make lib calls into libB.so and libB.so is available only in Sun studio compiled version. 

Do you think this will work out ? 

One other aspect I am concerned about is that with the above, myprog will eventually make use of both the gcc C++ runtime and the Sun C++ runtime (via the two MODULES A and B which respectively call into libs libA.so and libB.so). 
Do you see any issues with that ? 

Also - do you know of any good examples and/or web resources that demonstrate how the "thunking" libs. should be created and provide more info. on the details ? 

Thanks very much 

Regards 
Kumar. 


----- Original Message ---- 
From: John (Eljay) Love-Jensen <eljay@adobe.com> 
To: Kumar Bhaskar <akumargolf2000@yahoo.com>; gcc-help@gcc.gnu.org 
Sent: Sunday, December 16, 2007 9:17:37 AM 
Subject: RE: Sub lib compatibility with g++ 

Hi Kumar, 

> I understand that gcc C++ and Sun Studio C++ are not ABI compatible, but was wondering if there is anything at all I can do to get around this problem, short of requesting for a gcc compiled 3rd party lib and/or I having to change my compiler to Sun Studio. 

Yes, there is a solution. Since the C ABI is the same on both compilers, you can write a thunking library using the Sun C++ compiler that has C harness routines that call the Sun C++ compiled library methods. 

And on the GCC side, you can either use those C routines directly, which, effectively, treats that C++ library as if it were a C library (via the thunking library). 

Or in addition, you could also write a thunking C++ proxy wrapper on the GCC side, that behaves as-if it were the objects in the Sun space. 

Some of the issues that the thunking library has to handle is catching ALL exceptions, translating (flattening) those exceptions into something that can be presented over the C barrier (the Sun-side thunking library). Flattening all vectors, strings, and other Standard C++ Library (STL) objects that are used by the Sun C++ libraries interface (if any). Flattening all non-POD parameters, and and all returned results. 

It's a lot of work. I've done it before several times, even once again in the past couple months. I don't recommend it, if you can avoid it. 

> I have access to the sun compiler and sun C++ runtime. 

If you didn't, the challenge would be insurmountable! 

> For instance - Is it possible to set some options to gcc to indicate - make use of the Sun name mangling style ? 

No, GCC doesn't have that option. 

But it's not just that "mangling is different" (although that is a big factor too). The Standard C++ Library (std::vector, std::string, et cetera) is different too. Iterators are different. Exception handling mechanics are different. Stack unwinding is different. Parameter passing is different. Result propagation is different. Inlining is different. Free store (C++ heap) management is different. Streams (fstream, iostream, stringstream) are different. Non-C POD like bool and wchar_t may be different. 

All those things are part-and-parcel of the C++ ABI, which is different in Sun and GCC. 

HTH, 
--Eljay


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]