summaryrefslogtreecommitdiff
path: root/src/ir/table-utils.h
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-03-30 11:14:29 -0700
committerGitHub <noreply@github.com>2020-03-30 11:14:29 -0700
commitd8179402b3bb991f336b19bcca8ccbc60c842166 (patch)
treec70757545451aaebc75d74bede99fe5c1576d90b /src/ir/table-utils.h
parent2b758fbdc46fc8fe5241bcf1ba5bbd81e6d556ed (diff)
downloadbinaryen-d8179402b3bb991f336b19bcca8ccbc60c842166.tar.gz
binaryen-d8179402b3bb991f336b19bcca8ccbc60c842166.tar.bz2
binaryen-d8179402b3bb991f336b19bcca8ccbc60c842166.zip
Represent dylink section in IR, so we can update it. (#2715)
Update it from wasm-emscripten-finalize when we append to the table.
Diffstat (limited to 'src/ir/table-utils.h')
-rw-r--r--src/ir/table-utils.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/ir/table-utils.h b/src/ir/table-utils.h
index 3c49ab16a..e0453dece 100644
--- a/src/ir/table-utils.h
+++ b/src/ir/table-utils.h
@@ -67,10 +67,23 @@ inline Table::Segment& ensureTableWithOneSegment(Table& table, Module& wasm) {
// Appends a name to the table. This assumes the table has 0 or 1 segments,
// as with 2 or more it's ambiguous what we should do (use a hole in the middle
// or not).
+// This works on code from wasm-ld, but on arbitrary code it may not be valid
+// in the presence of a dynamic linking section. Specifically, we assume the
+// module has a single table segment, and that the dylink section indicates
+// we can validly append to that segment, see the check below.
inline Index append(Table& table, Name name, Module& wasm) {
auto& segment = ensureTableWithOneSegment(table, wasm);
- table.segments[0];
auto tableIndex = segment.data.size();
+ if (wasm.dylinkSection) {
+ if (segment.data.size() != wasm.dylinkSection->tableSize) {
+ Fatal() << "Appending to the table in a module with a dylink section "
+ "that has tableSize which indicates it wants to reserve more "
+ "table space than the actual table elements in the module. "
+ "We don't know how to correctly update the dylink section in "
+ "that case.";
+ }
+ wasm.dylinkSection->tableSize++;
+ }
segment.data.push_back(name);
table.initial = table.initial + 1;
return tableIndex;