summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-emscripten-finalize.cpp5
-rw-r--r--src/wasm-emscripten.h5
-rw-r--r--src/wasm/wasm-emscripten.cpp3
3 files changed, 10 insertions, 3 deletions
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);