diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2022-07-25 18:26:06 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2022-07-25 22:46:43 -0700 |
| commit | 20ea44ef107828d76692e610e1ca62ee231fb4a9 (patch) | |
| tree | 3cdd9e3816f57c9b5e2469af238c69e2520e68cb /src/link/MachO/Object.zig | |
| parent | cff5d9c805aa3433cc2562c3cb29bd3201817214 (diff) | |
| download | zig-20ea44ef107828d76692e610e1ca62ee231fb4a9.tar.gz zig-20ea44ef107828d76692e610e1ca62ee231fb4a9.zip | |
macho: fix memory leak and refactor Target usage
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index 5e10c0c0a3..c7fb4f3ee4 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -66,6 +66,7 @@ pub fn deinit(self: *Object, gpa: Allocator) void { } self.load_commands.deinit(gpa); gpa.free(self.contents); + self.symtab.deinit(gpa); self.sections_as_symbols.deinit(gpa); self.atom_by_index_table.deinit(gpa); @@ -78,7 +79,7 @@ pub fn deinit(self: *Object, gpa: Allocator) void { gpa.free(self.name); } -pub fn parse(self: *Object, allocator: Allocator, target: std.Target) !void { +pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch) !void { const file_stat = try self.file.stat(); const file_size = math.cast(usize, file_stat.size) orelse return error.Overflow; self.contents = try self.file.readToEndAlloc(allocator, file_size); @@ -108,8 +109,8 @@ pub fn parse(self: *Object, allocator: Allocator, target: std.Target) !void { return error.UnsupportedCpuArchitecture; }, }; - if (this_arch != target.cpu.arch) { - log.err("mismatched cpu architecture: expected {s}, found {s}", .{ target.cpu.arch, this_arch }); + if (this_arch != cpu_arch) { + log.err("mismatched cpu architecture: expected {s}, found {s}", .{ cpu_arch, this_arch }); return error.MismatchedCpuArchitecture; } @@ -351,7 +352,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) macho_file.getSection(match).sectName(), }); - const arch = macho_file.base.options.target.cpu.arch; + const cpu_arch = macho_file.base.options.target.cpu.arch; const is_zerofill = blk: { const section_type = sect.type_(); break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL; @@ -466,7 +467,7 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) sect, ); - if (arch == .x86_64 and addr == sect.addr) { + if (cpu_arch == .x86_64 and addr == sect.addr) { // In x86_64 relocs, it can so happen that the compiler refers to the same // atom by both the actual assigned symbol and the start of the section. In this // case, we need to link the two together so add an alias. |
