summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/tools/wasm-merge.cpp2
-rw-r--r--src/wasm-binary.h6
-rw-r--r--src/wasm/wasm-binary.cpp33
-rw-r--r--src/wasm/wasm.cpp2
4 files changed, 34 insertions, 9 deletions
diff --git a/src/tools/wasm-merge.cpp b/src/tools/wasm-merge.cpp
index 6c7bd46af..e8910860e 100644
--- a/src/tools/wasm-merge.cpp
+++ b/src/tools/wasm-merge.cpp
@@ -106,7 +106,7 @@ struct Mergeable {
}
}
for (auto& section : wasm.userSections) {
- if (section.name == "dylink") {
+ if (section.name == BinaryConsts::UserSections::Dylink) {
WasmBinaryBuilder builder(wasm, section.data, false);
totalMemorySize = std::max(totalMemorySize, builder.getU32LEB());
totalTableSize = std::max(totalTableSize, builder.getU32LEB());
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 487979b3a..a1155f684 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -340,6 +340,8 @@ namespace UserSections {
extern const char* Name;
extern const char* SourceMapUrl;
+extern const char* Dylink;
+
enum Subsection {
NameFunction = 1,
NameLocal = 2,
@@ -713,7 +715,9 @@ public:
void writeNames();
void writeSourceMapUrl();
void writeSymbolMap();
- void writeUserSections();
+ void writeEarlyUserSections();
+ void writeLateUserSections();
+ void writeUserSection(const UserSection& section);
void writeSourceMapProlog();
void writeSourceMapEpilog();
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index c6d1a6a60..a7bc9c91e 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -39,6 +39,9 @@ void WasmBinaryWriter::prepare() {
void WasmBinaryWriter::write() {
writeHeader();
+
+ writeEarlyUserSections();
+
if (sourceMap) {
writeSourceMapProlog();
}
@@ -62,7 +65,7 @@ void WasmBinaryWriter::write() {
writeSourceMapEpilog();
}
- writeUserSections();
+ writeLateUserSections();
finishUp();
}
@@ -535,17 +538,33 @@ void WasmBinaryWriter::writeSourceMapEpilog() {
*sourceMap << "\"}";
}
-void WasmBinaryWriter::writeUserSections() {
+void WasmBinaryWriter::writeEarlyUserSections() {
+ // The dylink section must be the first in the module, per
+ // the spec, to allow simple parsing by loaders.
for (auto& section : wasm->userSections) {
- auto start = startSection(0);
- writeInlineString(section.name.c_str());
- for (size_t i = 0; i < section.data.size(); i++) {
- o << uint8_t(section.data[i]);
+ if (section.name == BinaryConsts::UserSections::Dylink) {
+ writeUserSection(section);
}
- finishSection(start);
}
}
+void WasmBinaryWriter::writeLateUserSections() {
+ for (auto& section : wasm->userSections) {
+ if (section.name != BinaryConsts::UserSections::Dylink) {
+ writeUserSection(section);
+ }
+ }
+}
+
+void WasmBinaryWriter::writeUserSection(const UserSection& section) {
+ auto start = startSection(0);
+ writeInlineString(section.name.c_str());
+ for (size_t i = 0; i < section.data.size(); i++) {
+ o << uint8_t(section.data[i]);
+ }
+ finishSection(start);
+}
+
void WasmBinaryWriter::writeDebugLocation(Expression* curr, Function* func) {
auto& debugLocations = func->debugLocations;
auto iter = debugLocations.find(curr);
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index d88ab0fcd..433803772 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -29,6 +29,8 @@ namespace BinaryConsts {
namespace UserSections {
const char* Name = "name";
const char* SourceMapUrl = "sourceMappingURL";
+
+const char* Dylink = "dylink";
}
}