C++ Logo


Advanced search

Re: [std-proposals] Common ABI specification

From: samuel ammonius <sfammonius_at_[hidden]>
Date: Fri, 27 Jan 2023 19:34:09 -0330
On Fri, Jan 27, 2023 at 6:25 PM Jonathan Wakely <cxx_at_[hidden]> wrote:

> On Fri, 27 Jan 2023 at 21:11, samuel ammonius wrote:
>> GCC and IBM's C++ compilers use the same system for name
>> mangling, which uses valid identifiers.
> No it doesn't. A mangled name begins with a "_Z" prefix, which is not
> allowed as an identifier, because it's a reserved name. So no program can
> ever have "_Z1fv" as an identifier, which means it can be used as a mangled
> name and won't clash with unmangled names like "f".
> The problem with your proposed scheme is that mangling foo::bar as foo_bar
> clashes with an identifier foo_bar. Don't try to make up your own mangling
> scheme when we already have ones that work.
Oh, sorry. I wasn't aware that "_Z" was reserved. I'll use the Itanium name
mangling scheme in a new version of the proposal.

On Fri, Jan 27, 2023 at 7:21 PM Jens Maurer <jens.maurer_at_[hidden]> wrote:

> On 27/01/2023 22.11, samuel ammonius via Std-Proposals wrote:
> > GCC and IBM's C++ compilers use the same system for name
> > mangling, which uses valid identifiers. It's documented here:
> > https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling
> > <https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling>
> > Would that work?
> >
> > <https://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling>
> >> And doing that would not be a pure extension with no impact on the
> current language, because it would require incompatible changes from at
> least one
> >> existing, widely-used compiler.
> >
> > What about something similar to /extern "C"/ for telling compilers
> > that the symbols are stored this way? (extern "cpp_common_abi")
> Could you remind me what the purpose of your proposal is?
> There is the Itanium ABI for those C++ implementations that
> choose to use it, and those C++ implementations are link-
> compatible, meaning that object files produced by different
> compilers can be linked together (if the same standard
> library is used).
> Other programming languages are certainly welcome to use that
> ABI if it fits their needs, but as-is, it's a C++ ABI, and
> thus is tailored to C++ and evolves as new features are added
> to C++ that need ABI consideration.
> I'd also like to point out that the C++ standard has traditionally
> refrained from specifying an ABI, as it is at a different level
> of abstraction than the source code. It seems the existing
> cross-vendor efforts to define ABIs work quite nicely, so I'm
> not seeing an imminent need for WG21 to get involved here.
> Jens
I agree that C++ compilers are doing pretty good in being
compatible with each other, but it's still good to have a fixed
standard that developers can count on. With a standard name
mangling scheme, C++ developers can ship precompiled
libraries and be confident that they should work for developers
using them. Developers in other languages can alias the full
mangled name of a C++ function without worrying that it
won't work on different compilers and platforms.

Received on 2023-01-27 23:04:22