summaryrefslogtreecommitdiffstats
path: root/lld/wasm/Writer.cpp
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2019-03-29 20:43:49 +0000
committerThomas Lively <tlively@google.com>2019-03-29 20:43:49 +0000
commit06391f34bd4ec04a2f0e9376b99d7821185eabb2 (patch)
tree36896d9ab7d5609abc86003683dda82dc837c860 /lld/wasm/Writer.cpp
parent54f7118de5b9bd7d1b2a4b5ba1e9662c22104d91 (diff)
downloadbcm5719-llvm-06391f34bd4ec04a2f0e9376b99d7821185eabb2.tar.gz
bcm5719-llvm-06391f34bd4ec04a2f0e9376b99d7821185eabb2.zip
[WebAssembly] "atomics" feature requires shared memory
Summary: Makes it a linker error if the "atomics" feature is used but the user does not opt in to shared memory or if "atomics" is disallowed but the user does opt in to shared memory. Also check that an appropriate max memory size is supplied if shared memory is used. Reviewers: sbc100, aheejin Subscribers: dschuff, jgravelle-google, sunfish, jfb, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59281 llvm-svn: 357310
Diffstat (limited to 'lld/wasm/Writer.cpp')
-rw-r--r--lld/wasm/Writer.cpp14
1 files changed, 11 insertions, 3 deletions
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index 63e33d69962..50dc76f8e41 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -169,7 +169,7 @@ void Writer::createImportSection() {
Import.Kind = WASM_EXTERNAL_MEMORY;
Import.Memory.Flags = 0;
Import.Memory.Initial = NumMemoryPages;
- if (MaxMemoryPages != 0) {
+ if (MaxMemoryPages != 0 || Config->SharedMemory) {
Import.Memory.Flags |= WASM_LIMITS_FLAG_HAS_MAX;
Import.Memory.Maximum = MaxMemoryPages;
}
@@ -257,7 +257,7 @@ void Writer::createMemorySection() {
SyntheticSection *Section = createSyntheticSection(WASM_SEC_MEMORY);
raw_ostream &OS = Section->getStream();
- bool HasMax = MaxMemoryPages != 0;
+ bool HasMax = MaxMemoryPages != 0 || Config->SharedMemory;
writeUleb128(OS, 1, "memory count");
unsigned Flags = 0;
if (HasMax)
@@ -831,7 +831,8 @@ void Writer::layoutMemory() {
NumMemoryPages = alignTo(MemoryPtr, WasmPageSize) / WasmPageSize;
log("mem: total pages = " + Twine(NumMemoryPages));
- if (Config->MaxMemory != 0) {
+ // Check max if explicitly supplied or required by shared memory
+ if (Config->MaxMemory != 0 || Config->SharedMemory) {
if (Config->MaxMemory != alignTo(Config->MaxMemory, WasmPageSize))
error("maximum memory must be " + Twine(WasmPageSize) + "-byte aligned");
if (MemoryPtr > Config->MaxMemory)
@@ -927,9 +928,16 @@ void Writer::calculateTargetFeatures() {
if (InferFeatures)
TargetFeatures.insert(Used.begin(), Used.end());
+ if (TargetFeatures.count("atomics") && !Config->SharedMemory)
+ error("'atomics' feature is used, so --shared-memory must be used");
+
if (!Config->CheckFeatures)
return;
+ if (Disallowed.count("atomics") && Config->SharedMemory)
+ error(
+ "'atomics' feature is disallowed, so --shared-memory must not be used");
+
// Validate that used features are allowed in output
if (!InferFeatures) {
for (auto &Feature : Used) {
OpenPOWER on IntegriCloud