| ... | @@ -1580,6 +1580,13 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1580,6 +1580,13 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1580 | files.putAssumeCapacityNoClobber(zig_object.index, .{ off, 0, 0 }); | 1580 | files.putAssumeCapacityNoClobber(zig_object.index, .{ off, 0, 0 }); |
| 1581 | } | 1581 | } |
| 1582 | | 1582 | |
| | 1583 | // Align to even byte boundary |
| | 1584 | { |
| | 1585 | const end = ar_strtab.items.len; |
| | 1586 | const aligned = mem.alignForward(usize, end, 2); |
| | 1587 | try ar_strtab.writer().writeByteNTimes(0, aligned - end); |
| | 1588 | } |
| | 1589 | |
| 1583 | // Encode ar symtab in 64bit format. | 1590 | // Encode ar symtab in 64bit format. |
| 1584 | var ar_symtab = std.ArrayList(u8).init(gpa); | 1591 | var ar_symtab = std.ArrayList(u8).init(gpa); |
| 1585 | defer ar_symtab.deinit(); | 1592 | defer ar_symtab.deinit(); |
| ... | @@ -1599,7 +1606,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1599,7 +1606,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1599 | try ar_symtab.writer().print("{s}\x00", .{name}); | 1606 | try ar_symtab.writer().print("{s}\x00", .{name}); |
| 1600 | } | 1607 | } |
| 1601 | | 1608 | |
| 1602 | // Align to 8bytes if required | 1609 | // Align to 8 bytes if required |
| 1603 | { | 1610 | { |
| 1604 | const end = ar_symtab.items.len; | 1611 | const end = ar_symtab.items.len; |
| 1605 | const aligned = mem.alignForward(usize, end, 8); | 1612 | const aligned = mem.alignForward(usize, end, 8); |
| ... | @@ -1617,8 +1624,6 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1617,8 +1624,6 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1617 | file_off += @sizeOf(Archive.ar_hdr) + @as(u64, @intCast(ar_symtab.items.len)); | 1624 | file_off += @sizeOf(Archive.ar_hdr) + @as(u64, @intCast(ar_symtab.items.len)); |
| 1618 | // Strtab | 1625 | // Strtab |
| 1619 | file_off += @sizeOf(Archive.ar_hdr) + @as(u64, @intCast(ar_strtab.items.len)); | 1626 | file_off += @sizeOf(Archive.ar_hdr) + @as(u64, @intCast(ar_strtab.items.len)); |
| 1620 | // And because we are nice, we will align to 8 bytes. | | |
| 1621 | file_off = mem.alignForward(u64, file_off, 8); | | |
| 1622 | | 1627 | |
| 1623 | const files_ptr = files.getPtr(zig_object.index).?; | 1628 | const files_ptr = files.getPtr(zig_object.index).?; |
| 1624 | files_ptr[1] = file_off; | 1629 | files_ptr[1] = file_off; |
| ... | @@ -1661,7 +1666,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1661,7 +1666,7 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1661 | const hdr = setArHdr(.{ | 1666 | const hdr = setArHdr(.{ |
| 1662 | .kind = .strtab, | 1667 | .kind = .strtab, |
| 1663 | .name_off = 0, | 1668 | .name_off = 0, |
| 1664 | .size = @intCast(mem.alignForward(usize, ar_strtab.items.len, 8)), | 1669 | .size = @intCast(ar_strtab.items.len), |
| 1665 | }); | 1670 | }); |
| 1666 | try self.base.file.?.pwriteAll(mem.asBytes(&hdr), pos); | 1671 | try self.base.file.?.pwriteAll(mem.asBytes(&hdr), pos); |
| 1667 | pos += @sizeOf(Archive.ar_hdr); | 1672 | pos += @sizeOf(Archive.ar_hdr); |
| ... | @@ -1674,8 +1679,16 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1674,8 +1679,16 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1674 | const entry = files.get(zig_object.index).?; | 1679 | const entry = files.get(zig_object.index).?; |
| 1675 | const hdr = setArHdr(.{ .kind = .object, .name_off = entry[0], .size = @intCast(entry[2]) }); | 1680 | const hdr = setArHdr(.{ .kind = .object, .name_off = entry[0], .size = @intCast(entry[2]) }); |
| 1676 | try self.base.file.?.pwriteAll(mem.asBytes(&hdr), entry[1]); | 1681 | try self.base.file.?.pwriteAll(mem.asBytes(&hdr), entry[1]); |
| | 1682 | pos += @sizeOf(Archive.ar_hdr) + entry[2]; |
| 1677 | } | 1683 | } |
| 1678 | | 1684 | |
| | 1685 | if (pos % 2 != 0) { |
| | 1686 | pos += 1; |
| | 1687 | try self.base.file.?.pwriteAll(&[1]u8{0}, pos); |
| | 1688 | } |
| | 1689 | |
| | 1690 | assert(mem.isAligned(pos, 2)); |
| | 1691 | |
| 1679 | // TODO parsed positionals | 1692 | // TODO parsed positionals |
| 1680 | | 1693 | |
| 1681 | // Magic bytes. | 1694 | // Magic bytes. |