| ... | @@ -1036,14 +1036,16 @@ pub fn updateFunc( | ... | @@ -1036,14 +1036,16 @@ pub fn updateFunc( |
| 1036 | const ip = &zcu.intern_pool; | 1036 | const ip = &zcu.intern_pool; |
| 1037 | const gpa = elf_file.base.comp.gpa; | 1037 | const gpa = elf_file.base.comp.gpa; |
| 1038 | const func = zcu.funcInfo(func_index); | 1038 | const func = zcu.funcInfo(func_index); |
| 1039 | const jump_table = self.jumpTablePtr() orelse try self.initJumpTable(gpa, elf_file); | 1039 | if (elf_file.base.isRelocatable() and self.jumpTablePtr() == null) { |
| | 1040 | try self.initJumpTable(gpa, elf_file); |
| | 1041 | } |
| 1040 | | 1042 | |
| 1041 | log.debug("updateFunc {}({d})", .{ ip.getNav(func.owner_nav).fqn.fmt(ip), func.owner_nav }); | 1043 | log.debug("updateFunc {}({d})", .{ ip.getNav(func.owner_nav).fqn.fmt(ip), func.owner_nav }); |
| 1042 | | 1044 | |
| 1043 | const sym_index = try self.getOrCreateMetadataForNav(elf_file, func.owner_nav); | 1045 | const sym_index = try self.getOrCreateMetadataForNav(elf_file, func.owner_nav); |
| 1044 | self.symbol(sym_index).atom(elf_file).?.freeRelocs(elf_file); | 1046 | self.symbol(sym_index).atom(elf_file).?.freeRelocs(elf_file); |
| 1045 | | 1047 | |
| 1046 | { | 1048 | if (self.jumpTablePtr()) |jump_table| { |
| 1047 | const sym = self.symbol(sym_index); | 1049 | const sym = self.symbol(sym_index); |
| 1048 | if (!sym.flags.has_zjt) { | 1050 | if (!sym.flags.has_zjt) { |
| 1049 | const index = try jump_table.addSymbol(gpa, sym_index); | 1051 | const index = try jump_table.addSymbol(gpa, sym_index); |
| ... | @@ -1100,21 +1102,23 @@ pub fn updateFunc( | ... | @@ -1100,21 +1102,23 @@ pub fn updateFunc( |
| 1100 | | 1102 | |
| 1101 | // Exports will be updated by `Zcu.processExports` after the update. | 1103 | // Exports will be updated by `Zcu.processExports` after the update. |
| 1102 | | 1104 | |
| 1103 | if (jump_table.dirty) { | 1105 | if (self.jumpTablePtr()) |jump_table| { |
| 1104 | // TODO write in bulk | 1106 | if (jump_table.dirty) { |
| 1105 | for (jump_table.entries.items(.dirty), 0..) |*dirty, i| { | 1107 | // TODO write in bulk |
| 1106 | try jump_table.writeEntry(@intCast(i), self, elf_file); | 1108 | for (jump_table.entries.items(.dirty), 0..) |*dirty, i| { |
| 1107 | dirty.* = false; | 1109 | try jump_table.writeEntry(@intCast(i), self, elf_file); |
| 1108 | } | 1110 | dirty.* = false; |
| 1109 | } else { | 1111 | } |
| 1110 | const sym = self.symbol(sym_index); | 1112 | } else { |
| 1111 | const jt_index = sym.extra(elf_file).zjt; | 1113 | const sym = self.symbol(sym_index); |
| 1112 | var jt_entry = jump_table.entries.get(jt_index); | 1114 | const jt_index = sym.extra(elf_file).zjt; |
| 1113 | if (jt_entry.dirty) { | 1115 | var jt_entry = jump_table.entries.get(jt_index); |
| 1114 | try jump_table.writeEntry(jt_index, self, elf_file); | 1116 | if (jt_entry.dirty) { |
| 1115 | jt_entry.dirty = false; | 1117 | try jump_table.writeEntry(jt_index, self, elf_file); |
| | 1118 | jt_entry.dirty = false; |
| | 1119 | } |
| | 1120 | jump_table.entries.set(jt_index, jt_entry); |
| 1116 | } | 1121 | } |
| 1117 | jump_table.entries.set(jt_index, jt_entry); | | |
| 1118 | } | 1122 | } |
| 1119 | } | 1123 | } |
| 1120 | | 1124 | |
| ... | @@ -1474,7 +1478,7 @@ pub fn jumpTablePtr(self: *ZigObject) ?*JumpTable { | ... | @@ -1474,7 +1478,7 @@ pub fn jumpTablePtr(self: *ZigObject) ?*JumpTable { |
| 1474 | return if (self.jump_table) |*jt| jt else null; | 1478 | return if (self.jump_table) |*jt| jt else null; |
| 1475 | } | 1479 | } |
| 1476 | | 1480 | |
| 1477 | fn initJumpTable(self: *ZigObject, allocator: Allocator, elf_file: *Elf) error{OutOfMemory}!*JumpTable { | 1481 | fn initJumpTable(self: *ZigObject, allocator: Allocator, elf_file: *Elf) error{OutOfMemory}!void { |
| 1478 | const name_off = try self.addString(allocator, "__zig_jump_table"); | 1482 | const name_off = try self.addString(allocator, "__zig_jump_table"); |
| 1479 | const sym_index = try self.newSymbolWithAtom(allocator, name_off); | 1483 | const sym_index = try self.newSymbolWithAtom(allocator, name_off); |
| 1480 | const sym = self.symbol(sym_index); | 1484 | const sym = self.symbol(sym_index); |
| ... | @@ -1485,7 +1489,6 @@ fn initJumpTable(self: *ZigObject, allocator: Allocator, elf_file: *Elf) error{O | ... | @@ -1485,7 +1489,6 @@ fn initJumpTable(self: *ZigObject, allocator: Allocator, elf_file: *Elf) error{O |
| 1485 | atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(JumpTable.alignment(elf_file.getTarget().cpu.arch)); | 1489 | atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(JumpTable.alignment(elf_file.getTarget().cpu.arch)); |
| 1486 | atom_ptr.output_section_index = elf_file.zig_text_section_index.?; | 1490 | atom_ptr.output_section_index = elf_file.zig_text_section_index.?; |
| 1487 | self.jump_table = JumpTable{ .sym_index = sym_index }; | 1491 | self.jump_table = JumpTable{ .sym_index = sym_index }; |
| 1488 | return &(self.jump_table.?); | | |
| 1489 | } | 1492 | } |
| 1490 | | 1493 | |
| 1491 | pub fn asFile(self: *ZigObject) File { | 1494 | pub fn asFile(self: *ZigObject) File { |