| ... | @@ -140,7 +140,7 @@ pub const ScratchSpace = struct { | ... | @@ -140,7 +140,7 @@ pub const ScratchSpace = struct { |
| 140 | const FuncImportIndex = enum(u32) { | 140 | const FuncImportIndex = enum(u32) { |
| 141 | _, | 141 | _, |
| 142 | | 142 | |
| 143 | fn ptr(index: FunctionImport, ss: *const ScratchSpace) *FunctionImport { | 143 | fn ptr(index: FuncImportIndex, ss: *const ScratchSpace) *FunctionImport { |
| 144 | return &ss.func_imports.items[@intFromEnum(index)]; | 144 | return &ss.func_imports.items[@intFromEnum(index)]; |
| 145 | } | 145 | } |
| 146 | }; | 146 | }; |
| ... | @@ -351,10 +351,13 @@ pub fn parse( | ... | @@ -351,10 +351,13 @@ pub fn parse( |
| 351 | .function => { | 351 | .function => { |
| 352 | const local_index, pos = readLeb(u32, bytes, pos); | 352 | const local_index, pos = readLeb(u32, bytes, pos); |
| 353 | if (symbol.flags.undefined) { | 353 | if (symbol.flags.undefined) { |
| 354 | symbol.pointee = .{ .function_import = @enumFromInt(local_index) }; | 354 | const function_import: ScratchSpace.FuncImportIndex = @enumFromInt(local_index); |
| | 355 | symbol.pointee = .{ .function_import = function_import }; |
| 355 | if (symbol.flags.explicit_name) { | 356 | if (symbol.flags.explicit_name) { |
| 356 | const name, pos = readBytes(bytes, pos); | 357 | const name, pos = readBytes(bytes, pos); |
| 357 | symbol.name = (try wasm.internString(name)).toOptional(); | 358 | symbol.name = (try wasm.internString(name)).toOptional(); |
| | 359 | } else { |
| | 360 | symbol.name = function_import.ptr(ss).name.toOptional(); |
| 358 | } | 361 | } |
| 359 | } else { | 362 | } else { |
| 360 | symbol.pointee = .{ .function = @enumFromInt(functions_start + local_index) }; | 363 | symbol.pointee = .{ .function = @enumFromInt(functions_start + local_index) }; |
| ... | @@ -365,10 +368,13 @@ pub fn parse( | ... | @@ -365,10 +368,13 @@ pub fn parse( |
| 365 | .global => { | 368 | .global => { |
| 366 | const local_index, pos = readLeb(u32, bytes, pos); | 369 | const local_index, pos = readLeb(u32, bytes, pos); |
| 367 | if (symbol.flags.undefined) { | 370 | if (symbol.flags.undefined) { |
| 368 | symbol.pointee = .{ .global_import = @enumFromInt(global_imports_start + local_index) }; | 371 | const global_import: Wasm.GlobalImport.Index = @enumFromInt(global_imports_start + local_index); |
| | 372 | symbol.pointee = .{ .global_import = global_import }; |
| 369 | if (symbol.flags.explicit_name) { | 373 | if (symbol.flags.explicit_name) { |
| 370 | const name, pos = readBytes(bytes, pos); | 374 | const name, pos = readBytes(bytes, pos); |
| 371 | symbol.name = (try wasm.internString(name)).toOptional(); | 375 | symbol.name = (try wasm.internString(name)).toOptional(); |
| | 376 | } else { |
| | 377 | symbol.name = global_import.key(wasm).toOptional(); |
| 372 | } | 378 | } |
| 373 | } else { | 379 | } else { |
| 374 | symbol.pointee = .{ .global = @enumFromInt(globals_start + local_index) }; | 380 | symbol.pointee = .{ .global = @enumFromInt(globals_start + local_index) }; |
| ... | @@ -380,10 +386,13 @@ pub fn parse( | ... | @@ -380,10 +386,13 @@ pub fn parse( |
| 380 | table_count += 1; | 386 | table_count += 1; |
| 381 | const local_index, pos = readLeb(u32, bytes, pos); | 387 | const local_index, pos = readLeb(u32, bytes, pos); |
| 382 | if (symbol.flags.undefined) { | 388 | if (symbol.flags.undefined) { |
| 383 | symbol.pointee = .{ .table_import = @enumFromInt(table_imports_start + local_index) }; | 389 | const table_import: Wasm.TableImport.Index = @enumFromInt(table_imports_start + local_index); |
| | 390 | symbol.pointee = .{ .table_import = table_import }; |
| 384 | if (symbol.flags.explicit_name) { | 391 | if (symbol.flags.explicit_name) { |
| 385 | const name, pos = readBytes(bytes, pos); | 392 | const name, pos = readBytes(bytes, pos); |
| 386 | symbol.name = (try wasm.internString(name)).toOptional(); | 393 | symbol.name = (try wasm.internString(name)).toOptional(); |
| | 394 | } else { |
| | 395 | symbol.name = table_import.key(wasm).toOptional(); |
| 387 | } | 396 | } |
| 388 | } else { | 397 | } else { |
| 389 | symbol.pointee = .{ .table = @enumFromInt(tables_start + local_index) }; | 398 | symbol.pointee = .{ .table = @enumFromInt(tables_start + local_index) }; |
| ... | @@ -439,10 +448,39 @@ pub fn parse( | ... | @@ -439,10 +448,39 @@ pub fn parse( |
| 439 | .MEMORY_ADDR_TLS_SLEB, | 448 | .MEMORY_ADDR_TLS_SLEB, |
| 440 | .MEMORY_ADDR_LOCREL_I32, | 449 | .MEMORY_ADDR_LOCREL_I32, |
| 441 | .MEMORY_ADDR_TLS_SLEB64, | 450 | .MEMORY_ADDR_TLS_SLEB64, |
| | 451 | => { |
| | 452 | const addend: i32, pos = readLeb(i32, bytes, pos); |
| | 453 | const sym_section = ss.symbol_table.items[index].pointee.data; |
| | 454 | if (sym_section.segment_offset != 0) { |
| | 455 | return diags.failParse(path, "data symbol {d} has nonzero offset {d}", .{ |
| | 456 | index, sym_section.segment_offset, |
| | 457 | }); |
| | 458 | } |
| | 459 | const seg_size = sym_section.segment_index.ptr(wasm).payload.len; |
| | 460 | if (sym_section.size != seg_size) { |
| | 461 | return diags.failParse(path, "data symbol {d} has size {d}, inequal to corresponding data segment {d} size {d}", .{ |
| | 462 | index, sym_section.size, @intFromEnum(sym_section.segment_index), seg_size, |
| | 463 | }); |
| | 464 | } |
| | 465 | wasm.object_relocations.appendAssumeCapacity(.{ |
| | 466 | .tag = tag, |
| | 467 | .offset = offset, |
| | 468 | .pointee = .{ .data_segment = sym_section.segment_index }, |
| | 469 | .addend = addend, |
| | 470 | }); |
| | 471 | }, |
| 442 | .FUNCTION_OFFSET_I32, | 472 | .FUNCTION_OFFSET_I32, |
| 443 | .SECTION_OFFSET_I32, | | |
| 444 | .FUNCTION_OFFSET_I64, | 473 | .FUNCTION_OFFSET_I64, |
| 445 | => { | 474 | => { |
| | 475 | const addend: i32, pos = readLeb(i32, bytes, pos); |
| | 476 | wasm.object_relocations.appendAssumeCapacity(.{ |
| | 477 | .tag = tag, |
| | 478 | .offset = offset, |
| | 479 | .pointee = .{ .function = ss.symbol_table.items[index].pointee.function }, |
| | 480 | .addend = addend, |
| | 481 | }); |
| | 482 | }, |
| | 483 | .SECTION_OFFSET_I32 => { |
| 446 | const addend: i32, pos = readLeb(i32, bytes, pos); | 484 | const addend: i32, pos = readLeb(i32, bytes, pos); |
| 447 | wasm.object_relocations.appendAssumeCapacity(.{ | 485 | wasm.object_relocations.appendAssumeCapacity(.{ |
| 448 | .tag = tag, | 486 | .tag = tag, |