| ... | @@ -79,6 +79,7 @@ growable_table: bool, | ... | @@ -79,6 +79,7 @@ growable_table: bool, |
| 79 | name: []const u8, | 79 | name: []const u8, |
| 80 | /// List of relocatable files to be linked into the final binary. | 80 | /// List of relocatable files to be linked into the final binary. |
| 81 | objects: std.ArrayList(Object) = .empty, | 81 | objects: std.ArrayList(Object) = .empty, |
| | 82 | archive_builder: Archive.Builder = .{}, |
| 82 | | 83 | |
| 83 | func_types: std.array_hash_map.Auto(FunctionType, void) = .empty, | 84 | func_types: std.array_hash_map.Auto(FunctionType, void) = .empty, |
| 84 | /// Provides a mapping of both imports and provided functions to symbol name. | 85 | /// Provides a mapping of both imports and provided functions to symbol name. |
| ... | @@ -467,8 +468,7 @@ pub const OutputDataIndex = enum(u32) { | ... | @@ -467,8 +468,7 @@ pub const OutputDataIndex = enum(u32) { |
| 467 | } | 468 | } |
| 468 | | 469 | |
| 469 | pub fn fromUav(wasm: *const Wasm, ip_index: InternPool.Index) OutputDataIndex { | 470 | pub fn fromUav(wasm: *const Wasm, ip_index: InternPool.Index) OutputDataIndex { |
| 470 | const comp = wasm.base.comp; | 471 | const resolution: ObjectDataImport.Resolution = if (wasm.base.isRelocatable()) |
| 471 | const resolution: ObjectDataImport.Resolution = if (comp.config.output_mode == .Obj) | | |
| 472 | .pack(wasm, .{ .uav_obj = @fromBackingInt(@intCast(wasm.uavs_obj.getIndex(ip_index).?)) }) | 472 | .pack(wasm, .{ .uav_obj = @fromBackingInt(@intCast(wasm.uavs_obj.getIndex(ip_index).?)) }) |
| 473 | else | 473 | else |
| 474 | .pack(wasm, .{ .uav_exe = @fromBackingInt(@intCast(wasm.uavs_exe.getIndex(ip_index).?)) }); | 474 | .pack(wasm, .{ .uav_exe = @fromBackingInt(@intCast(wasm.uavs_exe.getIndex(ip_index).?)) }); |
| ... | @@ -482,7 +482,7 @@ pub const OutputDataIndex = enum(u32) { | ... | @@ -482,7 +482,7 @@ pub const OutputDataIndex = enum(u32) { |
| 482 | if (nav.getExtern(ip) != null) { | 482 | if (nav.getExtern(ip) != null) { |
| 483 | return fromSymbolName(wasm, wasm.imports.get(nav_index).?); | 483 | return fromSymbolName(wasm, wasm.imports.get(nav_index).?); |
| 484 | } | 484 | } |
| 485 | const resolution: ObjectDataImport.Resolution = if (wasm.base.comp.config.output_mode == .Obj) | 485 | const resolution: ObjectDataImport.Resolution = if (wasm.base.isRelocatable()) |
| 486 | .pack(wasm, .{ .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(nav_index).?)) }) | 486 | .pack(wasm, .{ .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(nav_index).?)) }) |
| 487 | else | 487 | else |
| 488 | .pack(wasm, .{ .nav_exe = @fromBackingInt(@intCast(wasm.navs_exe.getIndex(nav_index).?)) }); | 488 | .pack(wasm, .{ .nav_exe = @fromBackingInt(@intCast(wasm.navs_exe.getIndex(nav_index).?)) }); |
| ... | @@ -500,7 +500,7 @@ pub const GlobalIndex = enum(u32) { | ... | @@ -500,7 +500,7 @@ pub const GlobalIndex = enum(u32) { |
| 500 | /// Same as `stack_pointer` but with a safety assertion. | 500 | /// Same as `stack_pointer` but with a safety assertion. |
| 501 | pub fn stackPointer(wasm: *const Wasm) ObjectGlobal.Index { | 501 | pub fn stackPointer(wasm: *const Wasm) ObjectGlobal.Index { |
| 502 | const comp = wasm.base.comp; | 502 | const comp = wasm.base.comp; |
| 503 | assert(comp.config.output_mode != .Obj); | 503 | assert(!wasm.base.isRelocatable()); |
| 504 | assert(comp.zcu != null); | 504 | assert(comp.zcu != null); |
| 505 | return .stack_pointer; | 505 | return .stack_pointer; |
| 506 | } | 506 | } |
| ... | @@ -879,8 +879,7 @@ const ZcuDataStarts = struct { | ... | @@ -879,8 +879,7 @@ const ZcuDataStarts = struct { |
| 879 | uavs_i: u32, | 879 | uavs_i: u32, |
| 880 | | 880 | |
| 881 | fn init(wasm: *const Wasm) ZcuDataStarts { | 881 | fn init(wasm: *const Wasm) ZcuDataStarts { |
| 882 | const comp = wasm.base.comp; | 882 | const is_obj = wasm.base.isRelocatable(); |
| 883 | const is_obj = comp.config.output_mode == .Obj; | | |
| 884 | return if (is_obj) initObj(wasm) else initExe(wasm); | 883 | return if (is_obj) initObj(wasm) else initExe(wasm); |
| 885 | } | 884 | } |
| 886 | | 885 | |
| ... | @@ -897,8 +896,7 @@ const ZcuDataStarts = struct { | ... | @@ -897,8 +896,7 @@ const ZcuDataStarts = struct { |
| 897 | } | 896 | } |
| 898 | | 897 | |
| 899 | fn finish(zds: ZcuDataStarts, wasm: *Wasm, pt: Zcu.PerThread) !void { | 898 | fn finish(zds: ZcuDataStarts, wasm: *Wasm, pt: Zcu.PerThread) !void { |
| 900 | const comp = wasm.base.comp; | 899 | const is_obj = wasm.base.isRelocatable(); |
| 901 | const is_obj = comp.config.output_mode == .Obj; | | |
| 902 | return if (is_obj) finishObj(zds, wasm, pt) else finishExe(zds, wasm, pt); | 900 | return if (is_obj) finishObj(zds, wasm, pt) else finishExe(zds, wasm, pt); |
| 903 | } | 901 | } |
| 904 | | 902 | |
| ... | @@ -1276,8 +1274,7 @@ pub const GlobalImport = extern struct { | ... | @@ -1276,8 +1274,7 @@ pub const GlobalImport = extern struct { |
| 1276 | const object_global_index = i - first_object_global; | 1274 | const object_global_index = i - first_object_global; |
| 1277 | if (object_global_index < wasm.object_globals.items.len) | 1275 | if (object_global_index < wasm.object_globals.items.len) |
| 1278 | return .{ .object_global = @fromBackingInt(@intCast(object_global_index)) }; | 1276 | return .{ .object_global = @fromBackingInt(@intCast(object_global_index)) }; |
| 1279 | const comp = wasm.base.comp; | 1277 | const is_obj = wasm.base.isRelocatable(); |
| 1280 | const is_obj = comp.config.output_mode == .Obj; | | |
| 1281 | const uav_index = object_global_index - wasm.object_globals.items.len; | 1278 | const uav_index = object_global_index - wasm.object_globals.items.len; |
| 1282 | if (is_obj) { | 1279 | if (is_obj) { |
| 1283 | if (uav_index < wasm.uavs_obj.entries.len) { | 1280 | if (uav_index < wasm.uavs_obj.entries.len) { |
| ... | @@ -1323,7 +1320,7 @@ pub const GlobalImport = extern struct { | ... | @@ -1323,7 +1320,7 @@ pub const GlobalImport = extern struct { |
| 1323 | } | 1320 | } |
| 1324 | | 1321 | |
| 1325 | pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution { | 1322 | pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution { |
| 1326 | const is_obj = wasm.base.comp.config.output_mode == .Obj; | 1323 | const is_obj = wasm.base.isRelocatable(); |
| 1327 | return pack(wasm, if (is_obj) .{ | 1324 | return pack(wasm, if (is_obj) .{ |
| 1328 | .uav_obj = @fromBackingInt(@intCast(wasm.uavs_obj.getIndex(ip_index).?)), | 1325 | .uav_obj = @fromBackingInt(@intCast(wasm.uavs_obj.getIndex(ip_index).?)), |
| 1329 | } else .{ | 1326 | } else .{ |
| ... | @@ -1332,8 +1329,7 @@ pub const GlobalImport = extern struct { | ... | @@ -1332,8 +1329,7 @@ pub const GlobalImport = extern struct { |
| 1332 | } | 1329 | } |
| 1333 | | 1330 | |
| 1334 | pub fn fromIpNav(wasm: *const Wasm, ip_nav: InternPool.Nav.Index) Resolution { | 1331 | pub fn fromIpNav(wasm: *const Wasm, ip_nav: InternPool.Nav.Index) Resolution { |
| 1335 | const comp = wasm.base.comp; | 1332 | const is_obj = wasm.base.isRelocatable(); |
| 1336 | const is_obj = comp.config.output_mode == .Obj; | | |
| 1337 | return pack(wasm, if (is_obj) .{ | 1333 | return pack(wasm, if (is_obj) .{ |
| 1338 | .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(ip_nav).?)), | 1334 | .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(ip_nav).?)), |
| 1339 | } else .{ | 1335 | } else .{ |
| ... | @@ -1819,8 +1815,7 @@ pub const ObjectDataImport = extern struct { | ... | @@ -1819,8 +1815,7 @@ pub const ObjectDataImport = extern struct { |
| 1819 | else | 1815 | else |
| 1820 | object_index - wasm.object_datas.items.len; | 1816 | object_index - wasm.object_datas.items.len; |
| 1821 | | 1817 | |
| 1822 | const comp = wasm.base.comp; | 1818 | const is_obj = wasm.base.isRelocatable(); |
| 1823 | const is_obj = comp.config.output_mode == .Obj; | | |
| 1824 | if (is_obj) { | 1819 | if (is_obj) { |
| 1825 | const nav_index = if (uav_index < wasm.uavs_obj.entries.len) | 1820 | const nav_index = if (uav_index < wasm.uavs_obj.entries.len) |
| 1826 | return .{ .uav_obj = @fromBackingInt(@intCast(uav_index)) } | 1821 | return .{ .uav_obj = @fromBackingInt(@intCast(uav_index)) } |
| ... | @@ -1863,7 +1858,7 @@ pub const ObjectDataImport = extern struct { | ... | @@ -1863,7 +1858,7 @@ pub const ObjectDataImport = extern struct { |
| 1863 | } | 1858 | } |
| 1864 | | 1859 | |
| 1865 | pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution { | 1860 | pub fn fromIpIndex(wasm: *const Wasm, ip_index: InternPool.Index) Resolution { |
| 1866 | const is_obj = wasm.base.comp.config.output_mode == .Obj; | 1861 | const is_obj = wasm.base.isRelocatable(); |
| 1867 | return pack(wasm, if (is_obj) .{ | 1862 | return pack(wasm, if (is_obj) .{ |
| 1868 | .uav_obj = @fromBackingInt(@intCast(wasm.uavs_obj.getIndex(ip_index).?)), | 1863 | .uav_obj = @fromBackingInt(@intCast(wasm.uavs_obj.getIndex(ip_index).?)), |
| 1869 | } else .{ | 1864 | } else .{ |
| ... | @@ -1872,7 +1867,7 @@ pub const ObjectDataImport = extern struct { | ... | @@ -1872,7 +1867,7 @@ pub const ObjectDataImport = extern struct { |
| 1872 | } | 1867 | } |
| 1873 | | 1868 | |
| 1874 | pub fn fromIpNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) Resolution { | 1869 | pub fn fromIpNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) Resolution { |
| 1875 | const is_obj = wasm.base.comp.config.output_mode == .Obj; | 1870 | const is_obj = wasm.base.isRelocatable(); |
| 1876 | return pack(wasm, if (is_obj) .{ | 1871 | return pack(wasm, if (is_obj) .{ |
| 1877 | .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(nav_index).?)), | 1872 | .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(nav_index).?)), |
| 1878 | } else .{ | 1873 | } else .{ |
| ... | @@ -2117,8 +2112,7 @@ pub const DataSegmentId = enum(u32) { | ... | @@ -2117,8 +2112,7 @@ pub const DataSegmentId = enum(u32) { |
| 2117 | else | 2112 | else |
| 2118 | object_index - wasm.object_data_segments.items.len; | 2113 | object_index - wasm.object_data_segments.items.len; |
| 2119 | | 2114 | |
| 2120 | const comp = wasm.base.comp; | 2115 | const is_obj = wasm.base.isRelocatable(); |
| 2121 | const is_obj = comp.config.output_mode == .Obj; | | |
| 2122 | if (is_obj) { | 2116 | if (is_obj) { |
| 2123 | const nav_index = if (uav_index < wasm.uavs_obj.entries.len) | 2117 | const nav_index = if (uav_index < wasm.uavs_obj.entries.len) |
| 2124 | return .{ .uav_obj = @fromBackingInt(@intCast(uav_index)) } | 2118 | return .{ .uav_obj = @fromBackingInt(@intCast(uav_index)) } |
| ... | @@ -2139,8 +2133,7 @@ pub const DataSegmentId = enum(u32) { | ... | @@ -2139,8 +2133,7 @@ pub const DataSegmentId = enum(u32) { |
| 2139 | } | 2133 | } |
| 2140 | | 2134 | |
| 2141 | pub fn fromNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) DataSegmentId { | 2135 | pub fn fromNav(wasm: *const Wasm, nav_index: InternPool.Nav.Index) DataSegmentId { |
| 2142 | const comp = wasm.base.comp; | 2136 | const is_obj = wasm.base.isRelocatable(); |
| 2143 | const is_obj = comp.config.output_mode == .Obj; | | |
| 2144 | return pack(wasm, if (is_obj) .{ | 2137 | return pack(wasm, if (is_obj) .{ |
| 2145 | .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(nav_index).?)), | 2138 | .nav_obj = @fromBackingInt(@intCast(wasm.navs_obj.getIndex(nav_index).?)), |
| 2146 | } else .{ | 2139 | } else .{ |
| ... | @@ -2717,7 +2710,7 @@ pub const FunctionImportId = enum(u32) { | ... | @@ -2717,7 +2710,7 @@ pub const FunctionImportId = enum(u32) { |
| 2717 | /// Asserts not emitting an object, and `Wasm.import_symbols` is false. | 2710 | /// Asserts not emitting an object, and `Wasm.import_symbols` is false. |
| 2718 | pub fn undefinedAllowed(id: FunctionImportId, wasm: *const Wasm) bool { | 2711 | pub fn undefinedAllowed(id: FunctionImportId, wasm: *const Wasm) bool { |
| 2719 | assert(!wasm.import_symbols); | 2712 | assert(!wasm.import_symbols); |
| 2720 | assert(wasm.base.comp.config.output_mode != .Obj); | 2713 | assert(!wasm.base.isRelocatable()); |
| 2721 | return switch (unpack(id, wasm)) { | 2714 | return switch (unpack(id, wasm)) { |
| 2722 | .object_function_import => |i| { | 2715 | .object_function_import => |i| { |
| 2723 | const import = i.value(wasm); | 2716 | const import = i.value(wasm); |
| ... | @@ -3343,6 +3336,7 @@ pub fn createEmpty( | ... | @@ -3343,6 +3336,7 @@ pub fn createEmpty( |
| 3343 | assert(target.ofmt == .wasm); | 3336 | assert(target.ofmt == .wasm); |
| 3344 | | 3337 | |
| 3345 | const output_mode = comp.config.output_mode; | 3338 | const output_mode = comp.config.output_mode; |
| | 3339 | const is_relocatable = output_mode == .Obj or (output_mode == .Lib and comp.config.link_mode == .static); |
| 3346 | const wasi_exec_model = comp.config.wasi_exec_model; | 3340 | const wasi_exec_model = comp.config.wasi_exec_model; |
| 3347 | | 3341 | |
| 3348 | const wasm = try arena.create(Wasm); | 3342 | const wasm = try arena.create(Wasm); |
| ... | @@ -3356,7 +3350,7 @@ pub fn createEmpty( | ... | @@ -3356,7 +3350,7 @@ pub fn createEmpty( |
| 3356 | // majority of cases, and therefore express "no garbage collection" | 3350 | // majority of cases, and therefore express "no garbage collection" |
| 3357 | // in terms of setting the no_strip and must_link flags on all | 3351 | // in terms of setting the no_strip and must_link flags on all |
| 3358 | // symbols. | 3352 | // symbols. |
| 3359 | .gc_sections = options.gc_sections orelse (output_mode != .Obj), | 3353 | .gc_sections = options.gc_sections orelse !is_relocatable, |
| 3360 | .print_gc_sections = options.print_gc_sections, | 3354 | .print_gc_sections = options.print_gc_sections, |
| 3361 | .stack_size = options.stack_size orelse switch (target.os.tag) { | 3355 | .stack_size = options.stack_size orelse switch (target.os.tag) { |
| 3362 | .freestanding => 1 * 1024 * 1024, // 1 MiB | 3356 | .freestanding => 1 * 1024 * 1024, // 1 MiB |
| ... | @@ -3436,6 +3430,11 @@ fn parseObject(wasm: *Wasm, obj: link.Input.Object) !void { | ... | @@ -3436,6 +3430,11 @@ fn parseObject(wasm: *Wasm, obj: link.Input.Object) !void { |
| 3436 | }; | 3430 | }; |
| 3437 | if (n != file_contents.len) return error.UnexpectedEndOfFile; | 3431 | if (n != file_contents.len) return error.UnexpectedEndOfFile; |
| 3438 | | 3432 | |
| | 3433 | if (wasm.base.isStaticLib()) { |
| | 3434 | try wasm.archive_builder.append(gpa, std.fs.path.basename(obj.path.sub_path), file_contents); |
| | 3435 | return; |
| | 3436 | } |
| | 3437 | |
| 3439 | var ss: Object.ScratchSpace = .{}; | 3438 | var ss: Object.ScratchSpace = .{}; |
| 3440 | defer ss.deinit(gpa); | 3439 | defer ss.deinit(gpa); |
| 3441 | | 3440 | |
| ... | @@ -3526,6 +3525,7 @@ pub fn deinit(wasm: *Wasm) void { | ... | @@ -3526,6 +3525,7 @@ pub fn deinit(wasm: *Wasm) void { |
| 3526 | wasm.object_relocations_table.deinit(gpa); | 3525 | wasm.object_relocations_table.deinit(gpa); |
| 3527 | wasm.object_comdat_symbols.deinit(gpa); | 3526 | wasm.object_comdat_symbols.deinit(gpa); |
| 3528 | wasm.objects.deinit(gpa); | 3527 | wasm.objects.deinit(gpa); |
| | 3528 | wasm.archive_builder.deinit(gpa); |
| 3529 | | 3529 | |
| 3530 | wasm.func_types.deinit(gpa); | 3530 | wasm.func_types.deinit(gpa); |
| 3531 | wasm.function_exports.deinit(gpa); | 3531 | wasm.function_exports.deinit(gpa); |
| ... | @@ -3575,7 +3575,7 @@ pub fn updateFunc( | ... | @@ -3575,7 +3575,7 @@ pub fn updateFunc( |
| 3575 | const zcu = pt.zcu; | 3575 | const zcu = pt.zcu; |
| 3576 | const gpa = zcu.gpa; | 3576 | const gpa = zcu.gpa; |
| 3577 | const ip = &zcu.intern_pool; | 3577 | const ip = &zcu.intern_pool; |
| 3578 | const is_obj = zcu.comp.config.output_mode == .Obj; | 3578 | const is_obj = wasm.base.isRelocatable(); |
| 3579 | const target = &zcu.comp.root_mod.resolved_target.result; | 3579 | const target = &zcu.comp.root_mod.resolved_target.result; |
| 3580 | const owner_nav = zcu.funcInfo(func_index).owner_nav; | 3580 | const owner_nav = zcu.funcInfo(func_index).owner_nav; |
| 3581 | log.debug("updateFunc {f}", .{ip.getNav(owner_nav).fqn.fmt(ip)}); | 3581 | log.debug("updateFunc {f}", .{ip.getNav(owner_nav).fqn.fmt(ip)}); |
| ... | @@ -3656,7 +3656,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index | ... | @@ -3656,7 +3656,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index |
| 3656 | const nav = ip.getNav(nav_index); | 3656 | const nav = ip.getNav(nav_index); |
| 3657 | const comp = wasm.base.comp; | 3657 | const comp = wasm.base.comp; |
| 3658 | const gpa = comp.gpa; | 3658 | const gpa = comp.gpa; |
| 3659 | const is_obj = comp.config.output_mode == .Obj; | 3659 | const is_obj = wasm.base.isRelocatable(); |
| 3660 | const target = &comp.root_mod.resolved_target.result; | 3660 | const target = &comp.root_mod.resolved_target.result; |
| 3661 | | 3661 | |
| 3662 | switch (ip.indexToKey(nav.resolved.?.value)) { | 3662 | switch (ip.indexToKey(nav.resolved.?.value)) { |
| ... | @@ -3740,7 +3740,7 @@ pub fn updateExports( | ... | @@ -3740,7 +3740,7 @@ pub fn updateExports( |
| 3740 | const zcu = pt.zcu; | 3740 | const zcu = pt.zcu; |
| 3741 | const gpa = zcu.gpa; | 3741 | const gpa = zcu.gpa; |
| 3742 | const ip = &zcu.intern_pool; | 3742 | const ip = &zcu.intern_pool; |
| 3743 | const is_obj = wasm.base.comp.config.output_mode == .Obj; | 3743 | const is_obj = wasm.base.isRelocatable(); |
| 3744 | | 3744 | |
| 3745 | for (export_indices) |export_idx| { | 3745 | for (export_indices) |export_idx| { |
| 3746 | const exp = export_idx.ptr(zcu); | 3746 | const exp = export_idx.ptr(zcu); |
| ... | @@ -3797,7 +3797,11 @@ pub fn loadInput(wasm: *Wasm, input: link.Input) !void { | ... | @@ -3797,7 +3797,11 @@ pub fn loadInput(wasm: *Wasm, input: link.Input) !void { |
| 3797 | .dso => unreachable, | 3797 | .dso => unreachable, |
| 3798 | .tbd => unreachable, | 3798 | .tbd => unreachable, |
| 3799 | .object => |obj| try parseObject(wasm, obj), | 3799 | .object => |obj| try parseObject(wasm, obj), |
| 3800 | .archive => |obj| try parseArchive(wasm, obj), | 3800 | .archive => |obj| if (wasm.base.isStaticLib()) { |
| | 3801 | obj.file.close(io); // ignore archives like LLVM |
| | 3802 | } else { |
| | 3803 | try parseArchive(wasm, obj); |
| | 3804 | }, |
| 3801 | } | 3805 | } |
| 3802 | } | 3806 | } |
| 3803 | | 3807 | |
| ... | @@ -3811,7 +3815,7 @@ pub fn prelink(wasm: *Wasm, prog_node: std.Progress.Node) link.Error!void { | ... | @@ -3811,7 +3815,7 @@ pub fn prelink(wasm: *Wasm, prog_node: std.Progress.Node) link.Error!void { |
| 3811 | const comp = wasm.base.comp; | 3815 | const comp = wasm.base.comp; |
| 3812 | const gpa = comp.gpa; | 3816 | const gpa = comp.gpa; |
| 3813 | const rdynamic = comp.config.rdynamic; | 3817 | const rdynamic = comp.config.rdynamic; |
| 3814 | const is_obj = comp.config.output_mode == .Obj; | 3818 | const is_obj = wasm.base.isRelocatable(); |
| 3815 | | 3819 | |
| 3816 | assert(wasm.missing_exports.entries.len == 0); | 3820 | assert(wasm.missing_exports.entries.len == 0); |
| 3817 | for (wasm.export_symbol_names) |exp_name| { | 3821 | for (wasm.export_symbol_names) |exp_name| { |
| ... | @@ -3915,7 +3919,7 @@ pub fn markFunctionImport( | ... | @@ -3915,7 +3919,7 @@ pub fn markFunctionImport( |
| 3915 | | 3919 | |
| 3916 | const comp = wasm.base.comp; | 3920 | const comp = wasm.base.comp; |
| 3917 | const gpa = comp.gpa; | 3921 | const gpa = comp.gpa; |
| 3918 | const is_obj = comp.config.output_mode == .Obj; | 3922 | const is_obj = wasm.base.isRelocatable(); |
| 3919 | | 3923 | |
| 3920 | try wasm.functions.ensureUnusedCapacity(gpa, 1); | 3924 | try wasm.functions.ensureUnusedCapacity(gpa, 1); |
| 3921 | | 3925 | |
| ... | @@ -3949,7 +3953,7 @@ fn markFunction(wasm: *Wasm, i: ObjectFunctionIndex, override_export: bool) link | ... | @@ -3949,7 +3953,7 @@ fn markFunction(wasm: *Wasm, i: ObjectFunctionIndex, override_export: bool) link |
| 3949 | if (gop.found_existing) return; | 3953 | if (gop.found_existing) return; |
| 3950 | | 3954 | |
| 3951 | const rdynamic = comp.config.rdynamic; | 3955 | const rdynamic = comp.config.rdynamic; |
| 3952 | const is_obj = comp.config.output_mode == .Obj; | 3956 | const is_obj = wasm.base.isRelocatable(); |
| 3953 | const function = i.ptr(wasm); | 3957 | const function = i.ptr(wasm); |
| 3954 | try markObject(wasm, function.object_index); | 3958 | try markObject(wasm, function.object_index); |
| 3955 | | 3959 | |
| ... | @@ -3991,7 +3995,7 @@ fn markGlobalImport( | ... | @@ -3991,7 +3995,7 @@ fn markGlobalImport( |
| 3991 | | 3995 | |
| 3992 | const comp = wasm.base.comp; | 3996 | const comp = wasm.base.comp; |
| 3993 | const gpa = comp.gpa; | 3997 | const gpa = comp.gpa; |
| 3994 | const is_obj = comp.config.output_mode == .Obj; | 3998 | const is_obj = wasm.base.isRelocatable(); |
| 3995 | | 3999 | |
| 3996 | try wasm.globals.ensureUnusedCapacity(gpa, 1); | 4000 | try wasm.globals.ensureUnusedCapacity(gpa, 1); |
| 3997 | | 4001 | |
| ... | @@ -4034,7 +4038,7 @@ fn markGlobal(wasm: *Wasm, i: ObjectGlobalIndex, override_export: bool) link.Err | ... | @@ -4034,7 +4038,7 @@ fn markGlobal(wasm: *Wasm, i: ObjectGlobalIndex, override_export: bool) link.Err |
| 4034 | if (gop.found_existing) return; | 4038 | if (gop.found_existing) return; |
| 4035 | | 4039 | |
| 4036 | const rdynamic = comp.config.rdynamic; | 4040 | const rdynamic = comp.config.rdynamic; |
| 4037 | const is_obj = comp.config.output_mode == .Obj; | 4041 | const is_obj = wasm.base.isRelocatable(); |
| 4038 | const global = i.ptr(wasm); | 4042 | const global = i.ptr(wasm); |
| 4039 | try markObject(wasm, global.object_index); | 4043 | try markObject(wasm, global.object_index); |
| 4040 | | 4044 | |
| ... | @@ -4057,7 +4061,7 @@ pub fn markTableImport( | ... | @@ -4057,7 +4061,7 @@ pub fn markTableImport( |
| 4057 | | 4061 | |
| 4058 | const comp = wasm.base.comp; | 4062 | const comp = wasm.base.comp; |
| 4059 | const gpa = comp.gpa; | 4063 | const gpa = comp.gpa; |
| 4060 | const is_obj = comp.config.output_mode == .Obj; | 4064 | const is_obj = wasm.base.isRelocatable(); |
| 4061 | | 4065 | |
| 4062 | try wasm.tables.ensureUnusedCapacity(gpa, 1); | 4066 | try wasm.tables.ensureUnusedCapacity(gpa, 1); |
| 4063 | | 4067 | |
| ... | @@ -4103,7 +4107,7 @@ pub fn markDataImport( | ... | @@ -4103,7 +4107,7 @@ pub fn markDataImport( |
| 4103 | | 4107 | |
| 4104 | const comp = wasm.base.comp; | 4108 | const comp = wasm.base.comp; |
| 4105 | const gpa = comp.gpa; | 4109 | const gpa = comp.gpa; |
| 4106 | const is_obj = comp.config.output_mode == .Obj; | 4110 | const is_obj = wasm.base.isRelocatable(); |
| 4107 | | 4111 | |
| 4108 | if (import.resolution == .unresolved) { | 4112 | if (import.resolution == .unresolved) { |
| 4109 | if (!is_obj) { | 4113 | if (!is_obj) { |
| ... | @@ -4682,7 +4686,7 @@ pub fn addNavReloc( | ... | @@ -4682,7 +4686,7 @@ pub fn addNavReloc( |
| 4682 | const ip = &zcu.intern_pool; | 4686 | const ip = &zcu.intern_pool; |
| 4683 | const gpa = comp.gpa; | 4687 | const gpa = comp.gpa; |
| 4684 | | 4688 | |
| 4685 | const is_obj = comp.config.output_mode == .Obj; | 4689 | const is_obj = wasm.base.isRelocatable(); |
| 4686 | | 4690 | |
| 4687 | if (nav_ty.zigTypeTag(zcu) == .@"fn") { | 4691 | if (nav_ty.zigTypeTag(zcu) == .@"fn") { |
| 4688 | const gop = try wasm.zcu_indirect_function_set.getOrPut(gpa, nav_index); | 4692 | const gop = try wasm.zcu_indirect_function_set.getOrPut(gpa, nav_index); |
| ... | @@ -4751,7 +4755,7 @@ pub fn addUavReloc( | ... | @@ -4751,7 +4755,7 @@ pub fn addUavReloc( |
| 4751 | gop.value_ptr.* = if (gop.found_existing) gop.value_ptr.maxStrict(this_align) else this_align; | 4755 | gop.value_ptr.* = if (gop.found_existing) gop.value_ptr.maxStrict(this_align) else this_align; |
| 4752 | } | 4756 | } |
| 4753 | | 4757 | |
| 4754 | if (comp.config.output_mode == .Obj) { | 4758 | if (wasm.base.isRelocatable()) { |
| 4755 | const gop = try wasm.uavs_obj.getOrPut(gpa, uav_val); | 4759 | const gop = try wasm.uavs_obj.getOrPut(gpa, uav_val); |
| 4756 | if (!gop.found_existing) gop.value_ptr.* = undefined; // to avoid recursion, `ZcuDataStarts` will lower the value later | 4760 | if (!gop.found_existing) gop.value_ptr.* = undefined; // to avoid recursion, `ZcuDataStarts` will lower the value later |
| 4757 | try wasm.zcu_relocations.append(gpa, .{ | 4761 | try wasm.zcu_relocations.append(gpa, .{ |
| ... | @@ -4782,7 +4786,7 @@ pub fn addUavReloc( | ... | @@ -4782,7 +4786,7 @@ pub fn addUavReloc( |
| 4782 | pub fn refNavObj(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsObjIndex { | 4786 | pub fn refNavObj(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsObjIndex { |
| 4783 | const comp = wasm.base.comp; | 4787 | const comp = wasm.base.comp; |
| 4784 | const gpa = comp.gpa; | 4788 | const gpa = comp.gpa; |
| 4785 | assert(comp.config.output_mode == .Obj); | 4789 | assert(wasm.base.isRelocatable()); |
| 4786 | const gop = try wasm.navs_obj.getOrPut(gpa, nav_index); | 4790 | const gop = try wasm.navs_obj.getOrPut(gpa, nav_index); |
| 4787 | if (!gop.found_existing) gop.value_ptr.* = .{ | 4791 | if (!gop.found_existing) gop.value_ptr.* = .{ |
| 4788 | // Lowering the value is delayed to avoid recursion. | 4792 | // Lowering the value is delayed to avoid recursion. |
| ... | @@ -4795,7 +4799,7 @@ pub fn refNavObj(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsObjIndex { | ... | @@ -4795,7 +4799,7 @@ pub fn refNavObj(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsObjIndex { |
| 4795 | pub fn refNavExe(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsExeIndex { | 4799 | pub fn refNavExe(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsExeIndex { |
| 4796 | const comp = wasm.base.comp; | 4800 | const comp = wasm.base.comp; |
| 4797 | const gpa = comp.gpa; | 4801 | const gpa = comp.gpa; |
| 4798 | assert(comp.config.output_mode != .Obj); | 4802 | assert(!wasm.base.isRelocatable()); |
| 4799 | const gop = try wasm.navs_exe.getOrPut(gpa, nav_index); | 4803 | const gop = try wasm.navs_exe.getOrPut(gpa, nav_index); |
| 4800 | if (gop.found_existing) { | 4804 | if (gop.found_existing) { |
| 4801 | gop.value_ptr.count += 1; | 4805 | gop.value_ptr.count += 1; |
| ... | @@ -4812,8 +4816,7 @@ pub fn refNavExe(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsExeIndex { | ... | @@ -4812,8 +4816,7 @@ pub fn refNavExe(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsExeIndex { |
| 4812 | /// Asserts it is called after `Flush.data_segments` is fully populated and sorted. | 4816 | /// Asserts it is called after `Flush.data_segments` is fully populated and sorted. |
| 4813 | pub fn uavAddr(wasm: *const Wasm, ip_index: InternPool.Index) u32 { | 4817 | pub fn uavAddr(wasm: *const Wasm, ip_index: InternPool.Index) u32 { |
| 4814 | assert(wasm.flush_buffer.memory_layout_finished); | 4818 | assert(wasm.flush_buffer.memory_layout_finished); |
| 4815 | const comp = wasm.base.comp; | 4819 | assert(!wasm.base.isRelocatable()); |
| 4816 | assert(comp.config.output_mode != .Obj); | | |
| 4817 | const uav_index: UavsExeIndex = @fromBackingInt(@intCast(wasm.uavs_exe.getIndex(ip_index).?)); | 4820 | const uav_index: UavsExeIndex = @fromBackingInt(@intCast(wasm.uavs_exe.getIndex(ip_index).?)); |
| 4818 | const ds_id: DataSegmentId = .pack(wasm, .{ .uav_exe = uav_index }); | 4821 | const ds_id: DataSegmentId = .pack(wasm, .{ .uav_exe = uav_index }); |
| 4819 | return wasm.flush_buffer.data_segments.get(ds_id).?; | 4822 | return wasm.flush_buffer.data_segments.get(ds_id).?; |
| ... | @@ -4834,7 +4837,7 @@ pub fn syntheticDataAddr(wasm: *const Wasm, resolution: ObjectDataImport.Resolut | ... | @@ -4834,7 +4837,7 @@ pub fn syntheticDataAddr(wasm: *const Wasm, resolution: ObjectDataImport.Resolut |
| 4834 | pub fn navAddr(wasm: *const Wasm, nav_index: InternPool.Nav.Index) u32 { | 4837 | pub fn navAddr(wasm: *const Wasm, nav_index: InternPool.Nav.Index) u32 { |
| 4835 | assert(wasm.flush_buffer.memory_layout_finished); | 4838 | assert(wasm.flush_buffer.memory_layout_finished); |
| 4836 | const comp = wasm.base.comp; | 4839 | const comp = wasm.base.comp; |
| 4837 | assert(comp.config.output_mode != .Obj); | 4840 | assert(!wasm.base.isRelocatable()); |
| 4838 | if (wasm.navs_exe.getIndex(nav_index)) |i| { | 4841 | if (wasm.navs_exe.getIndex(nav_index)) |i| { |
| 4839 | const navs_exe_index: NavsExeIndex = @fromBackingInt(@intCast(i)); | 4842 | const navs_exe_index: NavsExeIndex = @fromBackingInt(@intCast(i)); |
| 4840 | log.debug("navAddr {s} {}", .{ navs_exe_index.name(wasm), nav_index }); | 4843 | log.debug("navAddr {s} {}", .{ navs_exe_index.name(wasm), nav_index }); |
| ... | @@ -4888,15 +4891,13 @@ pub fn navAddr(wasm: *const Wasm, nav_index: InternPool.Nav.Index) u32 { | ... | @@ -4888,15 +4891,13 @@ pub fn navAddr(wasm: *const Wasm, nav_index: InternPool.Nav.Index) u32 { |
| 4888 | /// Asserts it is called after `Flush.data_segments` is fully populated and sorted. | 4891 | /// Asserts it is called after `Flush.data_segments` is fully populated and sorted. |
| 4889 | pub fn errorNameTableAddr(wasm: *Wasm) u32 { | 4892 | pub fn errorNameTableAddr(wasm: *Wasm) u32 { |
| 4890 | assert(wasm.flush_buffer.memory_layout_finished); | 4893 | assert(wasm.flush_buffer.memory_layout_finished); |
| 4891 | const comp = wasm.base.comp; | 4894 | assert(!wasm.base.isRelocatable()); |
| 4892 | assert(comp.config.output_mode != .Obj); | | |
| 4893 | return wasm.flush_buffer.data_segments.get(.__zig_error_name_table).?; | 4895 | return wasm.flush_buffer.data_segments.get(.__zig_error_name_table).?; |
| 4894 | } | 4896 | } |
| 4895 | | 4897 | |
| 4896 | pub fn tagIndexTableAddr(wasm: *Wasm, ip_index: InternPool.Index) u32 { | 4898 | pub fn tagIndexTableAddr(wasm: *Wasm, ip_index: InternPool.Index) u32 { |
| 4897 | assert(wasm.flush_buffer.memory_layout_finished); | 4899 | assert(wasm.flush_buffer.memory_layout_finished); |
| 4898 | const comp = wasm.base.comp; | 4900 | assert(!wasm.base.isRelocatable()); |
| 4899 | assert(comp.config.output_mode != .Obj); | | |
| 4900 | const f = &wasm.flush_buffer; | 4901 | const f = &wasm.flush_buffer; |
| 4901 | const table_base_addr = f.data_segments.get(.__zig_tag_name_table).?; | 4902 | const table_base_addr = f.data_segments.get(.__zig_tag_name_table).?; |
| 4902 | return table_base_addr + wasm.tagIndexTableOffset(ip_index); | 4903 | return table_base_addr + wasm.tagIndexTableOffset(ip_index); |