| author | |
| committer | |
| log | 372bc960b8315ea1ff17b369b0b33485d5e34cfb |
| tree | 8f492631dec579c28b8430e80213f6ad4d286dd9 |
| parent | f37ca3fa7370c501c630c53b370fecdeb313e3be |
4 files changed, 39 insertions(+), 28 deletions(-)
src/link.zig+2-2| ... | ... | @@ -1120,8 +1120,8 @@ pub const File = struct { |
| 1120 | 1120 | kind: Kind, |
| 1121 | 1121 | ty: Type, |
| 1122 | 1122 | |
| 1123 | pub fn initDecl(kind: Kind, decl: Module.Decl.OptionalIndex, mod: *Module) LazySymbol { | |
| 1124 | return .{ .kind = kind, .ty = if (decl.unwrap()) |decl_index| | |
| 1123 | pub fn initDecl(kind: Kind, decl: ?Module.Decl.Index, mod: *Module) LazySymbol { | |
| 1124 | return .{ .kind = kind, .ty = if (decl) |decl_index| | |
| 1125 | 1125 | mod.declPtr(decl_index).val.castTag(.ty).?.data |
| 1126 | 1126 | else |
| 1127 | 1127 | Type.anyerror }; |
src/link/Coff.zig+14-9| ... | ... | @@ -1136,7 +1136,11 @@ pub fn lowerUnnamedConst(self: *Coff, tv: TypedValue, decl_index: Module.Decl.In |
| 1136 | 1136 | return atom.getSymbolIndex().?; |
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !void { | |
| 1139 | pub fn updateDecl( | |
| 1140 | self: *Coff, | |
| 1141 | module: *Module, | |
| 1142 | decl_index: Module.Decl.Index, | |
| 1143 | ) link.File.UpdateDeclError!void { | |
| 1140 | 1144 | if (build_options.skip_non_native and builtin.object_format != .coff) { |
| 1141 | 1145 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1142 | 1146 | } |
| ... | ... | @@ -1146,6 +1150,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) ! |
| 1146 | 1150 | const tracy = trace(@src()); |
| 1147 | 1151 | defer tracy.end(); |
| 1148 | 1152 | |
| 1153 | try self.updateLazySymbol(decl_index); | |
| 1154 | ||
| 1149 | 1155 | const decl = module.declPtr(decl_index); |
| 1150 | 1156 | |
| 1151 | 1157 | if (decl.val.tag() == .extern_fn) { |
| ... | ... | @@ -1188,7 +1194,8 @@ pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) ! |
| 1188 | 1194 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); |
| 1189 | 1195 | } |
| 1190 | 1196 | |
| 1191 | fn updateLazySymbol(self: *Coff, decl: Module.Decl.OptionalIndex, metadata: LazySymbolMetadata) !void { | |
| 1197 | fn updateLazySymbol(self: *Coff, decl: ?Module.Decl.Index) !void { | |
| 1198 | const metadata = self.lazy_syms.get(Module.Decl.OptionalIndex.init(decl)) orelse return; | |
| 1192 | 1199 | const mod = self.base.options.module.?; |
| 1193 | 1200 | if (metadata.text_atom) |atom| try self.updateLazySymbolAtom( |
| 1194 | 1201 | link.File.LazySymbol.initDecl(.code, decl, mod), |
| ... | ... | @@ -1402,7 +1409,7 @@ pub fn updateDeclExports( |
| 1402 | 1409 | module: *Module, |
| 1403 | 1410 | decl_index: Module.Decl.Index, |
| 1404 | 1411 | exports: []const *Module.Export, |
| 1405 | ) !void { | |
| 1412 | ) link.File.UpdateDeclExportsError!void { | |
| 1406 | 1413 | if (build_options.skip_non_native and builtin.object_format != .coff) { |
| 1407 | 1414 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1408 | 1415 | } |
| ... | ... | @@ -1599,12 +1606,10 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 1599 | 1606 | |
| 1600 | 1607 | // Most lazy symbols can be updated when the corresponding decl is, |
| 1601 | 1608 | // so we only have to worry about the one without an associated decl. |
| 1602 | if (self.lazy_syms.get(.none)) |metadata| { | |
| 1603 | self.updateLazySymbol(.none, metadata) catch |err| switch (err) { | |
| 1604 | error.CodegenFail => return error.FlushFailure, | |
| 1605 | else => |e| return e, | |
| 1606 | }; | |
| 1607 | } | |
| 1609 | self.updateLazySymbol(null) catch |err| switch (err) { | |
| 1610 | error.CodegenFail => return error.FlushFailure, | |
| 1611 | else => |e| return e, | |
| 1612 | }; | |
| 1608 | 1613 | |
| 1609 | 1614 | const gpa = self.base.allocator; |
| 1610 | 1615 |
src/link/Elf.zig+14-9| ... | ... | @@ -1034,12 +1034,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1034 | 1034 | |
| 1035 | 1035 | // Most lazy symbols can be updated when the corresponding decl is, |
| 1036 | 1036 | // so we only have to worry about the one without an associated decl. |
| 1037 | if (self.lazy_syms.get(.none)) |metadata| { | |
| 1038 | self.updateLazySymbol(.none, metadata) catch |err| switch (err) { | |
| 1039 | error.CodegenFail => return error.FlushFailure, | |
| 1040 | else => |e| return e, | |
| 1041 | }; | |
| 1042 | } | |
| 1037 | self.updateLazySymbol(null) catch |err| switch (err) { | |
| 1038 | error.CodegenFail => return error.FlushFailure, | |
| 1039 | else => |e| return e, | |
| 1040 | }; | |
| 1043 | 1041 | |
| 1044 | 1042 | // TODO This linker code currently assumes there is only 1 compilation unit and it |
| 1045 | 1043 | // corresponds to the Zig source code. |
| ... | ... | @@ -2579,7 +2577,11 @@ pub fn updateFunc(self: *Elf, module: *Module, func: *Module.Fn, air: Air, liven |
| 2579 | 2577 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); |
| 2580 | 2578 | } |
| 2581 | 2579 | |
| 2582 | pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !void { | |
| 2580 | pub fn updateDecl( | |
| 2581 | self: *Elf, | |
| 2582 | module: *Module, | |
| 2583 | decl_index: Module.Decl.Index, | |
| 2584 | ) File.UpdateDeclError!void { | |
| 2583 | 2585 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2584 | 2586 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2585 | 2587 | } |
| ... | ... | @@ -2590,6 +2592,8 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v |
| 2590 | 2592 | const tracy = trace(@src()); |
| 2591 | 2593 | defer tracy.end(); |
| 2592 | 2594 | |
| 2595 | try self.updateLazySymbol(decl_index); | |
| 2596 | ||
| 2593 | 2597 | const decl = module.declPtr(decl_index); |
| 2594 | 2598 | |
| 2595 | 2599 | if (decl.val.tag() == .extern_fn) { |
| ... | ... | @@ -2656,7 +2660,8 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v |
| 2656 | 2660 | return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); |
| 2657 | 2661 | } |
| 2658 | 2662 | |
| 2659 | fn updateLazySymbol(self: *Elf, decl: Module.Decl.OptionalIndex, metadata: LazySymbolMetadata) !void { | |
| 2663 | fn updateLazySymbol(self: *Elf, decl: ?Module.Decl.Index) !void { | |
| 2664 | const metadata = self.lazy_syms.get(Module.Decl.OptionalIndex.init(decl)) orelse return; | |
| 2660 | 2665 | const mod = self.base.options.module.?; |
| 2661 | 2666 | if (metadata.text_atom) |atom| try self.updateLazySymbolAtom( |
| 2662 | 2667 | File.LazySymbol.initDecl(.code, decl, mod), |
| ... | ... | @@ -2810,7 +2815,7 @@ pub fn updateDeclExports( |
| 2810 | 2815 | module: *Module, |
| 2811 | 2816 | decl_index: Module.Decl.Index, |
| 2812 | 2817 | exports: []const *Module.Export, |
| 2813 | ) !void { | |
| 2818 | ) File.UpdateDeclExportsError!void { | |
| 2814 | 2819 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2815 | 2820 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2816 | 2821 | } |
src/link/MachO.zig+9-8| ... | ... | @@ -495,12 +495,10 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 495 | 495 | |
| 496 | 496 | // Most lazy symbols can be updated when the corresponding decl is, |
| 497 | 497 | // so we only have to worry about the one without an associated decl. |
| 498 | if (self.lazy_syms.get(.none)) |metadata| { | |
| 499 | self.updateLazySymbol(.none, metadata) catch |err| switch (err) { | |
| 500 | error.CodegenFail => return error.FlushFailure, | |
| 501 | else => |e| return e, | |
| 502 | }; | |
| 503 | } | |
| 498 | self.updateLazySymbol(null) catch |err| switch (err) { | |
| 499 | error.CodegenFail => return error.FlushFailure, | |
| 500 | else => |e| return e, | |
| 501 | }; | |
| 504 | 502 | |
| 505 | 503 | const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented; |
| 506 | 504 | |
| ... | ... | @@ -1962,6 +1960,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 1962 | 1960 | const tracy = trace(@src()); |
| 1963 | 1961 | defer tracy.end(); |
| 1964 | 1962 | |
| 1963 | try self.updateLazySymbol(decl_index); | |
| 1964 | ||
| 1965 | 1965 | const decl = module.declPtr(decl_index); |
| 1966 | 1966 | |
| 1967 | 1967 | if (decl.val.tag() == .extern_fn) { |
| ... | ... | @@ -2036,7 +2036,8 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index) |
| 2036 | 2036 | try self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index)); |
| 2037 | 2037 | } |
| 2038 | 2038 | |
| 2039 | fn updateLazySymbol(self: *MachO, decl: Module.Decl.OptionalIndex, metadata: LazySymbolMetadata) !void { | |
| 2039 | fn updateLazySymbol(self: *MachO, decl: ?Module.Decl.Index) !void { | |
| 2040 | const metadata = self.lazy_syms.get(Module.Decl.OptionalIndex.init(decl)) orelse return; | |
| 2040 | 2041 | const mod = self.base.options.module.?; |
| 2041 | 2042 | if (metadata.text_atom) |atom| try self.updateLazySymbolAtom( |
| 2042 | 2043 | File.LazySymbol.initDecl(.code, decl, mod), |
| ... | ... | @@ -2353,7 +2354,7 @@ pub fn updateDeclExports( |
| 2353 | 2354 | module: *Module, |
| 2354 | 2355 | decl_index: Module.Decl.Index, |
| 2355 | 2356 | exports: []const *Module.Export, |
| 2356 | ) !void { | |
| 2357 | ) File.UpdateDeclExportsError!void { | |
| 2357 | 2358 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 2358 | 2359 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2359 | 2360 | } |