zld: ___dso_handle is regular at 0x100000000

which points at the start of the __TEXT segment.

Also, ensure C++ initializers and terminators are rebased.
This commit is contained in:
Jakub Konka 2021-07-11 10:04:13 +02:00
parent 9e051e365b
commit 570660bb46
3 changed files with 14 additions and 5 deletions

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
}