mirror of
https://github.com/ziglang/zig.git
synced 2026-01-03 03:53:20 +00:00
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:
parent
9e051e365b
commit
570660bb46
@ -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;
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user