authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-07 12:06:31+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-03-17 19:59:13+01:00
log62f43fbc068ae63b6492af20a7cfd38b7426cb92
tree45090e6bd83b527241bed1375d4bf2112341c774
parentd484b3b3cbebddc3e1e8b160152e3f8e3be93b63

zld: clean up use of commands.zig module


2 files changed, 13 insertions(+), 64 deletions(-)

src/link/MachO/Zld.zig+13-59
......@@ -377,7 +377,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
377377 if (self.text_const_section_index != null) continue;
378378
379379 self.text_const_section_index = @intCast(u16, text_seg.sections.items.len);
380 try text_seg.append(self.allocator, .{
380 try text_seg.addSection(self.allocator, .{
381381 .sectname = makeStaticString("__const"),
382382 .segname = makeStaticString("__TEXT"),
383383 .addr = 0,
......@@ -396,7 +396,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
396396 if (self.data_const_section_index != null) continue;
397397
398398 self.data_const_section_index = @intCast(u16, data_seg.sections.items.len);
399 try data_seg.append(self.allocator, .{
399 try data_seg.addSection(self.allocator, .{
400400 .sectname = makeStaticString("__const"),
401401 .segname = makeStaticString("__DATA"),
402402 .addr = 0,
......@@ -417,7 +417,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
417417 if (self.cstring_section_index != null) continue;
418418
419419 self.cstring_section_index = @intCast(u16, text_seg.sections.items.len);
420 try text_seg.append(self.allocator, .{
420 try text_seg.addSection(self.allocator, .{
421421 .sectname = makeStaticString("__cstring"),
422422 .segname = makeStaticString("__TEXT"),
423423 .addr = 0,
......@@ -437,7 +437,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
437437 if (self.bss_section_index != null) continue;
438438
439439 self.bss_section_index = @intCast(u16, data_seg.sections.items.len);
440 try data_seg.append(self.allocator, .{
440 try data_seg.addSection(self.allocator, .{
441441 .sectname = makeStaticString("__bss"),
442442 .segname = makeStaticString("__DATA"),
443443 .addr = 0,
......@@ -457,7 +457,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
457457 if (self.tlv_section_index != null) continue;
458458
459459 self.tlv_section_index = @intCast(u16, data_seg.sections.items.len);
460 try data_seg.append(self.allocator, .{
460 try data_seg.addSection(self.allocator, .{
461461 .sectname = makeStaticString("__thread_vars"),
462462 .segname = makeStaticString("__DATA"),
463463 .addr = 0,
......@@ -477,7 +477,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
477477 if (self.tlv_data_section_index != null) continue;
478478
479479 self.tlv_data_section_index = @intCast(u16, data_seg.sections.items.len);
480 try data_seg.append(self.allocator, .{
480 try data_seg.addSection(self.allocator, .{
481481 .sectname = makeStaticString("__thread_data"),
482482 .segname = makeStaticString("__DATA"),
483483 .addr = 0,
......@@ -497,7 +497,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void {
497497 if (self.tlv_bss_section_index != null) continue;
498498
499499 self.tlv_bss_section_index = @intCast(u16, data_seg.sections.items.len);
500 try data_seg.append(self.allocator, .{
500 try data_seg.addSection(self.allocator, .{
501501 .sectname = makeStaticString("__thread_bss"),
502502 .segname = makeStaticString("__DATA"),
503503 .addr = 0,
......@@ -1842,7 +1842,7 @@ fn populateMetadata(self: *Zld) !void {
18421842 .aarch64 => 2,
18431843 else => unreachable, // unhandled architecture type
18441844 };
1845 try text_seg.append(self.allocator, .{
1845 try text_seg.addSection(self.allocator, .{
18461846 .sectname = makeStaticString("__text"),
18471847 .segname = makeStaticString("__TEXT"),
18481848 .addr = 0,
......@@ -1871,7 +1871,7 @@ fn populateMetadata(self: *Zld) !void {
18711871 .aarch64 => 3 * @sizeOf(u32),
18721872 else => unreachable, // unhandled architecture type
18731873 };
1874 try text_seg.append(self.allocator, .{
1874 try text_seg.addSection(self.allocator, .{
18751875 .sectname = makeStaticString("__stubs"),
18761876 .segname = makeStaticString("__TEXT"),
18771877 .addr = 0,
......@@ -1900,7 +1900,7 @@ fn populateMetadata(self: *Zld) !void {
19001900 .aarch64 => 6 * @sizeOf(u32),
19011901 else => unreachable,
19021902 };
1903 try text_seg.append(self.allocator, .{
1903 try text_seg.addSection(self.allocator, .{
19041904 .sectname = makeStaticString("__stub_helper"),
19051905 .segname = makeStaticString("__TEXT"),
19061906 .addr = 0,
......@@ -1938,7 +1938,7 @@ fn populateMetadata(self: *Zld) !void {
19381938 if (self.got_section_index == null) {
19391939 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
19401940 self.got_section_index = @intCast(u16, data_seg.sections.items.len);
1941 try data_seg.append(self.allocator, .{
1941 try data_seg.addSection(self.allocator, .{
19421942 .sectname = makeStaticString("__got"),
19431943 .segname = makeStaticString("__DATA"),
19441944 .addr = 0,
......@@ -1957,7 +1957,7 @@ fn populateMetadata(self: *Zld) !void {
19571957 if (self.la_symbol_ptr_section_index == null) {
19581958 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
19591959 self.la_symbol_ptr_section_index = @intCast(u16, data_seg.sections.items.len);
1960 try data_seg.append(self.allocator, .{
1960 try data_seg.addSection(self.allocator, .{
19611961 .sectname = makeStaticString("__la_symbol_ptr"),
19621962 .segname = makeStaticString("__DATA"),
19631963 .addr = 0,
......@@ -1976,7 +1976,7 @@ fn populateMetadata(self: *Zld) !void {
19761976 if (self.data_section_index == null) {
19771977 const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment;
19781978 self.data_section_index = @intCast(u16, data_seg.sections.items.len);
1979 try data_seg.append(self.allocator, .{
1979 try data_seg.addSection(self.allocator, .{
19801980 .sectname = makeStaticString("__data"),
19811981 .segname = makeStaticString("__DATA"),
19821982 .addr = 0,
......@@ -2290,41 +2290,8 @@ fn writeRebaseInfoTable(self: *Zld) !void {
22902290 try pointers.ensureCapacity(pointers.items.len + self.local_rebases.items.len);
22912291 pointers.appendSliceAssumeCapacity(self.local_rebases.items);
22922292
2293 // const text_seg = self.load_commands.items[self.text_segment_cmd_index.?].Segment;
2294 // const base_id = text_seg.sections.items.len;
2295 // for (self.locals.items()) |entry| {
2296 // for (entry.value.items) |symbol| {
2297 // const local = symbol.inner;
2298
2299 // if (self.data_const_section_index) |index| {
2300 // if (local.n_sect == base_id + index) {
2301 // const offset = local.n_value - data_seg.inner.vmaddr;
2302 // try pointers.append(.{
2303 // .offset = offset,
2304 // .segment_id = @intCast(u16, self.data_segment_cmd_index.?),
2305 // });
2306 // }
2307 // }
2308 // if (self.data_section_index) |index| {
2309 // if (local.n_sect == base_id + index) {
2310 // const offset = local.n_value - data_seg.inner.vmaddr;
2311 // try pointers.append(.{
2312 // .offset = offset,
2313 // .segment_id = @intCast(u16, self.data_segment_cmd_index.?),
2314 // });
2315 // }
2316 // }
2317 // }
2318 // }
2319
23202293 std.sort.sort(Pointer, pointers.items, {}, pointerCmp);
23212294
2322 // const nlocals = self.local_rebases.items.len;
2323 // var i = nlocals;
2324 // while (i > 0) : (i -= 1) {
2325 // pointers.appendAssumeCapacity(self.local_rebases.items[i - 1]);
2326 // }
2327
23282295 const size = try rebaseInfoSize(pointers.items);
23292296 var buffer = try self.allocator.alloc(u8, @intCast(usize, size));
23302297 defer self.allocator.free(buffer);
......@@ -2698,21 +2665,8 @@ fn writeSymbolTable(self: *Zld) !void {
26982665 log.debug(" | {}", .{entry.inner});
26992666 log.debug(" | {}", .{entry.tt});
27002667 log.debug(" | {s}", .{self.objects.items[entry.object_id].name});
2701 // switch (entry.tt) {
2702 // .Global => {
2703 // symbol = entry.inner;
2704 // break;
2705 // },
2706 // .WeakGlobal => {
2707 // symbol = entry.inner;
2708 // },
2709 // .Local => {},
2710 // }
27112668 try locals.append(entry.inner);
27122669 }
2713 // if (symbol) |s| {
2714 // try locals.append(s);
2715 // }
27162670 }
27172671 const nlocals = locals.items.len;
27182672
src/link/MachO/commands.zig-5
......@@ -166,11 +166,6 @@ pub const SegmentCommand = struct {
166166 return .{ .inner = inner };
167167 }
168168
169 // TODO remove me, I'm just a temp!
170 pub fn append(self: *SegmentCommand, alloc: *Allocator, section: macho.section_64) !void {
171 return self.addSection(alloc, section);
172 }
173
174169 pub fn addSection(self: *SegmentCommand, alloc: *Allocator, section: macho.section_64) !void {
175170 try self.sections.append(alloc, section);
176171 self.inner.cmdsize += @sizeOf(macho.section_64);