Skip to content

[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

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/BinaryFormat/Wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Object/WasmObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/Object/Wasm/data-offsets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# RUN: yaml2obj %s | llvm-objdump -s -

## Tests data offsets above 2**31 for I32_CONST and offset over 2**32 work for I64_CONST

--- !WASM
FileHeader:
Version: 0x00000001
Sections:
- Type: DATA
Segments:
- SectionOffset: 0
InitFlags: 0
Offset:
Opcode: I32_CONST
Value: 2147483649
Content: '6401020304'
- SectionOffset: 0
InitFlags: 0
Offset:
Opcode: I64_CONST
Value: 4294967297
Content: '6401020304'
4 changes: 2 additions & 2 deletions llvm/test/ObjectYAML/wasm/global_section.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Sections:
Mutable: false
InitExpr:
Opcode: I64_CONST
Value: -5
Value: 5
...
# CHECK: --- !WASM
# CHECK: FileHeader:
Expand All @@ -23,5 +23,5 @@ Sections:
# CHECK: Mutable: false
# CHECK: InitExpr:
# CHECK: Opcode: I64_CONST
# CHECK: Value: -5
# CHECK: Value: 5
# CHECK: ...
18 changes: 18 additions & 0 deletions llvm/test/ObjectYAML/wasm/invalidate_data_offset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# RUN: not yaml2obj %s 2>&1 | FileCheck %s

## Tests data offsets above 2**32 are not valid for for I32_CONST

--- !WASM
FileHeader:
Version: 0x00000001
Sections:
- Type: DATA
Segments:
- SectionOffset: 0
InitFlags: 0
Offset:
Opcode: I32_CONST
Value: 4294967297
Content: '6401020304'

# CHECK: error: out of range number