| ... | ... | @@ -140,7 +140,7 @@ pub const ScratchSpace = struct { |
| 140 | 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 | 144 | return &ss.func_imports.items[@intFromEnum(index)]; |
| 145 | 145 | } |
| 146 | 146 | }; |
| ... | ... | @@ -351,10 +351,13 @@ pub fn parse( |
| 351 | 351 | .function => { |
| 352 | 352 | const local_index, pos = readLeb(u32, bytes, pos); |
| 353 | 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 | 356 | if (symbol.flags.explicit_name) { |
| 356 | 357 | const name, pos = readBytes(bytes, pos); |
| 357 | 358 | symbol.name = (try wasm.internString(name)).toOptional(); |
| 359 | } else { |
| 360 | symbol.name = function_import.ptr(ss).name.toOptional(); |
| 358 | 361 | } |
| 359 | 362 | } else { |
| 360 | 363 | symbol.pointee = .{ .function = @enumFromInt(functions_start + local_index) }; |
| ... | ... | @@ -365,10 +368,13 @@ pub fn parse( |
| 365 | 368 | .global => { |
| 366 | 369 | const local_index, pos = readLeb(u32, bytes, pos); |
| 367 | 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 | 373 | if (symbol.flags.explicit_name) { |
| 370 | 374 | const name, pos = readBytes(bytes, pos); |
| 371 | 375 | symbol.name = (try wasm.internString(name)).toOptional(); |
| 376 | } else { |
| 377 | symbol.name = global_import.key(wasm).toOptional(); |
| 372 | 378 | } |
| 373 | 379 | } else { |
| 374 | 380 | symbol.pointee = .{ .global = @enumFromInt(globals_start + local_index) }; |
| ... | ... | @@ -380,10 +386,13 @@ pub fn parse( |
| 380 | 386 | table_count += 1; |
| 381 | 387 | const local_index, pos = readLeb(u32, bytes, pos); |
| 382 | 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 | 391 | if (symbol.flags.explicit_name) { |
| 385 | 392 | const name, pos = readBytes(bytes, pos); |
| 386 | 393 | symbol.name = (try wasm.internString(name)).toOptional(); |
| 394 | } else { |
| 395 | symbol.name = table_import.key(wasm).toOptional(); |
| 387 | 396 | } |
| 388 | 397 | } else { |
| 389 | 398 | symbol.pointee = .{ .table = @enumFromInt(tables_start + local_index) }; |
| ... | ... | @@ -439,10 +448,39 @@ pub fn parse( |
| 439 | 448 | .MEMORY_ADDR_TLS_SLEB, |
| 440 | 449 | .MEMORY_ADDR_LOCREL_I32, |
| 441 | 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 | 472 | .FUNCTION_OFFSET_I32, |
| 443 | | .SECTION_OFFSET_I32, |
| 444 | 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 | 484 | const addend: i32, pos = readLeb(i32, bytes, pos); |
| 447 | 485 | wasm.object_relocations.appendAssumeCapacity(.{ |
| 448 | 486 | .tag = tag, |