summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xauto_update_tests.py2
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp5
-rw-r--r--src/wasm-emscripten.h5
-rw-r--r--src/wasm/wasm-emscripten.cpp3
-rw-r--r--test/lld/em_asm.wast.mem.membin652 -> 84 bytes
-rw-r--r--test/lld/hello_world.wast.mem.membin581 -> 13 bytes
6 files changed, 11 insertions, 4 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py
index bef6a8908..f37019f3f 100755
--- a/auto_update_tests.py
+++ b/auto_update_tests.py
@@ -80,7 +80,7 @@ def update_lld_tests():
extension_arg_map = {
'.out': [],
'.jscall.out': ['--emscripten-reserved-function-pointers=3'],
- '.mem.out': ['--separate-data-segments', mem_file],
+ '.mem.out': ['--separate-data-segments', mem_file + '.mem'],
}
for ext, ext_args in extension_arg_map.items():
out_path = wast_path + ext
diff --git a/src/tools/wasm-emscripten-finalize.cpp b/src/tools/wasm-emscripten-finalize.cpp
index f2c74221d..42fc1e4db 100644
--- a/src/tools/wasm-emscripten-finalize.cpp
+++ b/src/tools/wasm-emscripten-finalize.cpp
@@ -224,7 +224,10 @@ int main(int argc, const char *argv[]) {
// for metadata).
if (!dataSegmentFile.empty()) {
Output memInitFile(dataSegmentFile, Flags::Binary, Flags::Release);
- generator.separateDataSegments(&memInitFile);
+ if (globalBase == INVALID_BASE) {
+ Fatal() << "globalBase must be set";
+ }
+ generator.separateDataSegments(&memInitFile, globalBase);
}
if (options.debug) {
diff --git a/src/wasm-emscripten.h b/src/wasm-emscripten.h
index d078cafbf..275c809fd 100644
--- a/src/wasm-emscripten.h
+++ b/src/wasm-emscripten.h
@@ -57,7 +57,10 @@ public:
void fixInvokeFunctionNames();
- void separateDataSegments(Output* outfile);
+ // Emits the data segments to a file. The file contains data from address base
+ // onwards (we must pass in base, as we can't tell it from the wasm - the first
+ // segment may start after a run of zeros, but we need those zeros in the file).
+ void separateDataSegments(Output* outfile, Address base);
private:
Module& wasm;
diff --git a/src/wasm/wasm-emscripten.cpp b/src/wasm/wasm-emscripten.cpp
index e09ad98d2..a383a812a 100644
--- a/src/wasm/wasm-emscripten.cpp
+++ b/src/wasm/wasm-emscripten.cpp
@@ -919,10 +919,11 @@ std::string EmscriptenGlueGenerator::generateEmscriptenMetadata(
return meta.str();
}
-void EmscriptenGlueGenerator::separateDataSegments(Output* outfile) {
+void EmscriptenGlueGenerator::separateDataSegments(Output* outfile, Address base) {
size_t lastEnd = 0;
for (Memory::Segment& seg : wasm.memory.segments) {
size_t offset = seg.offset->cast<Const>()->value.geti32();
+ offset -= base;
size_t fill = offset - lastEnd;
if (fill > 0) {
std::vector<char> buf(fill);
diff --git a/test/lld/em_asm.wast.mem.mem b/test/lld/em_asm.wast.mem.mem
index 1e5476727..9249eb195 100644
--- a/test/lld/em_asm.wast.mem.mem
+++ b/test/lld/em_asm.wast.mem.mem
Binary files differ
diff --git a/test/lld/hello_world.wast.mem.mem b/test/lld/hello_world.wast.mem.mem
index 674c410a9..2bc1f1ee6 100644
--- a/test/lld/hello_world.wast.mem.mem
+++ b/test/lld/hello_world.wast.mem.mem
Binary files differ