| ... | @@ -939,12 +939,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -939,12 +939,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 939 | } else null; | 939 | } else null; |
| 940 | const gc_sections = self.base.options.gc_sections orelse false; | 940 | const gc_sections = self.base.options.gc_sections orelse false; |
| 941 | | 941 | |
| 942 | if (self.isRelocatable() and self.zig_object_index == null) { | 942 | if (self.isObject() and self.zig_object_index == null) { |
| 943 | if (self.isStaticLib()) { | | |
| 944 | var err = try self.addErrorWithNotes(0); | | |
| 945 | try err.addMsg(self, "fatal linker error: emitting static libs unimplemented", .{}); | | |
| 946 | return; | | |
| 947 | } | | |
| 948 | // TODO this will become -r route I guess. For now, just copy the object file. | 943 | // TODO this will become -r route I guess. For now, just copy the object file. |
| 949 | assert(self.base.file == null); // TODO uncomment once we implement -r | 944 | assert(self.base.file == null); // TODO uncomment once we implement -r |
| 950 | const the_object_path = blk: { | 945 | const the_object_path = blk: { |
| ... | @@ -1555,15 +1550,18 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1555,15 +1550,18 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1555 | try self.writeElfHeader(); | 1550 | try self.writeElfHeader(); |
| 1556 | } | 1551 | } |
| 1557 | | 1552 | |
| 1558 | // TODO parse positionals that we want to make part of the archive | 1553 | var files = std.ArrayList(File.Index).init(gpa); |
| 1559 | | 1554 | defer files.deinit(); |
| 1560 | // TODO update ar symtab from parsed positionals | 1555 | try files.ensureTotalCapacityPrecise(self.objects.items.len + 1); |
| | 1556 | if (self.zigObjectPtr()) |zig_object| files.appendAssumeCapacity(zig_object.index); |
| | 1557 | for (self.objects.items) |index| files.appendAssumeCapacity(index); |
| 1561 | | 1558 | |
| | 1559 | // Update ar symtab from parsed objects |
| 1562 | var ar_symtab: Archive.ArSymtab = .{}; | 1560 | var ar_symtab: Archive.ArSymtab = .{}; |
| 1563 | defer ar_symtab.deinit(gpa); | 1561 | defer ar_symtab.deinit(gpa); |
| 1564 | | 1562 | |
| 1565 | if (self.zigObjectPtr()) |zig_object| { | 1563 | for (files.items) |index| { |
| 1566 | try zig_object.updateArSymtab(&ar_symtab, self); | 1564 | try self.file(index).?.updateArSymtab(&ar_symtab, self); |
| 1567 | } | 1565 | } |
| 1568 | | 1566 | |
| 1569 | ar_symtab.sort(); | 1567 | ar_symtab.sort(); |
| ... | @@ -1572,9 +1570,10 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1572,9 +1570,10 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1572 | var ar_strtab: Archive.ArStrtab = .{}; | 1570 | var ar_strtab: Archive.ArStrtab = .{}; |
| 1573 | defer ar_strtab.deinit(gpa); | 1571 | defer ar_strtab.deinit(gpa); |
| 1574 | | 1572 | |
| 1575 | if (self.zigObjectPtr()) |zig_object| { | 1573 | for (files.items) |index| { |
| 1576 | try zig_object.updateArStrtab(gpa, &ar_strtab); | 1574 | const file_ptr = self.file(index).?; |
| 1577 | zig_object.updateArSize(self); | 1575 | try file_ptr.updateArStrtab(gpa, &ar_strtab); |
| | 1576 | file_ptr.updateArSize(self); |
| 1578 | } | 1577 | } |
| 1579 | | 1578 | |
| 1580 | // Update file offsets of contributing objects. | 1579 | // Update file offsets of contributing objects. |
| ... | @@ -1587,10 +1586,16 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1587,10 +1586,16 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1587 | pos += @sizeOf(Archive.ar_hdr) + ar_strtab.size(); | 1586 | pos += @sizeOf(Archive.ar_hdr) + ar_strtab.size(); |
| 1588 | } | 1587 | } |
| 1589 | | 1588 | |
| 1590 | if (self.zigObjectPtr()) |zig_object| { | 1589 | for (files.items) |index| { |
| | 1590 | const file_ptr = self.file(index).?; |
| | 1591 | const state = switch (file_ptr) { |
| | 1592 | .zig_object => |x| &x.output_ar_state, |
| | 1593 | .object => |x| &x.output_ar_state, |
| | 1594 | else => unreachable, |
| | 1595 | }; |
| 1591 | pos = mem.alignForward(usize, pos, 2); | 1596 | pos = mem.alignForward(usize, pos, 2); |
| 1592 | zig_object.output_ar_state.file_off = pos; | 1597 | state.file_off = pos; |
| 1593 | pos += @sizeOf(Archive.ar_hdr) + (math.cast(usize, zig_object.output_ar_state.size) orelse return error.Overflow); | 1598 | pos += @sizeOf(Archive.ar_hdr) + (math.cast(usize, state.size) orelse return error.Overflow); |
| 1594 | } | 1599 | } |
| 1595 | | 1600 | |
| 1596 | break :blk pos; | 1601 | break :blk pos; |
| ... | @@ -1618,9 +1623,9 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void | ... | @@ -1618,9 +1623,9 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void |
| 1618 | } | 1623 | } |
| 1619 | | 1624 | |
| 1620 | // Write object files | 1625 | // Write object files |
| 1621 | if (self.zigObjectPtr()) |zig_object| { | 1626 | for (files.items) |index| { |
| 1622 | if (!mem.isAligned(buffer.items.len, 2)) try buffer.writer().writeByte(0); | 1627 | if (!mem.isAligned(buffer.items.len, 2)) try buffer.writer().writeByte(0); |
| 1623 | try zig_object.writeAr(self, buffer.writer()); | 1628 | try self.file(index).?.writeAr(self, buffer.writer()); |
| 1624 | } | 1629 | } |
| 1625 | | 1630 | |
| 1626 | assert(buffer.items.len == total_size); | 1631 | assert(buffer.items.len == total_size); |