| ... | @@ -207,7 +207,7 @@ missing_exports: std.AutoArrayHashMapUnmanaged(String, void) = .empty, | ... | @@ -207,7 +207,7 @@ missing_exports: std.AutoArrayHashMapUnmanaged(String, void) = .empty, |
| 207 | entry_resolution: FunctionImport.Resolution = .unresolved, | 207 | entry_resolution: FunctionImport.Resolution = .unresolved, |
| 208 | | 208 | |
| 209 | /// Empty when outputting an object. | 209 | /// Empty when outputting an object. |
| 210 | function_exports: std.ArrayListUnmanaged(FunctionExport) = .empty, | 210 | function_exports: std.AutoArrayHashMapUnmanaged(String, FunctionIndex) = .empty, |
| 211 | /// Tracks the value at the end of prelink. | 211 | /// Tracks the value at the end of prelink. |
| 212 | function_exports_len: u32 = 0, | 212 | function_exports_len: u32 = 0, |
| 213 | global_exports: std.ArrayListUnmanaged(GlobalExport) = .empty, | 213 | global_exports: std.ArrayListUnmanaged(GlobalExport) = .empty, |
| ... | @@ -353,8 +353,13 @@ pub const FunctionIndex = enum(u32) { | ... | @@ -353,8 +353,13 @@ pub const FunctionIndex = enum(u32) { |
| 353 | } | 353 | } |
| 354 | | 354 | |
| 355 | pub fn fromSymbolName(wasm: *const Wasm, name: String) ?FunctionIndex { | 355 | pub fn fromSymbolName(wasm: *const Wasm, name: String) ?FunctionIndex { |
| 356 | const import = wasm.object_function_imports.getPtr(name) orelse return null; | 356 | if (wasm.object_function_imports.getPtr(name)) |import| { |
| 357 | return fromResolution(wasm, import.resolution); | 357 | return fromResolution(wasm, import.resolution); |
| | 358 | } |
| | 359 | if (wasm.function_exports.get(name)) |index| { |
| | 360 | return index; |
| | 361 | } |
| | 362 | return null; |
| 358 | } | 363 | } |
| 359 | | 364 | |
| 360 | pub fn fromResolution(wasm: *const Wasm, resolution: FunctionImport.Resolution) ?FunctionIndex { | 365 | pub fn fromResolution(wasm: *const Wasm, resolution: FunctionImport.Resolution) ?FunctionIndex { |
| ... | @@ -363,11 +368,6 @@ pub const FunctionIndex = enum(u32) { | ... | @@ -363,11 +368,6 @@ pub const FunctionIndex = enum(u32) { |
| 363 | } | 368 | } |
| 364 | }; | 369 | }; |
| 365 | | 370 | |
| 366 | pub const FunctionExport = extern struct { | | |
| 367 | name: String, | | |
| 368 | function_index: FunctionIndex, | | |
| 369 | }; | | |
| 370 | | | |
| 371 | pub const GlobalExport = extern struct { | 371 | pub const GlobalExport = extern struct { |
| 372 | name: String, | 372 | name: String, |
| 373 | global_index: GlobalIndex, | 373 | global_index: GlobalIndex, |
| ... | @@ -386,7 +386,7 @@ pub const OutputFunctionIndex = enum(u32) { | ... | @@ -386,7 +386,7 @@ pub const OutputFunctionIndex = enum(u32) { |
| 386 | } | 386 | } |
| 387 | | 387 | |
| 388 | pub fn fromFunctionIndex(wasm: *const Wasm, index: FunctionIndex) OutputFunctionIndex { | 388 | pub fn fromFunctionIndex(wasm: *const Wasm, index: FunctionIndex) OutputFunctionIndex { |
| 389 | return @enumFromInt(wasm.function_imports.entries.len + @intFromEnum(index)); | 389 | return @enumFromInt(wasm.flush_buffer.function_imports.entries.len + @intFromEnum(index)); |
| 390 | } | 390 | } |
| 391 | | 391 | |
| 392 | pub fn fromObjectFunction(wasm: *const Wasm, index: ObjectFunctionIndex) OutputFunctionIndex { | 392 | pub fn fromObjectFunction(wasm: *const Wasm, index: ObjectFunctionIndex) OutputFunctionIndex { |
| ... | @@ -410,8 +410,7 @@ pub const OutputFunctionIndex = enum(u32) { | ... | @@ -410,8 +410,7 @@ pub const OutputFunctionIndex = enum(u32) { |
| 410 | return switch (ip.indexToKey(ip_index)) { | 410 | return switch (ip.indexToKey(ip_index)) { |
| 411 | .@"extern" => |ext| { | 411 | .@"extern" => |ext| { |
| 412 | const name = wasm.getExistingString(ext.name.toSlice(ip)).?; | 412 | const name = wasm.getExistingString(ext.name.toSlice(ip)).?; |
| 413 | if (wasm.function_imports.getIndex(name)) |i| return @enumFromInt(i); | 413 | return fromSymbolName(wasm, name); |
| 414 | return fromFunctionIndex(wasm, FunctionIndex.fromSymbolName(wasm, name).?); | | |
| 415 | }, | 414 | }, |
| 416 | else => fromResolution(wasm, .fromIpIndex(wasm, ip_index)).?, | 415 | else => fromResolution(wasm, .fromIpIndex(wasm, ip_index)).?, |
| 417 | }; | 416 | }; |
| ... | @@ -3424,7 +3423,7 @@ pub fn prelink(wasm: *Wasm, prog_node: std.Progress.Node) link.File.FlushError!v | ... | @@ -3424,7 +3423,7 @@ pub fn prelink(wasm: *Wasm, prog_node: std.Progress.Node) link.File.FlushError!v |
| 3424 | } | 3423 | } |
| 3425 | } | 3424 | } |
| 3426 | wasm.functions_end_prelink = @intCast(wasm.functions.entries.len); | 3425 | wasm.functions_end_prelink = @intCast(wasm.functions.entries.len); |
| 3427 | wasm.function_exports_len = @intCast(wasm.function_exports.items.len); | 3426 | wasm.function_exports_len = @intCast(wasm.function_exports.entries.len); |
| 3428 | | 3427 | |
| 3429 | for (wasm.object_global_imports.keys(), wasm.object_global_imports.values(), 0..) |name, *import, i| { | 3428 | for (wasm.object_global_imports.keys(), wasm.object_global_imports.values(), 0..) |name, *import, i| { |
| 3430 | if (import.flags.isIncluded(rdynamic)) { | 3429 | if (import.flags.isIncluded(rdynamic)) { |
| ... | @@ -3498,10 +3497,8 @@ fn markFunction(wasm: *Wasm, i: ObjectFunctionIndex) link.File.FlushError!void { | ... | @@ -3498,10 +3497,8 @@ fn markFunction(wasm: *Wasm, i: ObjectFunctionIndex) link.File.FlushError!void { |
| 3498 | const function = i.ptr(wasm); | 3497 | const function = i.ptr(wasm); |
| 3499 | markObject(wasm, function.object_index); | 3498 | markObject(wasm, function.object_index); |
| 3500 | | 3499 | |
| 3501 | if (!is_obj and function.flags.isExported(rdynamic)) try wasm.function_exports.append(gpa, .{ | 3500 | if (!is_obj and function.flags.isExported(rdynamic)) |
| 3502 | .name = function.name.unwrap().?, | 3501 | try wasm.function_exports.put(gpa, function.name.unwrap().?, @enumFromInt(gop.index)); |
| 3503 | .function_index = @enumFromInt(gop.index), | | |
| 3504 | }); | | |
| 3505 | | 3502 | |
| 3506 | try wasm.markRelocations(function.relocations(wasm)); | 3503 | try wasm.markRelocations(function.relocations(wasm)); |
| 3507 | } | 3504 | } |