From 2cb8b275caf090bf56cc78424aaa97766cd02fb6 Mon Sep 17 00:00:00 2001 From: Heejin Ahn Date: Fri, 26 Aug 2016 08:56:42 -0700 Subject: Fix alignment bug in .lcomm (#680) When parsing .lcomm directives, s2wasm does not parse the alignment number and skip it. This causes alignment bugs in some cases. (In the test case attached, 'buf' should be 4 bytes aligned, but it does not align it properly, so this code was generated: ``` (call $foo (i32.const 13) ) ``` 13 is not 4-bytes aligned. This patch fixes this bug. --- src/s2wasm.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/s2wasm.h b/src/s2wasm.h index 3a7cf31db..a45f3aab4 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -1328,11 +1328,12 @@ class S2WasmBuilder { mustMatch(name.str); skipComma(); Address size = getInt(); + Address localAlign = 1; if (*s == ',') { skipComma(); - getInt(); + localAlign = 1 << getInt(); } - linkerObj->addStatic(size, align, name); + linkerObj->addStatic(size, std::max(align, localAlign), name); } void skipImports() { -- cgit v1.2.3