| ... | @@ -151,7 +151,11 @@ uav_fixups: std.ArrayListUnmanaged(UavFixup) = .empty, | ... | @@ -151,7 +151,11 @@ uav_fixups: std.ArrayListUnmanaged(UavFixup) = .empty, |
| 151 | /// List of locations within `string_bytes` that must be patched with the virtual | 151 | /// List of locations within `string_bytes` that must be patched with the virtual |
| 152 | /// memory address of a Nav during `flush`. | 152 | /// memory address of a Nav during `flush`. |
| 153 | /// When emitting an object file, `out_relocs` is used instead. | 153 | /// When emitting an object file, `out_relocs` is used instead. |
| | 154 | /// No functions here only global variables. |
| 154 | nav_fixups: std.ArrayListUnmanaged(NavFixup) = .empty, | 155 | nav_fixups: std.ArrayListUnmanaged(NavFixup) = .empty, |
| | 156 | /// When a nav reference is a function pointer, this tracks the required function |
| | 157 | /// table entry index that needs to overwrite the code in the final output. |
| | 158 | func_table_fixups: std.ArrayListUnmanaged(FuncTableFixup) = .empty, |
| 155 | /// Symbols to be emitted into an object file. Remains empty when not emitting | 159 | /// Symbols to be emitted into an object file. Remains empty when not emitting |
| 156 | /// an object file. | 160 | /// an object file. |
| 157 | symbol_table: std.AutoArrayHashMapUnmanaged(String, void) = .empty, | 161 | symbol_table: std.AutoArrayHashMapUnmanaged(String, void) = .empty, |
| ... | @@ -307,6 +311,12 @@ pub const NavFixup = extern struct { | ... | @@ -307,6 +311,12 @@ pub const NavFixup = extern struct { |
| 307 | offset: u32, | 311 | offset: u32, |
| 308 | }; | 312 | }; |
| 309 | | 313 | |
| | 314 | pub const FuncTableFixup = extern struct { |
| | 315 | table_index: ZcuIndirectFunctionSetIndex, |
| | 316 | /// Index into `string_bytes`. |
| | 317 | offset: u32, |
| | 318 | }; |
| | 319 | |
| 310 | /// Index into `objects`. | 320 | /// Index into `objects`. |
| 311 | pub const ObjectIndex = enum(u32) { | 321 | pub const ObjectIndex = enum(u32) { |
| 312 | _, | 322 | _, |
| ... | @@ -2208,7 +2218,7 @@ pub const FunctionImportId = enum(u32) { | ... | @@ -2208,7 +2218,7 @@ pub const FunctionImportId = enum(u32) { |
| 2208 | pub fn pack(unpacked: Unpacked, wasm: *const Wasm) FunctionImportId { | 2218 | pub fn pack(unpacked: Unpacked, wasm: *const Wasm) FunctionImportId { |
| 2209 | return switch (unpacked) { | 2219 | return switch (unpacked) { |
| 2210 | .object_function_import => |i| @enumFromInt(@intFromEnum(i)), | 2220 | .object_function_import => |i| @enumFromInt(@intFromEnum(i)), |
| 2211 | .zcu_import => |i| @enumFromInt(@intFromEnum(i) - wasm.object_function_imports.entries.len), | 2221 | .zcu_import => |i| @enumFromInt(@intFromEnum(i) + wasm.object_function_imports.entries.len), |
| 2212 | }; | 2222 | }; |
| 2213 | } | 2223 | } |
| 2214 | | 2224 | |
| ... | @@ -2295,7 +2305,7 @@ pub const GlobalImportId = enum(u32) { | ... | @@ -2295,7 +2305,7 @@ pub const GlobalImportId = enum(u32) { |
| 2295 | pub fn pack(unpacked: Unpacked, wasm: *const Wasm) GlobalImportId { | 2305 | pub fn pack(unpacked: Unpacked, wasm: *const Wasm) GlobalImportId { |
| 2296 | return switch (unpacked) { | 2306 | return switch (unpacked) { |
| 2297 | .object_global_import => |i| @enumFromInt(@intFromEnum(i)), | 2307 | .object_global_import => |i| @enumFromInt(@intFromEnum(i)), |
| 2298 | .zcu_import => |i| @enumFromInt(@intFromEnum(i) - wasm.object_global_imports.entries.len), | 2308 | .zcu_import => |i| @enumFromInt(@intFromEnum(i) + wasm.object_global_imports.entries.len), |
| 2299 | }; | 2309 | }; |
| 2300 | } | 2310 | } |
| 2301 | | 2311 | |
| ... | @@ -2360,7 +2370,7 @@ pub const DataImportId = enum(u32) { | ... | @@ -2360,7 +2370,7 @@ pub const DataImportId = enum(u32) { |
| 2360 | pub fn pack(unpacked: Unpacked, wasm: *const Wasm) DataImportId { | 2370 | pub fn pack(unpacked: Unpacked, wasm: *const Wasm) DataImportId { |
| 2361 | return switch (unpacked) { | 2371 | return switch (unpacked) { |
| 2362 | .object_data_import => |i| @enumFromInt(@intFromEnum(i)), | 2372 | .object_data_import => |i| @enumFromInt(@intFromEnum(i)), |
| 2363 | .zcu_import => |i| @enumFromInt(@intFromEnum(i) - wasm.object_data_imports.entries.len), | 2373 | .zcu_import => |i| @enumFromInt(@intFromEnum(i) + wasm.object_data_imports.entries.len), |
| 2364 | }; | 2374 | }; |
| 2365 | } | 2375 | } |
| 2366 | | 2376 | |
| ... | @@ -3027,6 +3037,7 @@ pub fn deinit(wasm: *Wasm) void { | ... | @@ -3027,6 +3037,7 @@ pub fn deinit(wasm: *Wasm) void { |
| 3027 | wasm.out_relocs.deinit(gpa); | 3037 | wasm.out_relocs.deinit(gpa); |
| 3028 | wasm.uav_fixups.deinit(gpa); | 3038 | wasm.uav_fixups.deinit(gpa); |
| 3029 | wasm.nav_fixups.deinit(gpa); | 3039 | wasm.nav_fixups.deinit(gpa); |
| | 3040 | wasm.func_table_fixups.deinit(gpa); |
| 3030 | | 3041 | |
| 3031 | wasm.zcu_indirect_function_set.deinit(gpa); | 3042 | wasm.zcu_indirect_function_set.deinit(gpa); |
| 3032 | wasm.object_indirect_function_import_set.deinit(gpa); | 3043 | wasm.object_indirect_function_import_set.deinit(gpa); |