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...@@ -1319,9 +1319,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1319 for (zig_module.atoms.keys()) |atom_index| {1319 for (zig_module.atoms.keys()) |atom_index| {
1320 const atom_ptr = self.atom(atom_index).?;1320 const atom_ptr = self.atom(atom_index).?;
1321 if (!atom_ptr.flags.alive) continue;1321 if (!atom_ptr.flags.alive) continue;
1322 const shdr = &self.shdrs.items[atom_ptr.outputShndx().?];
1323 if (shdr.sh_type == elf.SHT_NOBITS) continue;
1322 const code = try zig_module.codeAlloc(self, atom_index);1324 const code = try zig_module.codeAlloc(self, atom_index);
1323 defer gpa.free(code);1325 defer gpa.free(code);
1324 const shdr = &self.shdrs.items[atom_ptr.outputShndx().?];
1325 const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr;1326 const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr;
1326 try atom_ptr.resolveRelocs(self, code);1327 try atom_ptr.resolveRelocs(self, code);
1327 try self.base.file.?.pwriteAll(code, file_offset);1328 try self.base.file.?.pwriteAll(code, file_offset);
...@@ -2862,10 +2863,6 @@ fn updateDeclCode(...@@ -2862,10 +2863,6 @@ fn updateDeclCode(
2862 try self.got.writeEntry(self, gop.index);2863 try self.got.writeEntry(self, gop.index);
2863 }2864 }
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
2869 if (self.base.child_pid) |pid| {2866 if (self.base.child_pid) |pid| {
2870 switch (builtin.os.tag) {2867 switch (builtin.os.tag) {
2871 .linux => {2868 .linux => {
...@@ -2887,7 +2884,13 @@ fn updateDeclCode(...@@ -2887,7 +2884,13 @@ fn updateDeclCode(
2887 }2884 }
2888 }2885 }
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 }
2891}2894}
28922895
2893pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {2896pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {