authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-30 00:52:10+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-30 00:52:10+02:00
loge72fd185e01aac14d7962f2eeb718653dc0c8e68
tree667c21f3f9e23e797edee75456657ae5ed96c365
parent6c50ad6e9f0223059d2ef62159e184ac829fc864

elf: skip writing out zerofill atoms to file


1 files changed, 9 insertions(+), 6 deletions(-)

src/link/Elf.zig+9-6
......@@ -1319,9 +1319,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
13191319 for (zig_module.atoms.keys()) |atom_index| {
13201320 const atom_ptr = self.atom(atom_index).?;
13211321 if (!atom_ptr.flags.alive) continue;
1322 const shdr = &self.shdrs.items[atom_ptr.outputShndx().?];
1323 if (shdr.sh_type == elf.SHT_NOBITS) continue;
13221324 const code = try zig_module.codeAlloc(self, atom_index);
13231325 defer gpa.free(code);
1324 const shdr = &self.shdrs.items[atom_ptr.outputShndx().?];
13251326 const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr;
13261327 try atom_ptr.resolveRelocs(self, code);
13271328 try self.base.file.?.pwriteAll(code, file_offset);
......@@ -2862,10 +2863,6 @@ fn updateDeclCode(
28622863 try self.got.writeEntry(self, gop.index);
28632864 }
28642865
2865 const phdr_index = self.phdr_to_shdr_table.get(shdr_index).?;
2866 const section_offset = sym.value - self.phdrs.items[phdr_index].p_vaddr;
2867 const file_offset = self.shdrs.items[shdr_index].sh_offset + section_offset;
2868
28692866 if (self.base.child_pid) |pid| {
28702867 switch (builtin.os.tag) {
28712868 .linux => {
......@@ -2887,7 +2884,13 @@ fn updateDeclCode(
28872884 }
28882885 }
28892886
2890 try self.base.file.?.pwriteAll(code, file_offset);
2887 const shdr = self.shdrs.items[shdr_index];
2888 if (shdr.sh_type != elf.SHT_NOBITS) {
2889 const phdr_index = self.phdr_to_shdr_table.get(shdr_index).?;
2890 const section_offset = sym.value - self.phdrs.items[phdr_index].p_vaddr;
2891 const file_offset = shdr.sh_offset + section_offset;
2892 try self.base.file.?.pwriteAll(code, file_offset);
2893 }
28912894}
28922895
28932896pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {