commit ecf6ed7d9bc9bcd61d619fae985ce9ebdc4d5562 (tree) parent 31b280c78f41fd36caa2d1ba194b36dc9ec56a28 Author: Jakub Konka <kubkon@jakubkonka.com> Date: Tue, 7 Nov 2023 15:04:57 +0100 elf: allocate alloc sections when emitting relocatable Diffstat:
| M | src/link/Elf.zig | | | 12 | +++++++++++- |
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/link/Elf.zig b/src/link/Elf.zig @@ -4331,7 +4331,17 @@ fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void { /// Allocates alloc sections when merging relocatable objects files together. fn allocateAllocSectionsObject(self: *Elf) !void { - _ = self; + for (self.shdrs.items) |*shdr| { + if (shdr.sh_type == elf.SHT_NULL) continue; + if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue; + const needed_size = shdr.sh_size; + if (needed_size > self.allocatedSize(shdr.sh_offset)) { + shdr.sh_size = 0; + const new_offset = self.findFreeSpace(needed_size, shdr.sh_addralign); + shdr.sh_offset = new_offset; + shdr.sh_size = needed_size; + } + } } /// Allocates non-alloc sections (debug info, symtabs, etc.).