summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/tool-options.h1
-rw-r--r--src/wasm-binary.h1
-rw-r--r--src/wasm-features.h13
-rw-r--r--src/wasm/wasm-binary.cpp11
-rw-r--r--src/wasm/wasm-type.cpp13
-rw-r--r--src/wasm/wasm-validator.cpp19
-rw-r--r--src/wasm/wasm.cpp1
-rw-r--r--test/binaryen.js/kitchen-sink.js.txt2
-rw-r--r--test/example/c-api-kitchen-sink.txt2
-rw-r--r--test/lit/help/wasm-as.test4
-rw-r--r--test/lit/help/wasm-ctor-eval.test4
-rw-r--r--test/lit/help/wasm-dis.test4
-rw-r--r--test/lit/help/wasm-emscripten-finalize.test4
-rw-r--r--test/lit/help/wasm-merge.test4
-rw-r--r--test/lit/help/wasm-metadce.test4
-rw-r--r--test/lit/help/wasm-opt.test5
-rw-r--r--test/lit/help/wasm-reduce.test4
-rw-r--r--test/lit/help/wasm-split.test4
-rw-r--r--test/lit/help/wasm2js.test5
-rw-r--r--test/lit/validation/shared-struct.wast12
-rw-r--r--test/passes/strip-target-features_roundtrip_print-features_all-features.txt1
-rw-r--r--test/unit/test_features.py1
22 files changed, 111 insertions, 8 deletions
diff --git a/src/tools/tool-options.h b/src/tools/tool-options.h
index 599b3b22c..10a03acc7 100644
--- a/src/tools/tool-options.h
+++ b/src/tools/tool-options.h
@@ -94,6 +94,7 @@ struct ToolOptions : public Options {
.addFeature(FeatureSet::Strings, "strings")
.addFeature(FeatureSet::MultiMemory, "multimemory")
.addFeature(FeatureSet::TypedContinuations, "typed continuations")
+ .addFeature(FeatureSet::SharedEverything, "shared-everything threads")
.add("--enable-typed-function-references",
"",
"Deprecated compatibility flag",
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index 71de2f915..ebfc27b1f 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -428,6 +428,7 @@ extern const char* ExtendedConstFeature;
extern const char* StringsFeature;
extern const char* MultiMemoryFeature;
extern const char* TypedContinuationsFeature;
+extern const char* SharedEverythingFeature;
enum Subsection {
NameModule = 0,
diff --git a/src/wasm-features.h b/src/wasm-features.h
index 2ace67c27..cda3ce447 100644
--- a/src/wasm-features.h
+++ b/src/wasm-features.h
@@ -45,11 +45,12 @@ struct FeatureSet {
Strings = 1 << 14,
MultiMemory = 1 << 15,
TypedContinuations = 1 << 16,
+ SharedEverything = 1 << 17,
MVP = None,
// Keep in sync with llvm default features:
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
Default = SignExt | MutableGlobals,
- All = (1 << 17) - 1,
+ All = (1 << 18) - 1,
};
static std::string toString(Feature f) {
@@ -88,6 +89,8 @@ struct FeatureSet {
return "multimemory";
case TypedContinuations:
return "typed-continuations";
+ case SharedEverything:
+ return "shared-everything";
default:
WASM_UNREACHABLE("unexpected feature");
}
@@ -135,6 +138,9 @@ struct FeatureSet {
bool hasTypedContinuations() const {
return (features & TypedContinuations) != 0;
}
+ bool hasSharedEverything() const {
+ return (features & SharedEverything) != 0;
+ }
bool hasAll() const { return (features & All) != 0; }
void set(FeatureSet f, bool v = true) {
@@ -157,6 +163,7 @@ struct FeatureSet {
void setStrings(bool v = true) { set(Strings, v); }
void setMultiMemory(bool v = true) { set(MultiMemory, v); }
void setTypedContinuations(bool v = true) { set(TypedContinuations, v); }
+ void setSharedEverything(bool v = true) { set(SharedEverything, v); }
void setMVP() { features = MVP; }
void setAll() { features = All; }
@@ -186,6 +193,10 @@ struct FeatureSet {
return *this;
}
+ FeatureSet operator-(FeatureSet& other) const {
+ return features & ~other.features;
+ }
+
uint32_t features;
};
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index 32dcc883a..7b88bdd76 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -1319,9 +1319,14 @@ void WasmBinaryWriter::writeFeaturesSection() {
return BinaryConsts::CustomSections::MultiMemoryFeature;
case FeatureSet::TypedContinuations:
return BinaryConsts::CustomSections::TypedContinuationsFeature;
- default:
- WASM_UNREACHABLE("unexpected feature flag");
+ case FeatureSet::SharedEverything:
+ return BinaryConsts::CustomSections::SharedEverythingFeature;
+ case FeatureSet::None:
+ case FeatureSet::Default:
+ case FeatureSet::All:
+ break;
}
+ WASM_UNREACHABLE("unexpected feature flag");
};
std::vector<const char*> features;
@@ -3825,6 +3830,8 @@ void WasmBinaryReader::readFeatures(size_t payloadLen) {
} else if (name ==
BinaryConsts::CustomSections::TypedContinuationsFeature) {
feature = FeatureSet::TypedContinuations;
+ } else if (name == BinaryConsts::CustomSections::SharedEverythingFeature) {
+ feature = FeatureSet::SharedEverything;
} else {
// Silently ignore unknown features (this may be and old binaryen running
// on a new wasm).
diff --git a/src/wasm/wasm-type.cpp b/src/wasm/wasm-type.cpp
index 83bf47107..532ebb913 100644
--- a/src/wasm/wasm-type.cpp
+++ b/src/wasm/wasm-type.cpp
@@ -932,10 +932,17 @@ FeatureSet Type::getFeatures() const {
}
}
- if (heapType->isStruct() || heapType->isArray() ||
- heapType->getRecGroup().size() > 1 ||
+ if (heapType->getRecGroup().size() > 1 ||
heapType->getDeclaredSuperType() || heapType->isOpen()) {
feats |= FeatureSet::ReferenceTypes | FeatureSet::GC;
+ }
+
+ if (heapType->isShared()) {
+ feats |= FeatureSet::SharedEverything;
+ }
+
+ if (heapType->isStruct() || heapType->isArray()) {
+ feats |= FeatureSet::ReferenceTypes | FeatureSet::GC;
} else if (heapType->isSignature()) {
// This is a function reference, which requires reference types and
// possibly also multivalue (if it has multiple returns). Note that
@@ -969,7 +976,7 @@ FeatureSet Type::getFeatures() const {
collector.noteChild(&heapType);
return collector.feats;
}
- TODO_SINGLE_COMPOUND(t);
+
switch (t.getBasic()) {
case Type::v128:
return FeatureSet::SIMD;
diff --git a/src/wasm/wasm-validator.cpp b/src/wasm/wasm-validator.cpp
index 689872a19..f8bd08e1d 100644
--- a/src/wasm/wasm-validator.cpp
+++ b/src/wasm/wasm-validator.cpp
@@ -3701,6 +3701,25 @@ static void validateGlobals(Module& module, ValidationInfo& info) {
seen.insert(curr);
}
});
+
+ // Check that globals have allowed types.
+ for (auto& g : module.globals) {
+ auto globalFeats = g->type.getFeatures();
+ if (!info.shouldBeTrue(globalFeats <= module.features, g->name, "")) {
+ auto& stream = info.getStream(nullptr);
+ stream << "global type requires additional features [";
+ bool first = true;
+ (globalFeats - module.features).iterFeatures([&](FeatureSet feat) {
+ if (first) {
+ first = false;
+ } else {
+ stream << " ";
+ }
+ stream << "--enable-" << feat.toString();
+ });
+ stream << "]\n";
+ }
+ }
}
static void validateMemories(Module& module, ValidationInfo& info) {
diff --git a/src/wasm/wasm.cpp b/src/wasm/wasm.cpp
index cae413397..ed05e9b47 100644
--- a/src/wasm/wasm.cpp
+++ b/src/wasm/wasm.cpp
@@ -54,6 +54,7 @@ const char* ExtendedConstFeature = "extended-const";
const char* StringsFeature = "strings";
const char* MultiMemoryFeature = "multimemory";
const char* TypedContinuationsFeature = "typed-continuations";
+const char* SharedEverythingFeature = "shared-everything";
} // namespace CustomSections
} // namespace BinaryConsts
diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt
index a3e88703e..28922c2a0 100644
--- a/test/binaryen.js/kitchen-sink.js.txt
+++ b/test/binaryen.js/kitchen-sink.js.txt
@@ -33,7 +33,7 @@ Features.RelaxedSIMD: 4096
Features.ExtendedConst: 8192
Features.Strings: 16384
Features.MultiMemory: 32768
-Features.All: 131071
+Features.All: 262143
InvalidId: 0
BlockId: 1
IfId: 2
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 7231ded9a..d79b34e66 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -47,7 +47,7 @@ BinaryenFeatureMemory64: 2048
BinaryenFeatureRelaxedSIMD: 4096
BinaryenFeatureExtendedConst: 8192
BinaryenFeatureStrings: 16384
-BinaryenFeatureAll: 131071
+BinaryenFeatureAll: 262143
(f32.neg
(f32.const -33.61199951171875)
)
diff --git a/test/lit/help/wasm-as.test b/test/lit/help/wasm-as.test
index 09e5b7c9d..114064576 100644
--- a/test/lit/help/wasm-as.test
+++ b/test/lit/help/wasm-as.test
@@ -108,6 +108,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-ctor-eval.test b/test/lit/help/wasm-ctor-eval.test
index e511ef0b9..93b5654ed 100644
--- a/test/lit/help/wasm-ctor-eval.test
+++ b/test/lit/help/wasm-ctor-eval.test
@@ -115,6 +115,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-dis.test b/test/lit/help/wasm-dis.test
index 2dffcc945..06dda9e96 100644
--- a/test/lit/help/wasm-dis.test
+++ b/test/lit/help/wasm-dis.test
@@ -101,6 +101,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-emscripten-finalize.test b/test/lit/help/wasm-emscripten-finalize.test
index a4ba48b16..1b31e1e44 100644
--- a/test/lit/help/wasm-emscripten-finalize.test
+++ b/test/lit/help/wasm-emscripten-finalize.test
@@ -143,6 +143,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-merge.test b/test/lit/help/wasm-merge.test
index c87be5edf..293bdbff0 100644
--- a/test/lit/help/wasm-merge.test
+++ b/test/lit/help/wasm-merge.test
@@ -131,6 +131,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-metadce.test b/test/lit/help/wasm-metadce.test
index f0889eb81..453328df1 100644
--- a/test/lit/help/wasm-metadce.test
+++ b/test/lit/help/wasm-metadce.test
@@ -156,6 +156,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-opt.test b/test/lit/help/wasm-opt.test
index 727d1ab21..9dd38e03e 100644
--- a/test/lit/help/wasm-opt.test
+++ b/test/lit/help/wasm-opt.test
@@ -721,6 +721,11 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything
+;; CHECK-NEXT: threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-reduce.test b/test/lit/help/wasm-reduce.test
index a98b8a199..397952855 100644
--- a/test/lit/help/wasm-reduce.test
+++ b/test/lit/help/wasm-reduce.test
@@ -137,6 +137,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm-split.test b/test/lit/help/wasm-split.test
index fcd919ea8..333864bcb 100644
--- a/test/lit/help/wasm-split.test
+++ b/test/lit/help/wasm-split.test
@@ -217,6 +217,10 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/help/wasm2js.test b/test/lit/help/wasm2js.test
index d8768f35e..72efcd223 100644
--- a/test/lit/help/wasm2js.test
+++ b/test/lit/help/wasm2js.test
@@ -675,6 +675,11 @@
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-continuations Disable typed continuations
;; CHECK-NEXT:
+;; CHECK-NEXT: --enable-shared-everything Enable shared-everything threads
+;; CHECK-NEXT:
+;; CHECK-NEXT: --disable-shared-everything Disable shared-everything
+;; CHECK-NEXT: threads
+;; CHECK-NEXT:
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
;; CHECK-NEXT:
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag
diff --git a/test/lit/validation/shared-struct.wast b/test/lit/validation/shared-struct.wast
new file mode 100644
index 000000000..ee25b6f24
--- /dev/null
+++ b/test/lit/validation/shared-struct.wast
@@ -0,0 +1,12 @@
+;; Test that shared structs require shared-everything threads
+
+;; RUN: not wasm-opt %s 2>&1 | filecheck %s --check-prefix NO-SHARED
+;; RUN: wasm-opt %s --enable-reference-types --enable-gc --enable-shared-everything -o - -S | filecheck %s --check-prefix SHARED
+
+;; NO-SHARED: global type requires additional features [--enable-reference-types --enable-gc --enable-shared-everything]
+;; SHARED: (type $t (shared (struct )))
+
+(module
+ (type $t (shared (struct)))
+ (global (import "" "") (ref null $t))
+)
diff --git a/test/passes/strip-target-features_roundtrip_print-features_all-features.txt b/test/passes/strip-target-features_roundtrip_print-features_all-features.txt
index a15210d05..2c6523e6d 100644
--- a/test/passes/strip-target-features_roundtrip_print-features_all-features.txt
+++ b/test/passes/strip-target-features_roundtrip_print-features_all-features.txt
@@ -15,6 +15,7 @@
--enable-strings
--enable-multimemory
--enable-typed-continuations
+--enable-shared-everything
(module
(type $0 (func (result v128 externref)))
(func $foo (type $0) (result v128 externref)
diff --git a/test/unit/test_features.py b/test/unit/test_features.py
index 4ce426275..3bd9ac127 100644
--- a/test/unit/test_features.py
+++ b/test/unit/test_features.py
@@ -425,4 +425,5 @@ class TargetFeaturesSectionTest(utils.BinaryenTestCase):
'--enable-strings',
'--enable-multimemory',
'--enable-typed-continuations',
+ '--enable-shared-everything',
], p2.stdout.splitlines())