I noticed today that long long
in wasi-sdk's clang is aligned to 8 bytes. I have been using clang -m32
targeting Linux to provide an oracle for fuzzing Lucet, but this alignment difference undermines that oracle's ability. I was wondering if the 8-byte alignment for long long
is a decision that LLVM made when putting together the wasm32 target, or if there's something inherently 8-byte aligned about Wasm i64s?
for the moment I'm going to try excluding long long
s from the fuzzer-generated programs but it's a shame to lose out on all that potential coverage
It originally did come about because it's the default in clang if the target doesn't override it.
That said, one nice property is that i64 (and structs containing it) are layout-compatible between wasm32 and wasm64
It's also nice for fields which are accessed atomically, since some hosts require 64-bit alignment for a 64-bit atomic access.
The other consideration here is that it's part of the C ABI, which we've effectively declared stable at this point. Changing it is probably possible, but we'd have to go through an ABI transition process.
got it, thanks Dan. That all makes sense, I just wanted to make sure it was intentional. I will have to do some thinking about how to get a good oracle again for fuzzing
running the wasm through some non-Cranelift backends like WAVM or Node probably is a good step, but then both the oracle and the test will be going through wasi-sdk's clang
if y'all have thoughts on how to make native Linux clang behave enough like Wasm, please let me know
Clang on my Linux box with -m32
says __alignof(long long)
is 8.
interesting. maybe I need to be using a newer clang...
frowning
acfoltzer@stribog:/tmp % clang-10 -m32 test.c -o test-clang10 acfoltzer@stribog:/tmp % clang-6.0 -m32 test.c -o test-clang6 acfoltzer@stribog:/tmp % ./test-clang10 alignof(long long) = 4 acfoltzer@stribog:/tmp % ./test-clang6 alignof(long long) = 8
I unfortunately don't have the bandwidth to be doing much more with fuzzing at the moment but it would be great to sort this out at some point
it appears that clang 7 -> 8 is where the alignment changed
Last updated: Nov 22 2024 at 16:03 UTC