| author | |
| committer | |
| log | 03c3a85ea36d8d6a18437b8d9c8a5fc714e4a81e |
| tree | a6714287704e5905243cad2483a3f21dfa0d3052 |
| parent | acd7cbf0b51dbc8039387de285e2b391a78f59ae |
2 files changed, 68 insertions(+), 20 deletions(-)
src/link/Elf.zig+26-2| ... | ... | @@ -3611,6 +3611,8 @@ fn initComdatGroups(self: *Elf) !void { |
| 3611 | 3611 | .name = ".group", |
| 3612 | 3612 | .type = elf.SHT_GROUP, |
| 3613 | 3613 | .entsize = @sizeOf(u32), |
| 3614 | .addralign = @alignOf(u32), | |
| 3615 | .offset = std.math.maxInt(u64), | |
| 3614 | 3616 | }), |
| 3615 | 3617 | .cg_index = cg_index, |
| 3616 | 3618 | }; |
| ... | ... | @@ -4293,13 +4295,22 @@ fn updateSectionSizesObject(self: *Elf) !void { |
| 4293 | 4295 | shdr.sh_size = eh_frame.calcEhFrameRelocs(self) * shdr.sh_entsize; |
| 4294 | 4296 | } |
| 4295 | 4297 | |
| 4296 | self.updateComdatGroupsSizes(); | |
| 4297 | 4298 | try self.updateSymtabSize(); |
| 4299 | self.updateComdatGroupsSizes(); | |
| 4298 | 4300 | self.updateShStrtabSize(); |
| 4299 | 4301 | } |
| 4300 | 4302 | |
| 4301 | 4303 | fn updateComdatGroupsSizes(self: *Elf) void { |
| 4302 | _ = self; | |
| 4304 | for (self.comdat_group_sections.items) |cg| { | |
| 4305 | const shdr = &self.shdrs.items[cg.shndx]; | |
| 4306 | shdr.sh_size = cg.size(self); | |
| 4307 | shdr.sh_link = self.symtab_section_index.?; | |
| 4308 | ||
| 4309 | const sym = self.symbol(cg.symbol(self)); | |
| 4310 | std.debug.print("{s}\n", .{sym.name(self)}); | |
| 4311 | shdr.sh_info = sym.outputSymtabIndex(self) orelse | |
| 4312 | self.sectionSymbolOutputSymtabIndex(sym.outputShndx().?); | |
| 4313 | } | |
| 4303 | 4314 | } |
| 4304 | 4315 | |
| 4305 | 4316 | fn updateShStrtabSize(self: *Elf) void { |
| ... | ... | @@ -5068,10 +5079,23 @@ fn writeSyntheticSectionsObject(self: *Elf) !void { |
| 5068 | 5079 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 5069 | 5080 | } |
| 5070 | 5081 | |
| 5082 | try self.writeComdatGroups(); | |
| 5071 | 5083 | try self.writeSymtab(); |
| 5072 | 5084 | try self.writeShStrtab(); |
| 5073 | 5085 | } |
| 5074 | 5086 | |
| 5087 | fn writeComdatGroups(self: *Elf) !void { | |
| 5088 | const gpa = self.base.allocator; | |
| 5089 | for (self.comdat_group_sections.items) |cgs| { | |
| 5090 | const shdr = self.shdrs.items[cgs.shndx]; | |
| 5091 | const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow; | |
| 5092 | var buffer = try std.ArrayList(u8).initCapacity(gpa, sh_size); | |
| 5093 | defer buffer.deinit(); | |
| 5094 | try cgs.write(self, buffer.writer()); | |
| 5095 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | |
| 5096 | } | |
| 5097 | } | |
| 5098 | ||
| 5075 | 5099 | fn writeShStrtab(self: *Elf) !void { |
| 5076 | 5100 | if (self.shstrtab_section_index) |index| { |
| 5077 | 5101 | const shdr = self.shdrs.items[index]; |
src/link/Elf/synthetic_sections.zig+42-18| ... | ... | @@ -1503,24 +1503,48 @@ pub const ComdatGroupSection = struct { |
| 1503 | 1503 | shndx: u32, |
| 1504 | 1504 | cg_index: u32, |
| 1505 | 1505 | |
| 1506 | // pub fn size(cg: ComdatGroupSection) usize { | |
| 1507 | // return cg.members.items.len + 1; | |
| 1508 | // } | |
| 1509 | ||
| 1510 | // pub fn write(cg: ComdatGroupSection, elf_file: *Elf, writer: anytype) !void { | |
| 1511 | // try writeInt(@as(u32, elf.GRP_COMDAT), elf_file, writer); | |
| 1512 | // for (cg.members.items) |atom_index| { | |
| 1513 | // const atom = elf_file.atom(atom_index); | |
| 1514 | // const input_shdr = atom.inputShdr(elf_file); | |
| 1515 | // switch (input_shdr.sh_type) { | |
| 1516 | // elf.SHT_RELA => { | |
| 1517 | ||
| 1518 | // }, | |
| 1519 | // else => {}, | |
| 1520 | // } | |
| 1521 | // } | |
| 1522 | // try writer.writeAll(mem.sliceAsBytes(cg.members.items)); | |
| 1523 | // } | |
| 1506 | fn file(cgs: ComdatGroupSection, elf_file: *Elf) ?File { | |
| 1507 | const cg = elf_file.comdatGroup(cgs.cg_index); | |
| 1508 | const cg_owner = elf_file.comdatGroupOwner(cg.owner); | |
| 1509 | return elf_file.file(cg_owner.file); | |
| 1510 | } | |
| 1511 | ||
| 1512 | pub fn symbol(cgs: ComdatGroupSection, elf_file: *Elf) Symbol.Index { | |
| 1513 | const cg = elf_file.comdatGroup(cgs.cg_index); | |
| 1514 | const object = cgs.file(elf_file).?.object; | |
| 1515 | const shdr = object.shdrs.items[cg.shndx]; | |
| 1516 | return object.symbols.items[shdr.sh_info]; | |
| 1517 | } | |
| 1518 | ||
| 1519 | pub fn size(cgs: ComdatGroupSection, elf_file: *Elf) usize { | |
| 1520 | const cg = elf_file.comdatGroup(cgs.cg_index); | |
| 1521 | const object = cgs.file(elf_file).?.object; | |
| 1522 | const members = object.comdatGroupMembers(cg.shndx); | |
| 1523 | return (members.len + 1) * @sizeOf(u32); | |
| 1524 | } | |
| 1525 | ||
| 1526 | pub fn write(cgs: ComdatGroupSection, elf_file: *Elf, writer: anytype) !void { | |
| 1527 | const cg = elf_file.comdatGroup(cgs.cg_index); | |
| 1528 | const object = cgs.file(elf_file).?.object; | |
| 1529 | const members = object.comdatGroupMembers(cg.shndx); | |
| 1530 | try writeInt(@as(u32, elf.GRP_COMDAT), elf_file, writer); | |
| 1531 | for (members) |shndx| { | |
| 1532 | const shdr = object.shdrs.items[shndx]; | |
| 1533 | switch (shdr.sh_type) { | |
| 1534 | elf.SHT_RELA => { | |
| 1535 | const atom_index = object.atoms.items[shdr.sh_info]; | |
| 1536 | const atom = elf_file.atom(atom_index).?; | |
| 1537 | const rela = elf_file.output_rela_sections.get(atom.outputShndx().?).?; | |
| 1538 | try writeInt(rela.shndx, elf_file, writer); | |
| 1539 | }, | |
| 1540 | else => { | |
| 1541 | const atom_index = object.atoms.items[shndx]; | |
| 1542 | const atom = elf_file.atom(atom_index).?; | |
| 1543 | try writeInt(atom.outputShndx().?, elf_file, writer); | |
| 1544 | }, | |
| 1545 | } | |
| 1546 | } | |
| 1547 | } | |
| 1524 | 1548 | }; |
| 1525 | 1549 | |
| 1526 | 1550 | fn writeInt(value: anytype, elf_file: *Elf, writer: anytype) !void { |