Skip to content

Commit 5becae6

Browse files
authored
Reland emitting of DataCount section (#2027)
This reverts commit cb2d635. The issues with feature validation were mostly resolved in #1993, and this PR finishes the job by adding feature flags to wasm-as to avoid emitting the DataCount section when bulk-memory is not enabled.
1 parent 9233afc commit 5becae6

5 files changed

Lines changed: 23 additions & 13 deletions

File tree

auto_update_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def update_bin_fmt_tests():
155155
for wast in sorted(os.listdir('test')):
156156
if wast.endswith('.wast') and wast not in []: # blacklist some known failures
157157
for debug_info in [0, 1]:
158-
cmd = WASM_AS + [os.path.join('test', wast), '-o', 'a.wasm']
158+
cmd = WASM_AS + [os.path.join('test', wast), '-o', 'a.wasm', '-all']
159159
if debug_info:
160160
cmd += ['-g']
161161
print ' '.join(cmd)

scripts/test/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def binary_format_check(wast, verify_final_result=True, wasm_as_args=['-g'],
384384
# checks we can convert the wast to binary and back
385385

386386
print ' (binary format check)'
387-
cmd = WASM_AS + [wast, '-o', 'a.wasm'] + wasm_as_args
387+
cmd = WASM_AS + [wast, '-o', 'a.wasm', '-all'] + wasm_as_args
388388
print ' ', ' '.join(cmd)
389389
if os.path.exists('a.wasm'):
390390
os.unlink('a.wasm')

src/tools/wasm-as.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
//
2020

2121
#include "support/colors.h"
22-
#include "support/command-line.h"
2322
#include "support/file.h"
2423
#include "wasm-io.h"
2524
#include "wasm-s-parser.h"
2625
#include "wasm-validator.h"
2726

27+
#include "tool-options.h"
2828
#include "tool-utils.h"
2929

3030
using namespace cashew;
@@ -35,7 +35,7 @@ int main(int argc, const char *argv[]) {
3535
std::string symbolMap;
3636
std::string sourceMapFilename;
3737
std::string sourceMapUrl;
38-
Options options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)");
38+
ToolOptions options("wasm-as", "Assemble a .wast (WebAssembly text format) into a .wasm (WebAssembly binary format)");
3939
options.extra["validate"] = "wasm";
4040
options
4141
.add("--output", "-o", "Output file (stdout if not specified)",
@@ -91,7 +91,7 @@ int main(int argc, const char *argv[]) {
9191
Fatal() << "error in parsing input";
9292
}
9393

94-
wasm.features = FeatureSet::All;
94+
options.applyFeatures(wasm);
9595

9696
if (options.extra["validate"] != "none") {
9797
if (options.debug) std::cerr << "Validating..." << std::endl;

src/wasm/wasm-binary.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,9 @@ void WasmBinaryWriter::writeDataCount() {
317317
if (!wasm->features.hasBulkMemory() || !wasm->memory.segments.size()) {
318318
return;
319319
}
320-
321-
// TODO(tlively): re-enable writing the data count once the default feature
322-
// set is no longer All, which causes validation errors in Emscripten due to
323-
// the presence of an unrecognized section.
324-
325-
// auto start = startSection(BinaryConsts::Section::DataCount);
326-
// o << U32LEB(wasm->memory.segments.size());
327-
// finishSection(start);
320+
auto start = startSection(BinaryConsts::Section::DataCount);
321+
o << U32LEB(wasm->memory.segments.size());
322+
finishSection(start);
328323
}
329324

330325
void WasmBinaryWriter::writeDataSegments() {

test/unit/test_datacount.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from scripts.test.shared import WASM_OPT, run_process
2+
from utils import BinaryenTestCase
3+
4+
5+
class DataCountTest(BinaryenTestCase):
6+
def test_datacount(self):
7+
self.roundtrip('bulkmem_data.wasm')
8+
9+
def test_bad_datacount(self):
10+
path = self.input_path('bulkmem_bad_datacount.wasm')
11+
p = run_process(WASM_OPT + ['-g', '-o', '-', path], check=False,
12+
capture_output=True)
13+
self.assertNotEqual(p.returncode, 0)
14+
self.assertIn('Number of segments does not agree with DataCount section',
15+
p.stderr)

0 commit comments

Comments
 (0)