diff options
-rw-r--r-- | src/s2wasm.h | 17 | ||||
-rw-r--r-- | test/dot_s/relocation.wast | 16 |
2 files changed, 31 insertions, 2 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h index a1805e659..45f12fdb7 100644 --- a/src/s2wasm.h +++ b/src/s2wasm.h @@ -34,9 +34,13 @@ private: size_t nextStatic = 1; // location of next static allocation, i.e., the data segment std::map<Name, int32_t> staticAddresses; // name => address + typedef std::pair<Const*, Name> Addressing; std::vector<Addressing> addressings; // we fix these up + typedef std::pair<std::vector<char>*, Name> Relocation; // the data, and the name whose address we should place there + std::vector<Relocation> relocations; + // utilities void skipWhitespace() { @@ -771,7 +775,12 @@ private: } } else if (match(".int32")) { raw->resize(4); - (*(int32_t*)(&(*raw)[0])) = getInt(); + if (isdigit(*s)) { + (*(int32_t*)(&(*raw)[0])) = getInt(); + } else { + // relocation, the address of something + relocations.emplace_back(raw, getStr()); + } } else if (match(".int64")) { raw->resize(8); (*(int64_t*)(&(*raw)[0])) = getInt(); @@ -808,8 +817,12 @@ private: assert(curr->value.i32 > 0); curr->type = i32; } + for (auto& pair : relocations) { + auto raw = pair.first; + auto name = pair.second; + (*(int32_t*)(&(*raw)[0])) = staticAddresses[name]; + } } - }; } // namespace wasm diff --git a/test/dot_s/relocation.wast b/test/dot_s/relocation.wast new file mode 100644 index 000000000..8949247bc --- /dev/null +++ b/test/dot_s/relocation.wast @@ -0,0 +1,16 @@ +(module + (memory 0 4294967295 (segment 2 "\06\00\00\00") (segment 6 "\02\00\00\00")) + (export "main" $main) + (func $main (result i32) + (local $$0 i32) + (block $fake_return_waka123 + (block + (br $fake_return_waka123 + (i32.load align=4 + (i32.const 0) + ) + ) + ) + ) + ) +) |