| ... | ... | @@ -377,7 +377,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 377 | 377 | if (self.text_const_section_index != null) continue; |
| 378 | 378 | |
| 379 | 379 | 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, .{ |
| 381 | 381 | .sectname = makeStaticString("__const"), |
| 382 | 382 | .segname = makeStaticString("__TEXT"), |
| 383 | 383 | .addr = 0, |
| ... | ... | @@ -396,7 +396,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 396 | 396 | if (self.data_const_section_index != null) continue; |
| 397 | 397 | |
| 398 | 398 | 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, .{ |
| 400 | 400 | .sectname = makeStaticString("__const"), |
| 401 | 401 | .segname = makeStaticString("__DATA"), |
| 402 | 402 | .addr = 0, |
| ... | ... | @@ -417,7 +417,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 417 | 417 | if (self.cstring_section_index != null) continue; |
| 418 | 418 | |
| 419 | 419 | 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, .{ |
| 421 | 421 | .sectname = makeStaticString("__cstring"), |
| 422 | 422 | .segname = makeStaticString("__TEXT"), |
| 423 | 423 | .addr = 0, |
| ... | ... | @@ -437,7 +437,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 437 | 437 | if (self.bss_section_index != null) continue; |
| 438 | 438 | |
| 439 | 439 | 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, .{ |
| 441 | 441 | .sectname = makeStaticString("__bss"), |
| 442 | 442 | .segname = makeStaticString("__DATA"), |
| 443 | 443 | .addr = 0, |
| ... | ... | @@ -457,7 +457,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 457 | 457 | if (self.tlv_section_index != null) continue; |
| 458 | 458 | |
| 459 | 459 | 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, .{ |
| 461 | 461 | .sectname = makeStaticString("__thread_vars"), |
| 462 | 462 | .segname = makeStaticString("__DATA"), |
| 463 | 463 | .addr = 0, |
| ... | ... | @@ -477,7 +477,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 477 | 477 | if (self.tlv_data_section_index != null) continue; |
| 478 | 478 | |
| 479 | 479 | 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, .{ |
| 481 | 481 | .sectname = makeStaticString("__thread_data"), |
| 482 | 482 | .segname = makeStaticString("__DATA"), |
| 483 | 483 | .addr = 0, |
| ... | ... | @@ -497,7 +497,7 @@ fn updateMetadata(self: *Zld, object_id: u16) !void { |
| 497 | 497 | if (self.tlv_bss_section_index != null) continue; |
| 498 | 498 | |
| 499 | 499 | 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, .{ |
| 501 | 501 | .sectname = makeStaticString("__thread_bss"), |
| 502 | 502 | .segname = makeStaticString("__DATA"), |
| 503 | 503 | .addr = 0, |
| ... | ... | @@ -1842,7 +1842,7 @@ fn populateMetadata(self: *Zld) !void { |
| 1842 | 1842 | .aarch64 => 2, |
| 1843 | 1843 | else => unreachable, // unhandled architecture type |
| 1844 | 1844 | }; |
| 1845 | | try text_seg.append(self.allocator, .{ |
| 1845 | try text_seg.addSection(self.allocator, .{ |
| 1846 | 1846 | .sectname = makeStaticString("__text"), |
| 1847 | 1847 | .segname = makeStaticString("__TEXT"), |
| 1848 | 1848 | .addr = 0, |
| ... | ... | @@ -1871,7 +1871,7 @@ fn populateMetadata(self: *Zld) !void { |
| 1871 | 1871 | .aarch64 => 3 * @sizeOf(u32), |
| 1872 | 1872 | else => unreachable, // unhandled architecture type |
| 1873 | 1873 | }; |
| 1874 | | try text_seg.append(self.allocator, .{ |
| 1874 | try text_seg.addSection(self.allocator, .{ |
| 1875 | 1875 | .sectname = makeStaticString("__stubs"), |
| 1876 | 1876 | .segname = makeStaticString("__TEXT"), |
| 1877 | 1877 | .addr = 0, |
| ... | ... | @@ -1900,7 +1900,7 @@ fn populateMetadata(self: *Zld) !void { |
| 1900 | 1900 | .aarch64 => 6 * @sizeOf(u32), |
| 1901 | 1901 | else => unreachable, |
| 1902 | 1902 | }; |
| 1903 | | try text_seg.append(self.allocator, .{ |
| 1903 | try text_seg.addSection(self.allocator, .{ |
| 1904 | 1904 | .sectname = makeStaticString("__stub_helper"), |
| 1905 | 1905 | .segname = makeStaticString("__TEXT"), |
| 1906 | 1906 | .addr = 0, |
| ... | ... | @@ -1938,7 +1938,7 @@ fn populateMetadata(self: *Zld) !void { |
| 1938 | 1938 | if (self.got_section_index == null) { |
| 1939 | 1939 | const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment; |
| 1940 | 1940 | 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, .{ |
| 1942 | 1942 | .sectname = makeStaticString("__got"), |
| 1943 | 1943 | .segname = makeStaticString("__DATA"), |
| 1944 | 1944 | .addr = 0, |
| ... | ... | @@ -1957,7 +1957,7 @@ fn populateMetadata(self: *Zld) !void { |
| 1957 | 1957 | if (self.la_symbol_ptr_section_index == null) { |
| 1958 | 1958 | const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment; |
| 1959 | 1959 | 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, .{ |
| 1961 | 1961 | .sectname = makeStaticString("__la_symbol_ptr"), |
| 1962 | 1962 | .segname = makeStaticString("__DATA"), |
| 1963 | 1963 | .addr = 0, |
| ... | ... | @@ -1976,7 +1976,7 @@ fn populateMetadata(self: *Zld) !void { |
| 1976 | 1976 | if (self.data_section_index == null) { |
| 1977 | 1977 | const data_seg = &self.load_commands.items[self.data_segment_cmd_index.?].Segment; |
| 1978 | 1978 | 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, .{ |
| 1980 | 1980 | .sectname = makeStaticString("__data"), |
| 1981 | 1981 | .segname = makeStaticString("__DATA"), |
| 1982 | 1982 | .addr = 0, |
| ... | ... | @@ -2290,41 +2290,8 @@ fn writeRebaseInfoTable(self: *Zld) !void { |
| 2290 | 2290 | try pointers.ensureCapacity(pointers.items.len + self.local_rebases.items.len); |
| 2291 | 2291 | pointers.appendSliceAssumeCapacity(self.local_rebases.items); |
| 2292 | 2292 | |
| 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 | | |
| 2320 | 2293 | std.sort.sort(Pointer, pointers.items, {}, pointerCmp); |
| 2321 | 2294 | |
| 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 | | |
| 2328 | 2295 | const size = try rebaseInfoSize(pointers.items); |
| 2329 | 2296 | var buffer = try self.allocator.alloc(u8, @intCast(usize, size)); |
| 2330 | 2297 | defer self.allocator.free(buffer); |
| ... | ... | @@ -2698,21 +2665,8 @@ fn writeSymbolTable(self: *Zld) !void { |
| 2698 | 2665 | log.debug(" | {}", .{entry.inner}); |
| 2699 | 2666 | log.debug(" | {}", .{entry.tt}); |
| 2700 | 2667 | 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 | | // } |
| 2711 | 2668 | try locals.append(entry.inner); |
| 2712 | 2669 | } |
| 2713 | | // if (symbol) |s| { |
| 2714 | | // try locals.append(s); |
| 2715 | | // } |
| 2716 | 2670 | } |
| 2717 | 2671 | const nlocals = locals.items.len; |
| 2718 | 2672 | |