aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-01-17 17:20:55 +0100
committerJakub Konka <kubkon@jakubkonka.com>2021-01-17 21:01:52 +0100
commit81183365852e7f871500a3f71810ae3b468f0027 (patch)
tree96a4de9d67ed5cf4330c81564c23973db381a7d3 /src/codegen.zig
parent3562edf13772bca66b4f04fc87be25b518393221 (diff)
downloadzig-81183365852e7f871500a3f71810ae3b468f0027.tar.gz
zig-81183365852e7f871500a3f71810ae3b468f0027.zip
macho: refactor undef symbol handling
Now, we don't erroneously write to the string table on every write of global and undef symbols.
Diffstat (limited to 'src/codegen.zig')
-rw-r--r--src/codegen.zig18
1 files changed, 5 insertions, 13 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index 1478ede6ff..430adc8137 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -1920,21 +1920,13 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
}
} else if (func_value.castTag(.extern_fn)) |func_payload| {
const decl = func_payload.data;
- // We don't free the decl_name immediately unless it already exists.
- // 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});
+ defer self.bin_file.allocator.free(decl_name);
const already_defined = macho_file.extern_lazy_symbols.contains(decl_name);
- 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;
- };
+ const symbol: u32 = if (macho_file.extern_lazy_symbols.getIndex(decl_name)) |index|
+ @intCast(u32, index)
+ else
+ try macho_file.addExternSymbol(decl_name);
const start = self.code.items.len;
const len: usize = blk: {
switch (arch) {