| ... | @@ -460,8 +460,7 @@ fn allocateTextSegment(self: *Zld) !void { | ... | @@ -460,8 +460,7 @@ fn allocateTextSegment(self: *Zld) !void { |
| 460 | try self.allocateSegment( | 460 | try self.allocateSegment( |
| 461 | self.text_segment_cmd_index.?, | 461 | self.text_segment_cmd_index.?, |
| 462 | 0, | 462 | 0, |
| 463 | // sizeofcmds + 10 * 4 * @sizeOf(u32), | 463 | sizeofcmds, |
| 464 | 3140, | | |
| 465 | true, | 464 | true, |
| 466 | ); | 465 | ); |
| 467 | } | 466 | } |
| ... | @@ -508,27 +507,23 @@ fn allocateSegment(self: *Zld, index: u16, offset: u64, start: u64, reverse: boo | ... | @@ -508,27 +507,23 @@ fn allocateSegment(self: *Zld, index: u16, offset: u64, start: u64, reverse: boo |
| 508 | seg.inner.filesize = aligned_size; | 507 | seg.inner.filesize = aligned_size; |
| 509 | | 508 | |
| 510 | // Allocate section offsets | 509 | // Allocate section offsets |
| 511 | // if (reverse) { | 510 | if (reverse) { |
| 512 | // var end_off: u64 = seg.inner.fileoff + seg.inner.filesize; | 511 | var end_off: u64 = seg.inner.fileoff + seg.inner.filesize; |
| 513 | // var count: usize = seg.sections.items.len; | 512 | var count: usize = seg.sections.items.len; |
| 514 | // while (count > 0) : (count -= 1) { | 513 | while (count > 0) : (count -= 1) { |
| 515 | // const sec = &seg.sections.items[count - 1]; | 514 | const sec = &seg.sections.items[count - 1]; |
| 516 | // const alignment = math.max(@alignOf(u32), try std.math.powi(u32, 2, sec.@"align")); | 515 | end_off -= mem.alignForwardGeneric(u64, sec.size, @alignOf(u64)); // TODO is 8-byte aligned correct? |
| 517 | // log.warn("{s} 0x{x} alignment = 0x{x}", .{ parseName(&sec.sectname), sec.@"align", alignment }); | 516 | sec.offset = @intCast(u32, end_off); |
| 518 | // end_off -= mem.alignForwardGeneric(u64, sec.size, alignment); | 517 | sec.addr = base_vmaddr + end_off; |
| 519 | // sec.offset = @intCast(u32, end_off); | 518 | } |
| 520 | // sec.addr = base_vmaddr + end_off; | 519 | } else { |
| 521 | // } | 520 | var next_off: u64 = seg.inner.fileoff + start; |
| 522 | // } else { | 521 | for (seg.sections.items) |*sect| { |
| 523 | var next_off: u64 = seg.inner.fileoff + start; | 522 | sect.offset = @intCast(u32, next_off); |
| 524 | for (seg.sections.items) |*sect| { | 523 | sect.addr = base_vmaddr + next_off; |
| 525 | const alignment = math.max(@alignOf(u32), try std.math.powi(u32, 2, sect.@"align")); | 524 | next_off += mem.alignForwardGeneric(u64, sect.size, @alignOf(u64)); // TODO is 8-byte aligned correct? |
| 526 | log.warn("{s} 0x{x} alignment = 0x{x}", .{ parseName(&sect.sectname), sect.@"align", alignment }); | 525 | } |
| 527 | sect.offset = @intCast(u32, next_off); | 526 | } |
| 528 | sect.addr = base_vmaddr + next_off; | | |
| 529 | next_off += mem.alignForwardGeneric(u64, sect.size, alignment); | | |
| 530 | } | | |
| 531 | // } | | |
| 532 | } | 527 | } |
| 533 | | 528 | |
| 534 | fn writeStubHelperCommon(self: *Zld) !void { | 529 | fn writeStubHelperCommon(self: *Zld) !void { |
| ... | @@ -1041,12 +1036,7 @@ fn doRelocs(self: *Zld) !void { | ... | @@ -1041,12 +1036,7 @@ fn doRelocs(self: *Zld) !void { |
| 1041 | break :blk narrowed; | 1036 | break :blk narrowed; |
| 1042 | } else { | 1037 | } else { |
| 1043 | const denom: u4 = try math.powi(u4, 2, parsed.size); | 1038 | const denom: u4 = try math.powi(u4, 2, parsed.size); |
| 1044 | const offf = math.divExact(u12, narrowed, denom) catch |_| { | 1039 | break :blk try math.divExact(u12, narrowed, denom); |
| 1045 | log.warn(" | narrowed 0x{x}", .{narrowed}); | | |
| 1046 | log.warn(" | denom 0x{x}", .{denom}); | | |
| 1047 | continue; | | |
| 1048 | }; | | |
| 1049 | break :blk offf; | | |
| 1050 | } | 1040 | } |
| 1051 | }; | 1041 | }; |
| 1052 | parsed.offset = offset; | 1042 | parsed.offset = offset; |