Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
8-byte access alignment detection is wrong with autoconf #7938
Original bug ID: 7938
autoconf's AC_CHECK_ALIGNOF([long]) always returns "x8", regardless of architecture. This is not actually the legal alignment of memory accesses.
ARCH_ALIGN_INT64 used to be defined from the result of config/auto-aux/int64align.c, which actually checks for legal memory access requirements. This was changed in 4.08.
Reading int64 values from the heap is going to be slower.
Comment author: @stedolan
I think that link is to the generated configure, the source is
I think the issue is that on 32-bit platforms, ocaml will now think that 64-bit reads and writes require 8-byte alignment, which will trigger the slow path whereby 64-bit accesses are emulated as a pair of 32-bit accesses.
What the old configure script checked was "will 64-bit accesses that are only 4-byte aligned trap?", while the new configure script asks "what is the optimal alignment of a 64-bit access?". There are several platforms (e.g. x86) where the optimal alignment is 8 bytes, yet 4-byte aligned accesses work fine.
The fix is to replace AC_CHECK_ALIGNOF with a macro that checks whether 4-byte alignment traps. I'm not enough of an autoconf expert to know if there's a standard macro for this, though.
Comment author: @Reperator
Indeed. I'm working on a PR that additionally needs checks for 32-bit and 16-bit accesses in order to use atomic reads/writes for bigarrays on supported platforms. If anybody with autoconf knowledge were to implement these, that'd be great.
Comment author: @xavierleroy
The old autodetection code was fragile and unreliable, so I advise against resurrecting it.
The plan we had with @shindere was to use the C compiler alignment as the default, and hard-code a small list of exceptions for which we know that the hardware supports reduced alignment, in particular x86.