Jim Starkey wrote:
> The argument against using pure virtual interfaces for plugin and engine
> interfaces has been the possibility that virtual calls between code
> produced by incompatible C++ compilers may not work correctly or crash. 
> However, all known pairs of incompatible C++ compilers using different
> symbol mangling rules, which precludes cross compiler symbol resolution
> for non-C symbols during both linking and dynamic library loading.
> 
> The slightly longer explanation is that either the linker or loader
> knows beans about C++ and virtual functions -- they just do exact symbol
> match.  The compiles, however, encode (aka mangle) symbols to include
> namespace scoping and argument types.  Neither the linker nor the loader
> would detect (or care) about different manglements of the same symbols
> from different C++ compilers.
> 
> See http://www.agner.org/optimize/calling_conventions.pdf for the gory
> details.
> 
> Matt, the ball is in your court.

/me looks at the ball slowly bouncing over the net towards his feet...

Correct, the linker knows zilch about C++ and virtual functions and only work
with symbol names.

The name mangling issue, however, does not play a role in virtual function
calls, since those by their nature does an array indexing an an indirect call.
There are no symbols associated there. However, the array is usually stored in a
"class information structure" and refered to from the class instance (using a
field usually called the __vptr). However, the placement of the __vptr and the
layout of the vtable can be drastically different between compilers.

A virtual call "obj.foo(my_variable)" in C++ could roughly be something like
"(*(*(obj.__vptr))[SLOT])(my_variable)", where SLOT is a constant number for the
slot of the virtual function in the vtable.

For calling functions *directly*, as in non-virtual calls, (e.g., from a plug-in
to a host, or the opposite), the name mangling plays a role since the naming
scheme might be different between the host and the plug-in.

Just my few cents,
Mats Kindahl
-- 
Mats Kindahl
Senior Software Engineer
Database Technology Group
Sun Microsystems

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to