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 {...@@ -530,7 +530,7 @@ pub fn parseTextBlocks(self: *Object, zld: *Zld) !void {
530 const reg = &sym.payload.regular;530 const reg = &sym.payload.regular;
531 if (reg.file) |file| {531 if (reg.file) |file| {
532 if (file != self) {532 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.? });
534 block.deinit();534 block.deinit();
535 self.allocator.destroy(block);535 self.allocator.destroy(block);
536 continue;536 continue;
src/link/MachO/Zld.zig+8-2
...@@ -1686,10 +1686,16 @@ fn resolveSymbols(self: *Zld) !void {...@@ -1686,10 +1686,16 @@ fn resolveSymbols(self: *Zld) !void {
1686 // Fourth pass, handle synthetic symbols and flag any undefined references.1686 // Fourth pass, handle synthetic symbols and flag any undefined references.
1687 if (self.globals.get("___dso_handle")) |symbol| {1687 if (self.globals.get("___dso_handle")) |symbol| {
1688 if (symbol.payload == .undef) {1688 if (symbol.payload == .undef) {
1689 const seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
1689 symbol.payload = .{1690 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 },
1691 };1697 };
1692 try self.imports.append(self.allocator, symbol);1698 try self.locals.append(self.allocator, symbol);
1693 }1699 }
1694 }1700 }
16951701
src/link/MachO/reloc.zig+5-2
...@@ -411,6 +411,8 @@ pub const Relocation = struct {...@@ -411,6 +411,8 @@ pub const Relocation = struct {
411 };411 };
412412
413 pub fn resolve(self: Relocation, zld: *Zld) !void {413 pub fn resolve(self: Relocation, zld: *Zld) !void {
414 log.debug("relocating {}", .{self});
415
414 const source_addr = blk: {416 const source_addr = blk: {
415 const sym = zld.locals.items[self.block.local_sym_index];417 const sym = zld.locals.items[self.block.local_sym_index];
416 break :blk sym.payload.regular.address + self.offset;418 break :blk sym.payload.regular.address + self.offset;
...@@ -497,7 +499,6 @@ pub const Relocation = struct {...@@ -497,7 +499,6 @@ pub const Relocation = struct {
497 }499 }
498 };500 };
499501
500 log.debug("relocating {}", .{self});
501 log.debug(" | source_addr = 0x{x}", .{source_addr});502 log.debug(" | source_addr = 0x{x}", .{source_addr});
502 log.debug(" | target_addr = 0x{x}", .{target_addr});503 log.debug(" | target_addr = 0x{x}", .{target_addr});
503504
...@@ -703,7 +704,9 @@ pub const Parser = struct {...@@ -703,7 +704,9 @@ pub const Parser = struct {
703704
704 if (!is_right_segment) break :rebase false;705 if (!is_right_segment) break :rebase false;
705 if (sect_type != macho.S_LITERAL_POINTERS and706 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)
707 {710 {
708 break :rebase false;711 break :rebase false;
709 }712 }