[cxx-abi-dev] Possibly ambiguous mangling of extern "C" functions

Lawrence Crowl crowl at google.com
Tue Aug 19 23:46:21 UTC 2008


On 8/19/08, Michael Wong <michaelw at ca.ibm.com> wrote:
> The example in question is at the end of "5.1.5 Type encodings".  of
> http://www.codesourcery.com/public/cxx-abi/abi.html.
>
> In this example, it is using an extern "C" function as a parameter to a
> class template. There are two problems:
> 1. Should there be full mangling, partial mangling, or no mangling of the
> extern 'C" function as a template parameter?
> 2. Should there be an X...E (after the I and before the L) since there is a
> <expr-primary> production under <template-arg> that makes that the case.
>
> Here is the example I actually used:
>
> extern "C" bool IsEmpty(char *); // (un)mangled as IsEmpty
>  template<bool (&)(char *)> struct CB { static int x; };
>  // CB<IsEmpty> is mangled as "2CBIL_Z7IsEmptyEE"
>  int *p = &CB<IsEmpty>::x;
>
>
> The example is shown without any supporting rules in the spec which makes it
> hard to justify other then an intuition, and it is shown with just the _Z7
> prefix mangling on the function. It does not mangle the function parameter,
> which may be OK if the group decides it is so since extern "C" function
> can't be overloaded anyway and you can't have it with different parameters.
> But then why bother to mangle it at all?

The mangling must distinguish between an extern "C" function and an
extern "C++" function of the same signature.  You cannot have both in
the same translation unit, but you can have both in the same program.

Some form of mangling for the C function is required to ensure that
one can parse the containing name.

>
> Checking various versions of GNU also shows different mangling with the
> latest that I have (4.1.2) deviating the most from the example. I show the
> example with and without the extern "C".
>
> gcc (GCC) 4.1.2 20071124 (Red Hat 4.1.2-42)
> with extern "C":
> _ZN2CBILZ7IsEmptyEE1xE <== GCC missing X and has the Z (but no underscore)
>
> without extern "C":
> _ZN2CBILZ7IsEmptyPcEE1xE <=== This is close but it is still missing the X
> and has no _Z
>
> gcc (GCC) 3.3.4
> with extern "C":
> _ZN2CBIXL7IsEmptyEEE1xE <== Older GCC has the X, but leaves out the _Z or Z
> (same as us with extern "C"), indicating no mangling, but it has the 7
>
> without extern "C":
> _ZN2CBIXL_Z7IsEmptyPcEEE1xE <== This one looks OK, same as us without extern
> "C"
>
> Anybody can report what EDG/Intel generates? Thanks.
>
>  Michael Wong
>  XL C++ Compiler kernel Development
>  IBM Canada Ltd., C2/KD2/8200/MKM
>  8200 Warden Avenue
>  Markham, Ontario  L6G 1C7
>  W:905-413-3283 F:905-413-4839
>  Boost test results
> http://www-1.ibm.com/support/docview.wss?rs=2239&context=SSJT9L&uid=swg27006911
>  C/C++ Compilers Support Page
> http://www.ibm.com/software/awdtools/ccompilers/support/
>  C/C++ Feature Request Interface
> http://www.ibm.com/support/docview.wss?uid=swg27005811
>  XL Fortran Compiler Support Page
> http://www.ibm.com/software/awdtools/fortran/xlfortran/support/
>  XL Fortran Feature Request Interface
> http://www.ibm.com/support/docview.wss?uid=swg27005812


-- 
Lawrence Crowl



More information about the cxx-abi-dev mailing list