2024-12-20 09:57:10

Apple ABI for structs on aarch64 reverse engineered in 5 minutes

Yesterday we added support for structs on Apple sillicon. It took us 5 minutes to figure it out.

The struct padding is ok : if size is greater than 32 bits, then align on 32 bits. This is a nice equilibrium between speed and space, and the same on all architectures we tested so far with gcc and clang.

What was wrong was the struct size : round to 64 bits for 64 bit Apple hardware. Note that on amd64 most compilers do 128 bit alignment for struct size because modern architectures are based on DDR and so have twice the bus width (64 bits) for concurrent memory access. It may mean that struct access is twice faster on amd64 gcc/clang than on Apple hardware and ABI. As Microsoft, they have a history of maintaining binary compatibility with pre-DDR hardware which explains a lot.

Excerpt from kc3/libkc3/struct_type.c:160

  if (sizeof(long) == 4)
    tmp.size = (offset + 3) / 4 * 4;
  else
#ifdef __APPLE__
    tmp.size = (offset + 7) / 8 * 8;
#else
    tmp.size = (offset + 15) / 16 * 16;
#endif

That's all !