summaryrefslogtreecommitdiff
path: root/src/wasm/wasm-binary.cpp
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2020-03-30 11:14:29 -0700
committerGitHub <noreply@github.com>2020-03-30 11:14:29 -0700
commitd8179402b3bb991f336b19bcca8ccbc60c842166 (patch)
treec70757545451aaebc75d74bede99fe5c1576d90b /src/wasm/wasm-binary.cpp
parent2b758fbdc46fc8fe5241bcf1ba5bbd81e6d556ed (diff)
downloadbinaryen-d8179402b3bb991f336b19bcca8ccbc60c842166.tar.gz
binaryen-d8179402b3bb991f336b19bcca8ccbc60c842166.tar.bz2
binaryen-d8179402b3bb991f336b19bcca8ccbc60c842166.zip
Represent dylink section in IR, so we can update it. (#2715)
Update it from wasm-emscripten-finalize when we append to the table.
Diffstat (limited to 'src/wasm/wasm-binary.cpp')
-rw-r--r--src/wasm/wasm-binary.cpp56
1 files changed, 43 insertions, 13 deletions
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 8d9696aa2..c36789828 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -38,7 +38,7 @@ void WasmBinaryWriter::prepare() {
void WasmBinaryWriter::write() {
writeHeader();
- writeEarlyUserSections();
+ writeDylinkSection();
initializeDebugInfo();
if (sourceMap) {
@@ -632,16 +632,6 @@ void WasmBinaryWriter::writeSourceMapEpilog() {
*sourceMap << "\"}";
}
-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) {
- if (section.name == BinaryConsts::UserSections::Dylink) {
- writeUserSection(section);
- }
- }
-}
-
void WasmBinaryWriter::writeLateUserSections() {
for (auto& section : wasm->userSections) {
if (section.name != BinaryConsts::UserSections::Dylink) {
@@ -707,6 +697,24 @@ void WasmBinaryWriter::writeFeaturesSection() {
finishSection(start);
}
+void WasmBinaryWriter::writeDylinkSection() {
+ if (!wasm->dylinkSection) {
+ return;
+ }
+
+ auto start = startSection(BinaryConsts::User);
+ writeInlineString(BinaryConsts::UserSections::Dylink);
+ o << U32LEB(wasm->dylinkSection->memorySize);
+ o << U32LEB(wasm->dylinkSection->memoryAlignment);
+ o << U32LEB(wasm->dylinkSection->tableSize);
+ o << U32LEB(wasm->dylinkSection->tableAlignment);
+ o << U32LEB(wasm->dylinkSection->neededDynlibs.size());
+ for (auto& neededDynlib : wasm->dylinkSection->neededDynlibs) {
+ writeInlineString(neededDynlib.c_str());
+ }
+ finishSection(start);
+}
+
void WasmBinaryWriter::writeDebugLocation(const Function::DebugLocation& loc) {
if (loc == lastDebugLocation) {
return;
@@ -963,6 +971,8 @@ void WasmBinaryBuilder::readUserSection(size_t payloadLen) {
readNames(payloadLen);
} else if (sectionName.equals(BinaryConsts::UserSections::TargetFeatures)) {
readFeatures(payloadLen);
+ } else if (sectionName.equals(BinaryConsts::UserSections::Dylink)) {
+ readDylink(payloadLen);
} else {
// an unfamiliar custom section
if (sectionName.equals(BinaryConsts::UserSections::Linking)) {
@@ -2122,8 +2132,8 @@ void WasmBinaryBuilder::readFeatures(size_t payloadLen) {
wasm.features = FeatureSet::MVP;
auto sectionPos = pos;
- size_t num_feats = getU32LEB();
- for (size_t i = 0; i < num_feats; ++i) {
+ size_t numFeatures = getU32LEB();
+ for (size_t i = 0; i < numFeatures; ++i) {
uint8_t prefix = getInt8();
if (prefix != BinaryConsts::FeatureUsed) {
if (prefix == BinaryConsts::FeatureRequired) {
@@ -2171,6 +2181,26 @@ void WasmBinaryBuilder::readFeatures(size_t payloadLen) {
}
}
+void WasmBinaryBuilder::readDylink(size_t payloadLen) {
+ wasm.dylinkSection = make_unique<DylinkSection>();
+
+ auto sectionPos = pos;
+
+ wasm.dylinkSection->memorySize = getU32LEB();
+ wasm.dylinkSection->memoryAlignment = getU32LEB();
+ wasm.dylinkSection->tableSize = getU32LEB();
+ wasm.dylinkSection->tableAlignment = getU32LEB();
+
+ size_t numNeededDynlibs = getU32LEB();
+ for (size_t i = 0; i < numNeededDynlibs; ++i) {
+ wasm.dylinkSection->neededDynlibs.push_back(getInlineString());
+ }
+
+ if (pos != sectionPos + payloadLen) {
+ throwError("bad features section size");
+ }
+}
+
BinaryConsts::ASTNodes WasmBinaryBuilder::readExpression(Expression*& curr) {
if (pos == endOfFunction) {
throwError("Reached function end without seeing End opcode");