-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Object][WebAssembly] Fix data segment offsets higher than 2^31 #125739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-webassembly @llvm/pr-subscribers-llvm-binary-utilities Author: Sam Clegg (sbc100) ChangesFixes: #58555 Full diff: https://github.com/llvm/llvm-project/pull/125739.diff 3 Files Affected:
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h
index ede2d692a594916..30271be232ca773 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -333,8 +333,8 @@ struct WasmTable {
struct WasmInitExprMVP {
uint8_t Opcode;
union {
- int32_t Int32;
- int64_t Int64;
+ uint32_t Int32;
+ uint64_t Int64;
uint32_t Float32;
uint64_t Float64;
uint32_t Global;
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 0f6fd5612f9d82a..7815c2670223198 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -201,10 +201,10 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr,
Expr.Inst.Opcode = readOpcode(Ctx);
switch (Expr.Inst.Opcode) {
case wasm::WASM_OPCODE_I32_CONST:
- Expr.Inst.Value.Int32 = readVarint32(Ctx);
+ Expr.Inst.Value.Int32 = readVaruint32(Ctx);
break;
case wasm::WASM_OPCODE_I64_CONST:
- Expr.Inst.Value.Int64 = readVarint64(Ctx);
+ Expr.Inst.Value.Int64 = readVaruint64(Ctx);
break;
case wasm::WASM_OPCODE_F32_CONST:
Expr.Inst.Value.Float32 = readFloat32(Ctx);
diff --git a/llvm/test/Object/Wasm/data-offsets.yaml b/llvm/test/Object/Wasm/data-offsets.yaml
new file mode 100644
index 000000000000000..26b2be2b78f5323
--- /dev/null
+++ b/llvm/test/Object/Wasm/data-offsets.yaml
@@ -0,0 +1,16 @@
+# RUN: yaml2obj %s | llvm-objdump -s -
+
+## Tests data offsets above 2**31
+
+--- !WASM
+FileHeader:
+ Version: 0x00000001
+Sections:
+ - Type: DATA
+ Segments:
+ - SectionOffset: 0
+ InitFlags: 0
+ Offset:
+ Opcode: I32_CONST
+ Value: 2147483649
+ Content: '6401020304'
|
For wasm64, could there be offsets higher than 2^32? Or are those just speced to be varint64? |
Yup, that should work. Do you want me to add a testing for that? |
070dfbc
to
3addae9
Compare
Yeah, that seems like we should have that if we don't already. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
otherwise LGTM
5ad5c02
to
82bcfcf
Compare
…31 (llvm#125739)" (llvm#125786) This reverts commit c798a5c. This broke bunch of test the emscripten side. Reverting while we investigate.
Fixes: #58555