[MLton] latest MLton segfault in gmp
Matthew Fluet
matthew.fluet at gmail.com
Wed Oct 14 14:58:20 PDT 2009
I'm hardly an expert. I used the www.x86-64.org document to implement
the C calling convention in the native codegen, but didn't peruse it
much otherwise.
Searching for "align" in the document, though, reveals that on page
12, it declares that {,signed,unsigned} {,long} long all have 8-byte
alignment. However, on the next page it states:
Like the Intel386 architecture, the AMD64 architecture in general does not re-
quire all data accesses to be properly aligned. Misaligned data
accesses are slower
than aligned accesses but otherwise behave identically. The only exceptions are
that __m128 and __m256 must always be aligned properly.
So, it isn't clear to me that one really needs to 8-align 64-bit integers.
In the next subsection (p. 13), on aggregates and unions, it states:
An array uses the same alignment as its elements, except that a local or global
array variable of length at least 16 bytes or a C99 variable-length
array variable
always has alignment of at least 16 bytes.
This seems to suggest that gcc is within its rights to assume that an
array of {,long} long-s is 16-byte aligned (if it has at least 2
elements). MLton would have a hard time supporting that short of
implementing '-align 16'.
I suggest that going with '-align 8' (as Wesley committed earlier
today) is a reasonable way to go.
I did want to also point out that there is a legacy issue, I would
assume, on Debian. Since mlton-20070826 is dynamically linked against
libgmp, isn't it just an incredible luck of the draw that a
self-compile with mlton-20070826 didn't happen to produce a
non-16-byte aligned IntInf array.
On Wed, Oct 14, 2009 at 5:57 AM, Wesley W. Terpstra <wesley at terpstra.ca> wrote:
> On Wed, Oct 14, 2009 at 7:23 AM, Florian Weimer <fw at deneb.enyo.de> wrote:
>>
>> The AMD64 psABI supplement requires 8-byte alignment. And the end of
>> the input area on the stack must be aligned to a 16 byte boundary upon
>> function entry. See <http://www.x86-64.org/documentation/abi-0.99.pdf>.
>
> The stack was actually already aligned, just not the GMP limb array in
> MLton's heap.
>
> Still, if requiring this 8-byte alignment is sanctioned, we should just go
> with -align 8 and be safe.
>
> Since Matthew is the AMD64 expert I'm mostly waiting to hear his opinion
> before I commit a fix.
>
>
> _______________________________________________
> MLton mailing list
> MLton at mlton.org
> http://mlton.org/mailman/listinfo/mlton
>
More information about the MLton
mailing list