C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Ensure ABI compatibility at runtime -- std::layout_of

From: Lauri Vasama <wg21_at_[hidden]>
Date: Thu, 7 Nov 2024 15:46:23 +0200
What if the types remain the same but their meaning changes?

Let's say you have a hash table where the capacity is stored in size_t.
Later the implementation is changed such that that same size_t stores
capacity - 1, i.e. a bitmask used for fast modulo when the capacity is
always a power of two. In this case the hash would not change, but ABI
compatibility is still broken.

On 07/11/2024 13.08, Frederick Virchanza Gotham via Std-Proposals wrote:
> On Thu, Nov 7, 2024 at 10:35 AM Giuseppe D'Angelo wrote:
>>> (2) It's possible for two classes to have identical layout but to
>>> still have differing and incompatible implementations.
>> Bingo. Say that your magic function tells you that vector<int> is made
>> up of 3 pointer-sized fields. What are they?
>>
>> * begin, end, capacity
>> * begin, end, pointer to physical end
>> * begin, size, capacity
>> * begin, size, pointer to metadata/bookkeeping
>> ...
>>
>>
>> And even if they match, who tells you they're used in a consistent way?
>>
>> You need something *beyond* C++ to deal with ABI incompatibilities and
>> with the unsafety of plugin loading in general.
>
> Maybe I'm going off into fairytale land with it here, but we could
> compute a hash sum for all of the members, so for example let's say
> the class is:
>
> class Monkey {
> int n;
> char *p;
> void DoSomething(void);
> };
>
> Then you would take the names of all of the members, i.e. n + p +
> DoSomething, and you concatenate them to give the string:
>
> "npDoSomething"
>
> and then you feed that into a hash algorithm such as sha256 to give a
> 256-Bit digest. So then you compare the two digests to see if you're
> dealing with the same implementations.

Received on 2024-11-07 13:46:29