authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-28 21:52:44+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-03-28 21:52:44+02:00
log17ec2cea6455148526f56fa17cb704fd1d656b06
tree5bb76051de4b95dd7cf2e651e981b75056b8e392
parentcde722a7117b6da129d3c49dabd445136ed5edb5

macho: remove error_union return from resolveRelocations()


3 files changed, 8 insertions(+), 18 deletions(-)

src/link/MachO.zig+1-1
...@@ -1091,7 +1091,7 @@ pub fn writeAtom(self: *MachO, atom_index: Atom.Index, code: []u8) !void {...@@ -1091,7 +1091,7 @@ pub fn writeAtom(self: *MachO, atom_index: Atom.Index, code: []u8) !void {
1091 log.debug("writing atom for symbol {s} at file offset 0x{x}", .{ atom.getName(self), file_offset });1091 log.debug("writing atom for symbol {s} at file offset 0x{x}", .{ atom.getName(self), file_offset });
10921092
1093 if (self.relocs.get(atom_index)) |relocs| {1093 if (self.relocs.get(atom_index)) |relocs| {
1094 try Atom.resolveRelocations(self, atom_index, relocs.items, code);1094 Atom.resolveRelocations(self, atom_index, relocs.items, code);
1095 }1095 }
10961096
1097 if (is_hot_update_compatible) {1097 if (is_hot_update_compatible) {
src/link/MachO/Atom.zig+2-2
...@@ -183,11 +183,11 @@ pub fn addLazyBinding(macho_file: *MachO, atom_index: Index, binding: Binding) !...@@ -183,11 +183,11 @@ pub fn addLazyBinding(macho_file: *MachO, atom_index: Index, binding: Binding) !
183 try gop.value_ptr.append(gpa, binding);183 try gop.value_ptr.append(gpa, binding);
184}184}
185185
186pub fn resolveRelocations(macho_file: *MachO, atom_index: Index, relocs: []Relocation, code: []u8) !void {186pub fn resolveRelocations(macho_file: *MachO, atom_index: Index, relocs: []Relocation, code: []u8) void {
187 log.debug("relocating '{s}'", .{macho_file.getAtom(atom_index).getName(macho_file)});187 log.debug("relocating '{s}'", .{macho_file.getAtom(atom_index).getName(macho_file)});
188 for (relocs) |*reloc| {188 for (relocs) |*reloc| {
189 if (!reloc.dirty) continue;189 if (!reloc.dirty) continue;
190 try reloc.resolve(macho_file, atom_index, code);190 reloc.resolve(macho_file, atom_index, code);
191 reloc.dirty = false;191 reloc.dirty = false;
192 }192 }
193}193}
src/link/MachO/Relocation.zig+5-15
...@@ -50,7 +50,7 @@ pub fn getTargetAtomIndex(self: Relocation, macho_file: *MachO) ?Atom.Index {...@@ -50,7 +50,7 @@ pub fn getTargetAtomIndex(self: Relocation, macho_file: *MachO) ?Atom.Index {
50 return macho_file.getAtomIndexForSymbol(self.target);50 return macho_file.getAtomIndexForSymbol(self.target);
51}51}
5252
53pub fn resolve(self: Relocation, macho_file: *MachO, atom_index: Atom.Index, code: []u8) !void {53pub fn resolve(self: Relocation, macho_file: *MachO, atom_index: Atom.Index, code: []u8) void {
54 const arch = macho_file.base.options.target.cpu.arch;54 const arch = macho_file.base.options.target.cpu.arch;
55 const atom = macho_file.getAtom(atom_index);55 const atom = macho_file.getAtom(atom_index);
56 const source_sym = atom.getSymbol(macho_file);56 const source_sym = atom.getSymbol(macho_file);
...@@ -68,18 +68,13 @@ pub fn resolve(self: Relocation, macho_file: *MachO, atom_index: Atom.Index, cod...@@ -68,18 +68,13 @@ pub fn resolve(self: Relocation, macho_file: *MachO, atom_index: Atom.Index, cod
68 });68 });
6969
70 switch (arch) {70 switch (arch) {
71 .aarch64 => return self.resolveAarch64(source_addr, target_addr, code),71 .aarch64 => self.resolveAarch64(source_addr, target_addr, code),
72 .x86_64 => return self.resolveX8664(source_addr, target_addr, code),72 .x86_64 => self.resolveX8664(source_addr, target_addr, code),
73 else => unreachable,73 else => unreachable,
74 }74 }
75}75}
7676
77fn resolveAarch64(77fn resolveAarch64(self: Relocation, source_addr: u64, target_addr: i64, code: []u8) void {
78 self: Relocation,
79 source_addr: u64,
80 target_addr: i64,
81 code: []u8,
82) !void {
83 const rel_type = @intToEnum(macho.reloc_type_arm64, self.type);78 const rel_type = @intToEnum(macho.reloc_type_arm64, self.type);
84 if (rel_type == .ARM64_RELOC_UNSIGNED) {79 if (rel_type == .ARM64_RELOC_UNSIGNED) {
85 return switch (self.length) {80 return switch (self.length) {
...@@ -212,12 +207,7 @@ fn resolveAarch64(...@@ -212,12 +207,7 @@ fn resolveAarch64(
212 }207 }
213}208}
214209
215fn resolveX8664(210fn resolveX8664(self: Relocation, source_addr: u64, target_addr: i64, code: []u8) void {
216 self: Relocation,
217 source_addr: u64,
218 target_addr: i64,
219 code: []u8,
220) !void {
221 const rel_type = @intToEnum(macho.reloc_type_x86_64, self.type);211 const rel_type = @intToEnum(macho.reloc_type_x86_64, self.type);
222 switch (rel_type) {212 switch (rel_type) {
223 .X86_64_RELOC_BRANCH,213 .X86_64_RELOC_BRANCH,