From c4c82597aaf43d7fee3cd8877801d9dd91e33f7b Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Wed, 6 Apr 2016 15:12:14 -0700 Subject: Fix s2wasm handling of aliased functions This fixes 2 bugs in s2wasm: * Handle address-taken aliases (i.e. when they appear in relocations), by looking up and subsituting the address of the aliasee. * Skip whitespace at the top of the scan() loop instead of requiring it to match. When there are multiple alias declarations in a row, the match("FUNCTION") at the end of an alias delcaration consumes the whitespace at the beginning of the next line, causing it to fail to match the tab character specified in the match pattern at the top of the loop. --- src/s2wasm.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/s2wasm.h b/src/s2wasm.h index c85a214a1..c2e8c77a0 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -405,9 +405,10 @@ class S2WasmBuilder { void scan() { while (*s) { - s = strstr(s, "\n .type "); + skipWhitespace(); + s = strstr(s, ".type"); if (!s) break; - mustMatch("\n .type "); + mustMatch(".type"); Name name = getCommaSeparated(); skipComma(); if (!match("@function")) continue; @@ -1282,6 +1283,8 @@ class S2WasmBuilder { if (debug) std::cerr << " ==> " << *(relocation.data) << '\n'; } else { // must be a function address + auto aliased = aliasedFunctions.find(name); + if (aliased != aliasedFunctions.end()) name = aliased->second; if (!wasm.checkFunction(name)) { std::cerr << "Unknown symbol: " << name << '\n'; if (!ignoreUnknownSymbols) abort(); -- cgit v1.2.3