| author | |
| committer | |
| log | 801c37209889883ad2d7b9cfb232fd8d9e0ed66c |
| tree | d64ffbd0691769032edd96392153039951394caf |
| parent | 0701646beb8421464346ce6e8993394d8d2c7d5c |
3 files changed, 25 insertions(+), 9 deletions(-)
src/link/Elf.zig+8-2| ... | ... | @@ -3308,7 +3308,7 @@ pub fn resolveMergeSections(self: *Elf) !void { |
| 3308 | 3308 | for (self.objects.items) |index| { |
| 3309 | 3309 | const file_ptr = self.file(index).?; |
| 3310 | 3310 | if (!file_ptr.isAlive()) continue; |
| 3311 | file_ptr.object.initMergeSections(self) catch |err| switch (err) { | |
| 3311 | file_ptr.object.initInputMergeSections(self) catch |err| switch (err) { | |
| 3312 | 3312 | error.MalformedObject => has_errors = true, |
| 3313 | 3313 | else => |e| return e, |
| 3314 | 3314 | }; |
| ... | ... | @@ -3316,6 +3316,12 @@ pub fn resolveMergeSections(self: *Elf) !void { |
| 3316 | 3316 | |
| 3317 | 3317 | if (has_errors) return error.FlushFailure; |
| 3318 | 3318 | |
| 3319 | for (self.objects.items) |index| { | |
| 3320 | const file_ptr = self.file(index).?; | |
| 3321 | if (!file_ptr.isAlive()) continue; | |
| 3322 | try file_ptr.object.initOutputMergeSections(self); | |
| 3323 | } | |
| 3324 | ||
| 3319 | 3325 | for (self.objects.items) |index| { |
| 3320 | 3326 | const file_ptr = self.file(index).?; |
| 3321 | 3327 | if (!file_ptr.isAlive()) continue; |
| ... | ... | @@ -3330,7 +3336,7 @@ pub fn resolveMergeSections(self: *Elf) !void { |
| 3330 | 3336 | |
| 3331 | 3337 | pub fn finalizeMergeSections(self: *Elf) !void { |
| 3332 | 3338 | for (self.merge_sections.items) |*msec| { |
| 3333 | try msec.finalize(self); | |
| 3339 | try msec.finalize(self.base.comp.gpa); | |
| 3334 | 3340 | } |
| 3335 | 3341 | } |
| 3336 | 3342 |
src/link/Elf/Object.zig+14-3| ... | ... | @@ -691,7 +691,7 @@ pub fn checkDuplicates(self: *Object, dupes: anytype, elf_file: *Elf) error{OutO |
| 691 | 691 | } |
| 692 | 692 | } |
| 693 | 693 | |
| 694 | pub fn initMergeSections(self: *Object, elf_file: *Elf) !void { | |
| 694 | pub fn initInputMergeSections(self: *Object, elf_file: *Elf) !void { | |
| 695 | 695 | const gpa = elf_file.base.comp.gpa; |
| 696 | 696 | |
| 697 | 697 | try self.input_merge_sections.ensureUnusedCapacity(gpa, self.shdrs.items.len); |
| ... | ... | @@ -709,8 +709,6 @@ pub fn initMergeSections(self: *Object, elf_file: *Elf) !void { |
| 709 | 709 | const imsec_idx = try self.addInputMergeSection(gpa); |
| 710 | 710 | const imsec = self.inputMergeSection(imsec_idx).?; |
| 711 | 711 | self.input_merge_sections_indexes.items[shndx] = imsec_idx; |
| 712 | ||
| 713 | imsec.merge_section_index = try elf_file.getOrCreateMergeSection(atom_ptr.name(elf_file), shdr.sh_flags, shdr.sh_type); | |
| 714 | 712 | imsec.atom_index = atom_index; |
| 715 | 713 | |
| 716 | 714 | const data = try self.codeDecompressAlloc(elf_file, atom_index); |
| ... | ... | @@ -769,6 +767,19 @@ pub fn initMergeSections(self: *Object, elf_file: *Elf) !void { |
| 769 | 767 | } |
| 770 | 768 | } |
| 771 | 769 | |
| 770 | pub fn initOutputMergeSections(self: *Object, elf_file: *Elf) !void { | |
| 771 | for (self.input_merge_sections_indexes.items) |index| { | |
| 772 | const imsec = self.inputMergeSection(index) orelse continue; | |
| 773 | const atom_ptr = self.atom(imsec.atom_index).?; | |
| 774 | const shdr = atom_ptr.inputShdr(elf_file); | |
| 775 | imsec.merge_section_index = try elf_file.getOrCreateMergeSection( | |
| 776 | atom_ptr.name(elf_file), | |
| 777 | shdr.sh_flags, | |
| 778 | shdr.sh_type, | |
| 779 | ); | |
| 780 | } | |
| 781 | } | |
| 782 | ||
| 772 | 783 | pub fn resolveMergeSubsections(self: *Object, elf_file: *Elf) !void { |
| 773 | 784 | const gpa = elf_file.base.comp.gpa; |
| 774 | 785 |
src/link/Elf/merge_section.zig+3-4| ... | ... | @@ -60,9 +60,8 @@ pub const MergeSection = struct { |
| 60 | 60 | |
| 61 | 61 | /// Finalizes the merge section and clears hash table. |
| 62 | 62 | /// Sorts all owned subsections. |
| 63 | pub fn finalize(msec: *MergeSection, elf_file: *Elf) !void { | |
| 64 | const gpa = elf_file.base.comp.gpa; | |
| 65 | try msec.finalized_subsections.ensureTotalCapacityPrecise(gpa, msec.subsections.items.len); | |
| 63 | pub fn finalize(msec: *MergeSection, allocator: Allocator) !void { | |
| 64 | try msec.finalized_subsections.ensureTotalCapacityPrecise(allocator, msec.subsections.items.len); | |
| 66 | 65 | |
| 67 | 66 | var it = msec.table.iterator(); |
| 68 | 67 | while (it.next()) |entry| { |
| ... | ... | @@ -70,7 +69,7 @@ pub const MergeSection = struct { |
| 70 | 69 | if (!msub.alive) continue; |
| 71 | 70 | msec.finalized_subsections.appendAssumeCapacity(entry.value_ptr.*); |
| 72 | 71 | } |
| 73 | msec.table.clearAndFree(gpa); | |
| 72 | msec.table.clearAndFree(allocator); | |
| 74 | 73 | |
| 75 | 74 | const sortFn = struct { |
| 76 | 75 | pub fn sortFn(ctx: *MergeSection, lhs: MergeSubsection.Index, rhs: MergeSubsection.Index) bool { |