| ... | @@ -18,9 +18,6 @@ objects: std.ArrayListUnmanaged(File.Index) = .{}, | ... | @@ -18,9 +18,6 @@ objects: std.ArrayListUnmanaged(File.Index) = .{}, |
| 18 | /// Stored in native-endian format, depending on target endianness needs to be bswapped on read/write. | 18 | /// Stored in native-endian format, depending on target endianness needs to be bswapped on read/write. |
| 19 | /// Same order as in the file. | 19 | /// Same order as in the file. |
| 20 | shdrs: std.ArrayListUnmanaged(elf.Elf64_Shdr) = .{}, | 20 | shdrs: std.ArrayListUnmanaged(elf.Elf64_Shdr) = .{}, |
| 21 | /// Given index to a section, returns a list of atoms allocated within it. | | |
| 22 | /// Excludes incrementally allocated atoms - for those, use linked-list approach. | | |
| 23 | atoms_by_shdr_table: std.AutoArrayHashMapUnmanaged(u16, AtomList) = .{}, | | |
| 24 | /// Given index to a section, pulls index of containing phdr if any. | 21 | /// Given index to a section, pulls index of containing phdr if any. |
| 25 | phdr_to_shdr_table: std.AutoHashMapUnmanaged(u16, u16) = .{}, | 22 | phdr_to_shdr_table: std.AutoHashMapUnmanaged(u16, u16) = .{}, |
| 26 | /// File offset into the shdr table. | 23 | /// File offset into the shdr table. |
| ... | @@ -319,12 +316,6 @@ pub fn deinit(self: *Elf) void { | ... | @@ -319,12 +316,6 @@ pub fn deinit(self: *Elf) void { |
| 319 | self.objects.deinit(gpa); | 316 | self.objects.deinit(gpa); |
| 320 | | 317 | |
| 321 | self.shdrs.deinit(gpa); | 318 | self.shdrs.deinit(gpa); |
| 322 | | | |
| 323 | for (self.atoms_by_shdr_table.values()) |*list| { | | |
| 324 | list.deinit(gpa); | | |
| 325 | } | | |
| 326 | self.atoms_by_shdr_table.deinit(gpa); | | |
| 327 | | | |
| 328 | self.phdr_to_shdr_table.deinit(gpa); | 319 | self.phdr_to_shdr_table.deinit(gpa); |
| 329 | self.phdrs.deinit(gpa); | 320 | self.phdrs.deinit(gpa); |
| 330 | self.shstrtab.deinit(gpa); | 321 | self.shstrtab.deinit(gpa); |
| ... | @@ -1254,7 +1245,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1254,7 +1245,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1254 | // Generate and emit non-incremental sections. | 1245 | // Generate and emit non-incremental sections. |
| 1255 | try self.initSections(); | 1246 | try self.initSections(); |
| 1256 | try self.sortSections(); | 1247 | try self.sortSections(); |
| 1257 | try self.addAtomsToSections(); | 1248 | try self.updateSectionSizes(); |
| 1258 | | 1249 | |
| 1259 | // Dump the state for easy debugging. | 1250 | // Dump the state for easy debugging. |
| 1260 | // State can be dumped via `--debug-log link_state`. | 1251 | // State can be dumped via `--debug-log link_state`. |
| ... | @@ -1266,7 +1257,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node | ... | @@ -1266,7 +1257,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1266 | // linker-defined synthetic symbols. | 1257 | // linker-defined synthetic symbols. |
| 1267 | try self.allocateObjects(); | 1258 | try self.allocateObjects(); |
| 1268 | self.allocateLinkerDefinedSymbols(); | 1259 | self.allocateLinkerDefinedSymbols(); |
| 1269 | try self.updateSyntheticSectionSizes(); | | |
| 1270 | | 1260 | |
| 1271 | // Look for entry address in objects if not set by the incremental compiler. | 1261 | // Look for entry address in objects if not set by the incremental compiler. |
| 1272 | if (self.entry_addr == null) { | 1262 | if (self.entry_addr == null) { |
| ... | @@ -3598,26 +3588,13 @@ fn sortSections(self: *Elf) !void { | ... | @@ -3598,26 +3588,13 @@ fn sortSections(self: *Elf) !void { |
| 3598 | } | 3588 | } |
| 3599 | } | 3589 | } |
| 3600 | | 3590 | |
| 3601 | fn addAtomsToSections(self: *Elf) !void { | 3591 | fn updateSectionSizes(self: *Elf) !void { |
| 3602 | const gpa = self.base.allocator; | | |
| 3603 | for (self.objects.items) |index| { | 3592 | for (self.objects.items) |index| { |
| 3604 | for (self.file(index).?.atoms()) |atom_index| { | 3593 | self.file(index).?.object.updateSectionSizes(self); |
| 3605 | const atom_ptr = self.atom(atom_index) orelse continue; | | |
| 3606 | if (!atom_ptr.flags.alive) continue; | | |
| 3607 | const gop = try self.atoms_by_shdr_table.getOrPut(gpa, atom_ptr.output_section_index); | | |
| 3608 | if (!gop.found_existing) gop.value_ptr.* = .{}; | | |
| 3609 | try gop.value_ptr.append(gpa, atom_index); | | |
| 3610 | } | | |
| 3611 | } | 3594 | } |
| 3612 | } | | |
| 3613 | | 3595 | |
| 3614 | fn updateSyntheticSectionSizes(self: *Elf) !void { | | |
| 3615 | if (self.got_section_index) |index| { | 3596 | if (self.got_section_index) |index| { |
| 3616 | if (self.got.dirty) { | 3597 | self.shdrs.items[index].sh_size = self.got.size(self); |
| 3617 | try self.growAllocSection(index, self.got.size(self)); | | |
| 3618 | self.got.dirty = false; | | |
| 3619 | self.got_addresses_dirty = true; | | |
| 3620 | } | | |
| 3621 | } | 3598 | } |
| 3622 | | 3599 | |
| 3623 | if (self.symtab_section_index != null) { | 3600 | if (self.symtab_section_index != null) { |