Skip to content

Commit 070dfbc

Browse files
committed
[Object][WebAssembly] Fix data segment offsets higher than 2^31
Fixes: #58555
1 parent d906da5 commit 070dfbc

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

llvm/include/llvm/BinaryFormat/Wasm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ struct WasmTable {
333333
struct WasmInitExprMVP {
334334
uint8_t Opcode;
335335
union {
336-
int32_t Int32;
337-
int64_t Int64;
336+
uint32_t Int32;
337+
uint64_t Int64;
338338
uint32_t Float32;
339339
uint64_t Float64;
340340
uint32_t Global;

llvm/lib/Object/WasmObjectFile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,10 @@ static Error readInitExpr(wasm::WasmInitExpr &Expr,
201201
Expr.Inst.Opcode = readOpcode(Ctx);
202202
switch (Expr.Inst.Opcode) {
203203
case wasm::WASM_OPCODE_I32_CONST:
204-
Expr.Inst.Value.Int32 = readVarint32(Ctx);
204+
Expr.Inst.Value.Int32 = readVaruint32(Ctx);
205205
break;
206206
case wasm::WASM_OPCODE_I64_CONST:
207-
Expr.Inst.Value.Int64 = readVarint64(Ctx);
207+
Expr.Inst.Value.Int64 = readVaruint64(Ctx);
208208
break;
209209
case wasm::WASM_OPCODE_F32_CONST:
210210
Expr.Inst.Value.Float32 = readFloat32(Ctx);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# RUN: yaml2obj %s | llvm-objdump -s -
2+
3+
## Tests data offsets above 2**31
4+
5+
--- !WASM
6+
FileHeader:
7+
Version: 0x00000001
8+
Sections:
9+
- Type: DATA
10+
Segments:
11+
- SectionOffset: 0
12+
InitFlags: 0
13+
Offset:
14+
Opcode: I32_CONST
15+
Value: 2147483649
16+
Content: '6401020304'

0 commit comments

Comments
 (0)