Skip to content

Commit

Permalink
macho: clean up managing objc synthetic globals in internal object
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Jan 27, 2024
1 parent 7b33275 commit ff2c70d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/MachO.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1240,18 +1240,17 @@ fn createObjcSections(self: *MachO) !void {
}

for (objc_msgsend_syms.keys()) |sym_index| {
const internal = self.getInternalObject().?;
const sym = self.getSymbol(sym_index);
_ = try internal.addSymbol(sym.getName(self), self);
sym.value = 0;
sym.atom = 0;
sym.nlist_idx = 0;
sym.file = self.internal_object_index.?;
sym.flags = .{};
sym.flags = .{ .global = true };
sym.visibility = .hidden;
const object = self.getInternalObject().?;
const name = eatPrefix(sym.getName(self), "_objc_msgSend$").?;
const selrefs_index = try object.addObjcMsgsendSections(name, self);
const selrefs_index = try internal.addObjcMsgsendSections(name, self);
try sym.addExtra(.{ .objc_selrefs = selrefs_index }, self);
try object.symbols.append(gpa, sym_index);
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/MachO/InternalObject.zig
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ pub fn addSymbol(self: *InternalObject, name: [:0]const u8, macho_file: *MachO)
const gop = try macho_file.getOrCreateGlobal(off);
self.symbols.addOneAssumeCapacity().* = gop.index;
const sym = macho_file.getSymbol(gop.index);
sym.* = .{ .name = off, .file = self.index };
sym.flags.global = true;
sym.file = self.index;
return gop.index;
}

Expand Down
4 changes: 2 additions & 2 deletions src/MachO/Symbol.zig
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub fn weakRef(symbol: Symbol, macho_file: *MachO) bool {
pub fn getName(symbol: Symbol, macho_file: *MachO) [:0]const u8 {
if (symbol.flags.global) return macho_file.string_intern.getAssumeExists(symbol.name);
return switch (symbol.getFile(macho_file).?) {
.object => |x| x.getString(symbol.name),
else => macho_file.string_intern.getAssumeExists(symbol.name),
.dylib => unreachable, // There are no local symbols for dylibs
inline else => |x| x.getString(symbol.name),
};
}

Expand Down

0 comments on commit ff2c70d

Please sign in to comment.