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