| author | |
| committer | |
| log | 570660bb4658823227d9cb227b1585eccff2af50 |
| tree | 7a241f1e70e38e691683efea6f855f5de92a38e9 |
| parent | 9e051e365b689cb4e6ceae5910fb70fe6a7eb0f8 |
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 | } |
| 1695 | 1701 |
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 | }; |
| 412 | 412 | ||
| 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 | }; |
| 499 | 501 | ||
| 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}); |
| 503 | 504 | ||
| ... | @@ -703,7 +704,9 @@ pub const Parser = struct { | ... | @@ -703,7 +704,9 @@ pub const Parser = struct { |
| 703 | 704 | ||
| 704 | if (!is_right_segment) break :rebase false; | 705 | if (!is_right_segment) break :rebase false; |
| 705 | if (sect_type != macho.S_LITERAL_POINTERS and | 706 | 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 | } |