diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-25 10:35:47 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-25 18:41:00 -0500 |
commit | a62d9e30d85cef666055a3afe33942017766b008 (patch) | |
tree | 1ba3d044b4d2b5425421babb48780f0928438ccd /src | |
parent | 49eff55076f009630c859424df932ad1e78bf33f (diff) | |
download | binaryen-a62d9e30d85cef666055a3afe33942017766b008.tar.gz binaryen-a62d9e30d85cef666055a3afe33942017766b008.tar.bz2 binaryen-a62d9e30d85cef666055a3afe33942017766b008.zip |
handle function indexes in relocations
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index 3e96c12ac..05d198bd0 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -983,6 +983,12 @@ private: } void fix() { + auto ensureFunctionIndex = [&](Name name) { + if (functionIndexes.count(name) == 0) { + functionIndexes[name] = functionIndexes.size(); + wasm.table.names.push_back(name); + } + }; for (auto& triple : addressings) { Const* curr = triple.value; Name name = triple.name; @@ -996,17 +1002,26 @@ private: std::cerr << "Unknown symbol: " << name << '\n'; abort_on("Unknown symbol"); } - if (functionIndexes.count(name) == 0) { - functionIndexes[name] = functionIndexes.size(); - wasm.table.names.push_back(name); - } + ensureFunctionIndex(name); curr->value = Literal(int32_t(functionIndexes[name] + offset)); } assert(curr->value.i32 > 0); curr->type = i32; } for (auto& relocation : relocations) { - *(relocation.data) = staticAddresses[relocation.value] + relocation.offset; + Name name = relocation.value; + const auto &symbolAddress = staticAddresses.find(name); + if (symbolAddress != staticAddresses.end()) { + *(relocation.data) = symbolAddress->second + relocation.offset; + } else { + // must be a function address + if (wasm.functionsMap.count(name) == 0) { + std::cerr << "Unknown symbol: " << name << '\n'; + abort_on("Unknown symbol"); + } + ensureFunctionIndex(name); + *(relocation.data) = functionIndexes[name] + relocation.offset; + } } } |