authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-11 10:04:13+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-07-15 18:49:47+02:00
log570660bb4658823227d9cb227b1585eccff2af50
tree7a241f1e70e38e691683efea6f855f5de92a38e9
parent9e051e365b689cb4e6ceae5910fb70fe6a7eb0f8

zld: ___dso_handle is regular at 0x100000000

which points at the start of the __TEXT segment. Also, ensure C++ initializers and terminators are rebased.

3 files changed, 14 insertions(+), 5 deletions(-)

src/link/MachO/Object.zig+1-1
......@@ -530,7 +530,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {
530530 const reg = &sym.payload.regular;
531531 if (reg.file) |file| {
532532 if (file != self) {
533 log.warn("deduping definition of {s} in {s}", .{ sym.name, self.name.? });
533 log.debug("deduping definition of {s} in {s}", .{ sym.name, self.name.? });
534534 block.deinit();
535535 self.allocator.destroy(block);
536536 continue;
src/link/MachO/Zld.zig+8-2
......@@ -1686,10 +1686,16 @@ fn resolveSymbols(self: *Zld) !void {
16861686 // Fourth pass, handle synthetic symbols and flag any undefined references.
16871687 if (self.globals.get("___dso_handle")) |symbol| {
16881688 if (symbol.payload == .undef) {
1689 const seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
16891690 symbol.payload = .{
1690 .proxy = .{},
1691 .regular = .{
1692 .linkage = .translation_unit,
1693 .address = seg.inner.vmaddr,
1694 .weak_ref = true,
1695 .local_sym_index = @intCast(u32, self.locals.items.len),
1696 },
16911697 };
1692 try self.imports.append(self.allocator, symbol);
1698 try self.locals.append(self.allocator, symbol);
16931699 }
16941700 }
16951701
src/link/MachO/reloc.zig+5-2
......@@ -411,6 +411,8 @@ pub const Relocation = struct {
411411 };
412412
413413 pub fn resolve(self: Relocation, zld: *Zld) !void {
414 log.debug("relocating {}", .{self});
415
414416 const source_addr = blk: {
415417 const sym = zld.locals.items[self.block.local_sym_index];
416418 break :blk sym.payload.regular.address + self.offset;
......@@ -497,7 +499,6 @@ pub const Relocation = struct {
497499 }
498500 };
499501
500 log.debug("relocating {}", .{self});
501502 log.debug(" | source_addr = 0x{x}", .{source_addr});
502503 log.debug(" | target_addr = 0x{x}", .{target_addr});
503504
......@@ -703,7 +704,9 @@ pub const Parser = struct {
703704
704705 if (!is_right_segment) break :rebase false;
705706 if (sect_type != macho.S_LITERAL_POINTERS and
706 sect_type != macho.S_REGULAR)
707 sect_type != macho.S_REGULAR and
708 sect_type != macho.S_MOD_INIT_FUNC_POINTERS and
709 sect_type != macho.S_MOD_TERM_FUNC_POINTERS)
707710 {
708711 break :rebase false;
709712 }