Skip to content

Commit e72fd18

Browse files
committed
elf: skip writing out zerofill atoms to file
1 parent 6c50ad6 commit e72fd18

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/link/Elf.zig

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

28932896
pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void {

0 commit comments

Comments
 (0)