C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Standard support for different ABI's for class vtables

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 01 Jun 2025 23:34:13 -0300
On Sunday, 1 June 2025 18:42:34 Brasilia Standard Time Oliver Hunt via Std-
Proposals wrote:
> The fact is that the windows C++ ABI is not the same as other platforms, and
> that’s what compilers targeting windows should be using. Arguing otherwise
> is no different from saying “long double on x86-64 darwin (maybe linux, I’m
> not sure?) is fp80, so compilers should be able to use that abi on windows
> despite it not being the case”/
[cut]
> In an ideal world compilers would emit code that conforms the the platform
> ABI, rather than complaining that what is fundamentally incorrect codegen
> not working.

The platform ABI does not include C++. The processor-specific ABI (psABI) for
each OS only covers calling sequence and standard types. The C++ ABI comes on
top and it has a psABI portion for some low-level details.

The x86-64 System V ABI is here:
 https://gitlab.com/x86-psABIs/x86-64-ABI
As you can see, it makes almost no references to C++, aside from making a
soon-to-be-unnecessary reference to "bool" instead of "_Bool", some discussion
about enums with different sizes, and how passing non-trivial C++ objects need
to go read the C++ ABI instead.

The Windows x86-64 ABI is documented[1] much in the same way. All compilers
adhere to it, otherwise they couldn't call Win32 functions.

The problem is the MSVC C++ ABI, which is entirely undocumented. Even Clang's
implementation is, AFAIK, entirely reverse-engineered. I don't think it's
reasonable to ask compiler vendors to implement against a spec that isn't
written down and published.

You may also not be old enough to remember when we had more ABIs. The rule has
always been that the compiler chooses the ABI for C++, not the OS. I worked
with IRIX, Solaris, HP-UX, AIX and C++ libraries did not interoperate there,
even in the late 2000s. On Solaris, you even had three different world
implementations, because Sun's CC supported two different Standard Libraries,
like Clang today supports libstdc++, libc++, and MS STL. HP moved to the IA-64
C++ ABI when HP-UX moved to IA-64, then it and IRIX became irrelevant. I don't
remember what the last ABI that Sun Studio supported before Solaris died; I'm
pretty sure IBM Visual Age C++ switched to the IA-64 at some time, but I
haven't worked with AIX in over 15 years.

[1] https://learn.microsoft.com/en-us/cpp/build/x64-software-conventions

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Platform & System Engineering

Received on 2025-06-02 02:34:22