elf: do not align end of archive to 2bytes; fix archive parser

This commit is contained in:
Jakub Konka 2023-11-03 19:30:51 +01:00
parent a333ac846d
commit ed2984f335
2 changed files with 3 additions and 9 deletions

View File

@ -1682,13 +1682,6 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void
pos += @sizeOf(Archive.ar_hdr) + entry[2];
}
if (pos % 2 != 0) {
pos += 1;
try self.base.file.?.pwriteAll(&[1]u8{0}, pos);
}
assert(mem.isAligned(pos, 2));
// TODO parsed positionals
// Magic bytes.

View File

@ -85,11 +85,12 @@ pub fn parse(self: *Archive, elf_file: *Elf) !void {
_ = try reader.readBytesNoEof(SARMAG);
while (true) {
if (stream.pos >= self.data.len) break;
if (stream.pos % 2 != 0) {
stream.pos += 1;
}
// TODO flag an error if stream.pos > self.data.len after alignment
const hdr = reader.readStruct(ar_hdr) catch break;
const hdr = try reader.readStruct(ar_hdr);
if (!mem.eql(u8, &hdr.ar_fmag, ARFMAG)) {
// TODO convert into an error