summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/s2wasm.h19
-rw-r--r--test/dot_s/vtable.wast2
-rw-r--r--test/s2wasm_known_gcc_test_failures.txt1
3 files changed, 17 insertions, 5 deletions
diff --git a/src/s2wasm.h b/src/s2wasm.h
index 74387859e..b7682788a 100644
--- a/src/s2wasm.h
+++ b/src/s2wasm.h
@@ -182,9 +182,12 @@ private:
return ret;
}
- void getConst(uint32_t* target) {
+ // gets a constant, which may be a relocation for later.
+ // returns whether this is a relocation
+ bool getConst(uint32_t* target) {
if (isdigit(*s)) {
*target = getInt();
+ return false;
} else {
// a global constant, we need to fix it up later
Name name = getStrToSep();
@@ -194,6 +197,7 @@ private:
offset = getInt();
}
relocations.emplace_back(target, name, offset);
+ return true;
}
}
@@ -889,6 +893,7 @@ private:
mustMatch(":");
auto raw = new std::vector<char>(); // leaked intentionally, no new allocation in Memory
bool zero = true;
+ std::vector<std::pair<size_t, size_t>> currRelocations; // [index in relocations, offset in raw]
while (1) {
skipWhitespace();
if (match(".asci")) {
@@ -924,7 +929,9 @@ private:
} else if (match(".int32")) {
size_t size = raw->size();
raw->resize(size + 4);
- getConst((uint32_t*)&(*raw)[size]);
+ if (getConst((uint32_t*)&(*raw)[size])) { // just the size, as we may reallocate; we must fix this later, if it's a relocation
+ currRelocations.emplace_back(relocations.size()-1, size);
+ }
zero = false;
} else if (match(".int64")) {
size_t size = raw->size();
@@ -947,8 +954,14 @@ private:
}
size = seenSize;
}
- while (nextStatic % align) nextStatic++;
+ // raw is now finalized, prepare relocations
+ for (auto& curr : currRelocations) {
+ auto r = curr.first;
+ auto i = curr.second;
+ relocations[r].data = (uint32_t*)&(*raw)[i];
+ }
// assign the address, add to memory
+ while (nextStatic % align) nextStatic++;
staticAddresses[name] = nextStatic;
if (!zero) {
addressSegments[nextStatic] = wasm.memory.segments.size();
diff --git a/test/dot_s/vtable.wast b/test/dot_s/vtable.wast
index bf4a08a54..e578ae7d0 100644
--- a/test/dot_s/vtable.wast
+++ b/test/dot_s/vtable.wast
@@ -1,5 +1,5 @@
(module
- (memory 0 4294967295 (segment 16 "1A\00") (segment 32 "1B\00") (segment 48 "1C\00") (segment 64 "1D\00") (segment 68 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 88 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 108 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 128 "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 152 "\00\00\00\00\10\00\00\00") (segment 160 "\00\00\00\00\00\00\00\00\98\00\00\00") (segment 176 "\00\00\00\00\00\00\00\00\98\00\00\00") (segment 192 "\00\00\00\00\00\00\00\00\a0\00\00\00") (segment 204 "\00\00\00\00"))
+ (memory 0 4294967295 (segment 16 "1A\00") (segment 32 "1B\00") (segment 48 "1C\00") (segment 64 "1D\00") (segment 68 "\00\00\00\00\98\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 88 "\00\00\00\00\a0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 108 "\00\00\00\00\b0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 128 "\00\00\00\00\c0\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00") (segment 152 "\00\00\00\00\10\00\00\00") (segment 160 "\00\00\00\00 \00\00\00\98\00\00\00") (segment 176 "\00\00\00\000\00\00\00\98\00\00\00") (segment 192 "\00\00\00\00@\00\00\00\a0\00\00\00") (segment 204 "\00\00\00\00"))
(import $_ZdlPv "env" "_ZdlPv")
(export "_ZN1A3fooEv" $_ZN1A3fooEv)
(export "_ZN1B3fooEv" $_ZN1B3fooEv)
diff --git a/test/s2wasm_known_gcc_test_failures.txt b/test/s2wasm_known_gcc_test_failures.txt
index dd55aa628..99aefa6c0 100644
--- a/test/s2wasm_known_gcc_test_failures.txt
+++ b/test/s2wasm_known_gcc_test_failures.txt
@@ -44,7 +44,6 @@ strncmp-1.c.s
struct-cpy-1.c.s
# No output, it just fails.
-20050929-1.c.s
pr35800.c.s
# Something about alignment?