diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-30 00:52:10 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-09-30 00:52:10 +0200 |
| commit | e72fd185e01aac14d7962f2eeb718653dc0c8e68 (patch) | |
| tree | 667c21f3f9e23e797edee75456657ae5ed96c365 /src | |
| parent | 6c50ad6e9f0223059d2ef62159e184ac829fc864 (diff) | |
| download | zig-e72fd185e01aac14d7962f2eeb718653dc0c8e68.tar.gz zig-e72fd185e01aac14d7962f2eeb718653dc0c8e68.zip | |
elf: skip writing out zerofill atoms to file
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf.zig | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 6e1453e5ac..4e43a20433 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1319,9 +1319,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node for (zig_module.atoms.keys()) |atom_index| { const atom_ptr = self.atom(atom_index).?; if (!atom_ptr.flags.alive) continue; + const shdr = &self.shdrs.items[atom_ptr.outputShndx().?]; + if (shdr.sh_type == elf.SHT_NOBITS) continue; const code = try zig_module.codeAlloc(self, atom_index); defer gpa.free(code); - const shdr = &self.shdrs.items[atom_ptr.outputShndx().?]; const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr; try atom_ptr.resolveRelocs(self, code); try self.base.file.?.pwriteAll(code, file_offset); @@ -2862,10 +2863,6 @@ fn updateDeclCode( try self.got.writeEntry(self, gop.index); } - const phdr_index = self.phdr_to_shdr_table.get(shdr_index).?; - const section_offset = sym.value - self.phdrs.items[phdr_index].p_vaddr; - const file_offset = self.shdrs.items[shdr_index].sh_offset + section_offset; - if (self.base.child_pid) |pid| { switch (builtin.os.tag) { .linux => { @@ -2887,7 +2884,13 @@ fn updateDeclCode( } } - try self.base.file.?.pwriteAll(code, file_offset); + const shdr = self.shdrs.items[shdr_index]; + if (shdr.sh_type != elf.SHT_NOBITS) { + const phdr_index = self.phdr_to_shdr_table.get(shdr_index).?; + const section_offset = sym.value - self.phdrs.items[phdr_index].p_vaddr; + const file_offset = shdr.sh_offset + section_offset; + try self.base.file.?.pwriteAll(code, file_offset); + } } pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void { |
