macho: document more code + add test case

This commit is contained in:
Jakub Konka
2021-01-09 20:38:55 +01:00
parent b86d0e488b
commit 7d40aaad2b
4 changed files with 72 additions and 63 deletions

View File

@@ -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,