Stream: wasi

Topic: alignment in wasi-sdk clang


view this post on Zulip acfoltzer (Mar 10 2020 at 01:20):

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?

view this post on Zulip acfoltzer (Mar 10 2020 at 01:21):

for the moment I'm going to try excluding long longs from the fuzzer-generated programs but it's a shame to lose out on all that potential coverage

view this post on Zulip Dan Gohman (Mar 10 2020 at 02:27):

It originally did come about because it's the default in clang if the target doesn't override it.

view this post on Zulip Dan Gohman (Mar 10 2020 at 02:27):

That said, one nice property is that i64 (and structs containing it) are layout-compatible between wasm32 and wasm64

view this post on Zulip Dan Gohman (Mar 10 2020 at 02:29):

It's also nice for fields which are accessed atomically, since some hosts require 64-bit alignment for a 64-bit atomic access.

view this post on Zulip Dan Gohman (Mar 10 2020 at 02:30):

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.

view this post on Zulip acfoltzer (Mar 10 2020 at 19:08):

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

view this post on Zulip acfoltzer (Mar 10 2020 at 19:09):

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

view this post on Zulip acfoltzer (Mar 10 2020 at 19:10):

if y'all have thoughts on how to make native Linux clang behave enough like Wasm, please let me know

view this post on Zulip Dan Gohman (Mar 10 2020 at 19:47):

Clang on my Linux box with -m32 says __alignof(long long) is 8.

view this post on Zulip acfoltzer (Mar 12 2020 at 17:53):

interesting. maybe I need to be using a newer clang...

view this post on Zulip acfoltzer (Mar 12 2020 at 17:56):

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

view this post on Zulip acfoltzer (Mar 12 2020 at 18:02):

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

view this post on Zulip acfoltzer (Mar 12 2020 at 18:03):

it appears that clang 7 -> 8 is where the alignment changed


Last updated: Dec 23 2024 at 13:07 UTC