diff options
author | Dominic Chen <d.c.ddcc@gmail.com> | 2016-07-13 09:03:35 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2016-07-13 09:03:35 -0700 |
commit | 1a07fc4cc4f729b116d41e6ea4a6a22207af53b8 (patch) | |
tree | 57af95c5753e61c44aa8dac9847fe79850ab65f9 | |
parent | a5e2d3a40690e2a258e7e7b13edd6ba37230a7de (diff) | |
download | binaryen-1a07fc4cc4f729b116d41e6ea4a6a22207af53b8.tar.gz binaryen-1a07fc4cc4f729b116d41e6ea4a6a22207af53b8.tar.bz2 binaryen-1a07fc4cc4f729b116d41e6ea4a6a22207af53b8.zip |
Handle aliases without size (e.g. weak symbol), add redefinition warnings (#630)
-rw-r--r-- | src/s2wasm.h | 19 | ||||
-rw-r--r-- | src/wasm-linker.cpp | 1 | ||||
-rw-r--r-- | test/dot_s/alias.s | 16 |
3 files changed, 18 insertions, 18 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 8f429f96c..8595bdb44 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -391,7 +391,8 @@ class S2WasmBuilder { } else if (match("=")) { Name alias = getAtSeparated(); mustMatch("@FUNCTION"); - info->aliasedSymbols.insert({name, LinkerObject::SymbolAlias(alias, LinkerObject::Relocation::kFunction, 0)}); + auto ret = info->aliasedSymbols.insert({name, LinkerObject::SymbolAlias(alias, LinkerObject::Relocation::kFunction, 0)}); + if (!ret.second) std::cerr << "Unsupported data alias redefinition: " << name << ", skipping...\n"; } else { abort_on("unknown directive"); } @@ -412,15 +413,6 @@ class S2WasmBuilder { s++; offset = getInt(); } - skipWhitespace(); - - // get the data size - mustMatch(".size"); - mustMatch(lhs.str); - mustMatch(","); - wasm::Address size = atoi(getStr().str); - WASM_UNUSED(size); - skipWhitespace(); // check if the rhs is already an alias const auto alias = symbolInfo->aliasedSymbols.find(rhs); @@ -430,8 +422,9 @@ class S2WasmBuilder { } // add the new alias - symbolInfo->aliasedSymbols.insert({lhs, LinkerObject::SymbolAlias(rhs, + auto ret = symbolInfo->aliasedSymbols.insert({lhs, LinkerObject::SymbolAlias(rhs, LinkerObject::Relocation::kData, offset)}); + if (!ret.second) std::cerr << "Unsupported function alias redefinition: " << lhs << ", skipping...\n"; } } } @@ -470,7 +463,9 @@ class S2WasmBuilder { WASM_UNUSED(rhs); skipWhitespace(); - mustMatch(".size"); + // if no size attribute (e.g. weak symbol), skip + if (!match(".size")) return; + mustMatch(lhs.str); mustMatch(","); Name size = getStr(); diff --git a/src/wasm-linker.cpp b/src/wasm-linker.cpp index a2e88cfb3..628e24ecc 100644 --- a/src/wasm-linker.cpp +++ b/src/wasm-linker.cpp @@ -123,6 +123,7 @@ void Linker::layout() { } }; for (auto& relocation : out.relocations) { + // TODO: Handle weak symbols properly, instead of always taking the weak definition. auto *alias = out.getAlias(relocation->symbol, relocation->kind); Name name = relocation->symbol; diff --git a/test/dot_s/alias.s b/test/dot_s/alias.s index 449e33f0e..121f3fc53 100644 --- a/test/dot_s/alias.s +++ b/test/dot_s/alias.s @@ -5,9 +5,9 @@ .globl __exit .type __exit,@function __exit: # @__exit - i32.const $push0=, _A + i32.const $push0=, _B i32.load $push1=, 0($pop0) - i32.const $push2=, ._B + i32.const $push2=, ._C i32.load $push3=, 0($pop2) i32.add $push4=, $pop1, $pop3 # BB#0: # %entry @@ -42,7 +42,11 @@ __exit_needed = __exit@FUNCTION .int32 2345 .size .L__unnamed_1, 12 -_A = .L__unnamed_1 - .size _A, 12 -._B = _A+8 - .size ._B, 4 + .weak .A +._A = .L__unname_1 + .weak ._B +_B = .L__unnamed_1 + .size _B, 12 + .weak ._C +._C = _B+8 + .size ._C, 4 |