aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Zld.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2021-07-07 22:15:41 +0200
committerJakub Konka <kubkon@jakubkonka.com>2021-07-15 18:49:47 +0200
commite524f43a6fbb5189d24aa42667ababdcd92a2ab2 (patch)
treeec68e9b10d3c6d9e03932db7a09459419ccbf3e4 /src/link/MachO/Zld.zig
parent7c662db8d95670f8ac0c88e9a2d6f49ef6782f13 (diff)
downloadzig-e524f43a6fbb5189d24aa42667ababdcd92a2ab2.tar.gz
zig-e524f43a6fbb5189d24aa42667ababdcd92a2ab2.zip
zld: save rebase and TLV offset as part of TextBlock
instead of as part of the Symbol. This seems to be more optimal way of handling dyld ops in presence of no splittable input sections in object files.
Diffstat (limited to 'src/link/MachO/Zld.zig')
-rw-r--r--src/link/MachO/Zld.zig29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/link/MachO/Zld.zig b/src/link/MachO/Zld.zig
index 485f6eda42..53bb31a718 100644
--- a/src/link/MachO/Zld.zig
+++ b/src/link/MachO/Zld.zig
@@ -128,6 +128,8 @@ pub const TextBlock = struct {
relocs: std.ArrayList(Relocation),
size: u64,
alignment: u32,
+ rebases: std.ArrayList(u64),
+ tlv_offsets: std.ArrayList(u64),
next: ?*TextBlock = null,
prev: ?*TextBlock = null,
@@ -137,6 +139,8 @@ pub const TextBlock = struct {
}
block.relocs.deinit();
block.references.deinit();
+ block.rebases.deinit();
+ block.tlv_offsets.deinit();
allocator.free(block.code);
}
@@ -144,24 +148,30 @@ pub const TextBlock = struct {
log.warn("TextBlock", .{});
log.warn(" | {}: {}", .{ self.local_sym_index, zld.locals.items[self.local_sym_index] });
if (self.aliases) |aliases| {
- log.warn(" | Aliases:", .{});
+ log.warn(" | aliases:", .{});
for (aliases) |index| {
log.warn(" | {}: {}", .{ index, zld.locals.items[index] });
}
}
if (self.references.count() > 0) {
- log.warn(" | References:", .{});
+ log.warn(" | references:", .{});
for (self.references.keys()) |index| {
log.warn(" | {}: {}", .{ index, zld.locals.items[index] });
}
}
log.warn(" | code.len = {}", .{self.code.len});
if (self.relocs.items.len > 0) {
- log.warn("Relocations:", .{});
+ log.warn(" | relocations:", .{});
for (self.relocs.items) |rel| {
- log.warn(" | {}", .{rel});
+ log.warn(" | {}", .{rel});
}
}
+ if (self.rebases.items.len > 0) {
+ log.warn(" | rebases: {any}", .{self.rebases.items});
+ }
+ if (self.tlv_offsets.items.len > 0) {
+ log.warn(" | TLV offsets: {any}", .{self.tlv_offsets.items});
+ }
log.warn(" | size = {}", .{self.size});
log.warn(" | align = {}", .{self.alignment});
}
@@ -271,6 +281,10 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg
try self.addRpaths(args.rpaths);
try self.addDataInCodeLC();
try self.addCodeSignatureLC();
+ // try self.allocateTextSegment();
+ // try self.allocateDataConstSegment();
+ // try self.allocateDataSegment();
+ // self.allocateLinkeditSegment();
var it = self.blocks.iterator();
while (it.next()) |entry| {
@@ -281,11 +295,6 @@ pub fn link(self: *Zld, files: []const []const u8, output: Output, args: LinkArg
entry.value_ptr.*.print(self);
}
return error.TODO;
- // try self.allocateTextSegment();
- // try self.allocateDataConstSegment();
- // try self.allocateDataSegment();
- // self.allocateLinkeditSegment();
- // try self.allocateSymbols();
// try self.flush();
}
@@ -1477,6 +1486,8 @@ fn resolveSymbols(self: *Zld) !void {
.references = std.AutoArrayHashMap(u32, void).init(self.allocator),
.code = code,
.relocs = std.ArrayList(Relocation).init(self.allocator),
+ .rebases = std.ArrayList(u64).init(self.allocator),
+ .tlv_offsets = std.ArrayList(u64).init(self.allocator),
.size = size,
.alignment = alignment,
};