From 7d40aaad2b514703995458909b315f222543c4cd Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sat, 9 Jan 2021 20:38:55 +0100 Subject: macho: document more code + add test case --- src/codegen.zig | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index ad4215191f..05898c77c8 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -1865,19 +1865,16 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type { // If it doesn't, it will get autofreed when we clean up the extern symbol table. const decl_name = try std.fmt.allocPrint(self.bin_file.allocator, "_{s}", .{decl.name}); const already_defined = macho_file.extern_lazy_symbols.contains(decl_name); - const symbol: u32 = blk: { - if (macho_file.extern_lazy_symbols.get(decl_name)) |sym| { - self.bin_file.allocator.free(decl_name); - break :blk sym.index; - } else { - const index = @intCast(u32, macho_file.extern_lazy_symbols.items().len); - try macho_file.extern_lazy_symbols.putNoClobber(self.bin_file.allocator, decl_name, .{ - .name = decl_name, - .dylib_ordinal = 1, // TODO this is now hardcoded, since we only support libSystem. - .index = index, - }); - break :blk index; - } + const symbol: u32 = if (macho_file.extern_lazy_symbols.getIndex(decl_name)) |index| blk: { + self.bin_file.allocator.free(decl_name); + break :blk @intCast(u32, index); + } else blk: { + const index = @intCast(u32, macho_file.extern_lazy_symbols.items().len); + try macho_file.extern_lazy_symbols.putNoClobber(self.bin_file.allocator, decl_name, .{ + .name = decl_name, + .dylib_ordinal = 1, // TODO this is now hardcoded, since we only support libSystem. + }); + break :blk index; }; try macho_file.stub_fixups.append(self.bin_file.allocator, .{ .symbol = symbol, -- cgit v1.2.3