summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2019-04-10 11:24:00 -0700
committerGitHub <noreply@github.com>2019-04-10 11:24:00 -0700
commit39eae1d5772099282af656ee2bb0ce388e2e7268 (patch)
treed72e4be3604c5922fb5bec9fed7cecdc7af279ab /src
parent85c303de41b1e0d46cb3d389512b9ab10472391e (diff)
downloadbinaryen-39eae1d5772099282af656ee2bb0ce388e2e7268.tar.gz
binaryen-39eae1d5772099282af656ee2bb0ce388e2e7268.tar.bz2
binaryen-39eae1d5772099282af656ee2bb0ce388e2e7268.zip
Handle relocatable code in AsmConstWalker (#1992)
In relocatable code the constant offset might be relative to __memory_base.
Diffstat (limited to 'src')
-rw-r--r--src/wasm/wasm-emscripten.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index 95566f5b9..1b40b871e 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -509,20 +509,33 @@ void AsmConstWalker::visitSetLocal(SetLocal* curr) {
void AsmConstWalker::visitCall(Call* curr) {
auto* import = wasm.getFunction(curr->target);
+ // Find calls to emscripten_asm_const* functions whose first argument is
+ // is always a string constant.
if (import->imported() && import->base.hasSubstring(EMSCRIPTEN_ASM_CONST)) {
auto baseSig = getSig(curr);
auto sig = fixupNameWithSig(curr->target, baseSig);
auto* arg = curr->operands[0];
- // The argument may be a get, in which case, the last set in this basic block
- // has the value.
if (auto* get = arg->dynCast<GetLocal>()) {
+ // The argument may be a local.get, in which case, the last set in this
+ // basic block has the value.
auto* set = sets[get->index];
if (set) {
assert(set->index == get->index);
arg = set->value;
}
- }
- auto* value = arg->cast<Const>();
+ } else if (auto* value = arg->dynCast<Binary>()) {
+ // In the dynamic linking case the address of the string constant
+ // is the result of adding its offset to __memory_base.
+ // In this case are only looking for the offset with the data segment so
+ // the RHS of the addition is just what we want.
+ assert(value->op == AddInt32);
+ arg = value->right;
+ }
+
+ auto* value = arg->dynCast<Const>();
+ if (!value)
+ Fatal() << "Unexpected arg0 type (" << getExpressionName(arg)
+ << ") in call to to: " << import->base;
auto code = codeForConstAddr(wasm, segmentOffsets, value);
value->value = idLiteralForCode(code);
sigsForCode[code].insert(sig);