diff options
author | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 16:10:24 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2015-12-14 16:10:24 -0800 |
commit | 4a6a88ae8387c9db99acda5b4fb1d2bff999a8a0 (patch) | |
tree | 16f3e2cdf0ba3226119b1513cef7348aedc23cc2 /src | |
parent | 0b41a7d99f7652d607b14897e2ee963b28b6916e (diff) | |
download | binaryen-4a6a88ae8387c9db99acda5b4fb1d2bff999a8a0.tar.gz binaryen-4a6a88ae8387c9db99acda5b4fb1d2bff999a8a0.tar.bz2 binaryen-4a6a88ae8387c9db99acda5b4fb1d2bff999a8a0.zip |
add relocation support
Diffstat (limited to 'src')
-rw-r--r-- | src/s2wasm.h | 17 |
1 files changed, 15 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 |