summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@users.noreply.github.com>2016-08-26 08:56:42 -0700
committerGitHub <noreply@github.com>2016-08-26 08:56:42 -0700
commit2cb8b275caf090bf56cc78424aaa97766cd02fb6 (patch)
treec01c751c22a76a670e76a30cf0af0cd8e0901902
parente168e2b9b6dd099c97c7ec313c3062d80fa1a9a8 (diff)
downloadbinaryen-2cb8b275caf090bf56cc78424aaa97766cd02fb6.tar.gz
binaryen-2cb8b275caf090bf56cc78424aaa97766cd02fb6.tar.bz2
binaryen-2cb8b275caf090bf56cc78424aaa97766cd02fb6.zip
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.
-rw-r--r--src/s2wasm.h5
-rw-r--r--test/dot_s/local_align.s26
-rw-r--r--test/dot_s/local_align.wast14
3 files changed, 43 insertions, 2 deletions
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() {
diff --git a/test/dot_s/local_align.s b/test/dot_s/local_align.s
new file mode 100644
index 000000000..0a8d5bc98
--- /dev/null
+++ b/test/dot_s/local_align.s
@@ -0,0 +1,26 @@
+ .text
+ .file "local_align.bc"
+ .type foo,@function
+foo:
+ .param i32
+ .endfunc
+.Lfunc_end0:
+ .size foo, .Lfunc_end0-foo
+
+ .hidden main
+ .globl main
+ .type main,@function
+main:
+ .result i32
+ i32.const $push0=, buf
+ call foo@FUNCTION, $pop0
+ i32.const $push1=, 0
+ .endfunc
+.Lfunc_end1:
+ .size main, .Lfunc_end1-main
+
+ .type temp,@object
+ .lcomm temp,1,1
+
+ .type buf,@object
+ .lcomm buf,156,4
diff --git a/test/dot_s/local_align.wast b/test/dot_s/local_align.wast
new file mode 100644
index 000000000..85900cbed
--- /dev/null
+++ b/test/dot_s/local_align.wast
@@ -0,0 +1,14 @@
+(module
+ (memory 1)
+ (export "memory" memory)
+ (export "main" $main)
+ (func $foo (param $0 i32)
+ )
+ (func $main (result i32)
+ (call $foo
+ (i32.const 16)
+ )
+ (i32.const 0)
+ )
+)
+;; METADATA: { "asmConsts": {},"staticBump": 172, "initializers": [] }