From 992cf17563f09a41222f28b64ddf554f5c81ff3c Mon Sep 17 00:00:00 2001 From: Derek Schuff Date: Tue, 6 Nov 2018 17:27:25 +0000 Subject: [PATCH] [WebAssembly] Add shared memory support to limits field Support the IS_SHARED bit in the memory limits flag word. The compiler does not create object files with memory definitions, but the field is used by the linker. Differential Revision: https://reviews.llvm.org/D54131 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@346246 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/BinaryFormat/Wasm.h | 1 + lib/Object/WasmObjectFile.cpp | 2 +- lib/ObjectYAML/WasmYAML.cpp | 1 + .../ObjectYAML/wasm/import_memory_shared.yaml | 36 +++++++++++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/ObjectYAML/wasm/import_memory_shared.yaml diff --git a/include/llvm/BinaryFormat/Wasm.h b/include/llvm/BinaryFormat/Wasm.h index 44dd92ea901..3d25c9d15e4 100644 --- a/include/llvm/BinaryFormat/Wasm.h +++ b/include/llvm/BinaryFormat/Wasm.h @@ -214,6 +214,7 @@ enum : unsigned { enum : unsigned { WASM_LIMITS_FLAG_HAS_MAX = 0x1, + WASM_LIMITS_FLAG_IS_SHARED = 0x2, }; // Kind codes used in the custom "name" section diff --git a/lib/Object/WasmObjectFile.cpp b/lib/Object/WasmObjectFile.cpp index 75925a5ea10..3bd66f9375f 100644 --- a/lib/Object/WasmObjectFile.cpp +++ b/lib/Object/WasmObjectFile.cpp @@ -193,7 +193,7 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr, static wasm::WasmLimits readLimits(WasmObjectFile::ReadContext &Ctx) { wasm::WasmLimits Result; - Result.Flags = readVaruint1(Ctx); + Result.Flags = readVaruint32(Ctx); Result.Initial = readVaruint32(Ctx); if (Result.Flags & wasm::WASM_LIMITS_FLAG_HAS_MAX) Result.Maximum = readVaruint32(Ctx); diff --git a/lib/ObjectYAML/WasmYAML.cpp b/lib/ObjectYAML/WasmYAML.cpp index 2e7a1d6f653..dba950af589 100644 --- a/lib/ObjectYAML/WasmYAML.cpp +++ b/lib/ObjectYAML/WasmYAML.cpp @@ -416,6 +416,7 @@ void ScalarBitSetTraits::bitset( IO &IO, WasmYAML::LimitFlags &Value) { #define BCase(X) IO.bitSetCase(Value, #X, wasm::WASM_LIMITS_FLAG_##X) BCase(HAS_MAX); + BCase(IS_SHARED); #undef BCase } diff --git a/test/ObjectYAML/wasm/import_memory_shared.yaml b/test/ObjectYAML/wasm/import_memory_shared.yaml new file mode 100644 index 00000000000..849bdc5314d --- /dev/null +++ b/test/ObjectYAML/wasm/import_memory_shared.yaml @@ -0,0 +1,36 @@ +# RUN: yaml2obj %s | obj2yaml | FileCheck %s +--- !WASM +FileHeader: + Version: 0x00000001 +Sections: + - Type: TYPE + Signatures: + - Index: 0 + ReturnType: I32 + ParamTypes: + - I32 + - Type: IMPORT + Imports: + - Module: foo + Field: imported_memory + Kind: MEMORY + Memory: + Flags: [ HAS_MAX, IS_SHARED ] + Initial: 0x00000010 + Maximum: 0x00000011 + +... +# CHECK: --- !WASM +# CHECK: FileHeader: +# CHECK: Version: 0x00000001 +# CHECK: Sections: +# CHECK: - Type: IMPORT +# CHECK: Imports: +# CHECK: - Module: foo +# CHECK: Field: imported_memory +# CHECK: Kind: MEMORY +# CHECK: Memory: +# CHECK: Flags: [ HAS_MAX, IS_SHARED ] +# CHECK: Initial: 0x00000010 +# CHECK: Maximum: 0x00000011 +# CHECK: ...