commit 570660bb4658823227d9cb227b1585eccff2af50 (tree)
parent 9e051e365b689cb4e6ceae5910fb70fe6a7eb0f8
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Sun, 11 Jul 2021 10:04:13 +0200
zld: ___dso_handle is regular at 0x100000000
which points at the start of the __TEXT segment.
Also, ensure C++ initializers and terminators are rebased.
Diffstat:
3 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig
@@ -530,7 +530,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {
const reg = &sym.payload.regular;
if (reg.file) |file| {
if (file != self) {
- log.warn("deduping definition of {s} in {s}", .{ sym.name, self.name.? });
+ log.debug("deduping definition of {s} in {s}", .{ sym.name, self.name.? });
block.deinit();
self.allocator.destroy(block);
continue;
diff --git a/src/link/MachO/Zld.zig b/src/link/MachO/Zld.zig
@@ -1686,10 +1686,16 @@ fn resolveSymbols(self: *Zld) !void {
// Fourth pass, handle synthetic symbols and flag any undefined references.
if (self.globals.get("___dso_handle")) |symbol| {
if (symbol.payload == .undef) {
+ const seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
symbol.payload = .{
- .proxy = .{},
+ .regular = .{
+ .linkage = .translation_unit,
+ .address = seg.inner.vmaddr,
+ .weak_ref = true,
+ .local_sym_index = @intCast(u32, self.locals.items.len),
+ },
};
- try self.imports.append(self.allocator, symbol);
+ try self.locals.append(self.allocator, symbol);
}
}
diff --git a/src/link/MachO/reloc.zig b/src/link/MachO/reloc.zig
@@ -411,6 +411,8 @@ pub const Relocation = struct {
};
pub fn resolve(self: Relocation, zld: *Zld) !void {
+ log.debug("relocating {}", .{self});
+
const source_addr = blk: {
const sym = zld.locals.items[self.block.local_sym_index];
break :blk sym.payload.regular.address + self.offset;
@@ -497,7 +499,6 @@ pub const Relocation = struct {
}
};
- log.debug("relocating {}", .{self});
log.debug(" | source_addr = 0x{x}", .{source_addr});
log.debug(" | target_addr = 0x{x}", .{target_addr});
@@ -703,7 +704,9 @@ pub const Parser = struct {
if (!is_right_segment) break :rebase false;
if (sect_type != macho.S_LITERAL_POINTERS and
- sect_type != macho.S_REGULAR)
+ sect_type != macho.S_REGULAR and
+ sect_type != macho.S_MOD_INIT_FUNC_POINTERS and
+ sect_type != macho.S_MOD_TERM_FUNC_POINTERS)
{
break :rebase false;
}