authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-07 15:04:57+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-07 15:04:57+01:00
logecf6ed7d9bc9bcd61d619fae985ce9ebdc4d5562
tree2a7585d2831fd2934ce91c5c0100fb41e1cee433
parent31b280c78f41fd36caa2d1ba194b36dc9ec56a28

elf: allocate alloc sections when emitting relocatable


1 files changed, 11 insertions(+), 1 deletions(-)

src/link/Elf.zig+11-1
...@@ -4331,7 +4331,17 @@ fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {...@@ -4331,7 +4331,17 @@ fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {
43314331
4332/// Allocates alloc sections when merging relocatable objects files together.4332/// Allocates alloc sections when merging relocatable objects files together.
4333fn allocateAllocSectionsObject(self: *Elf) !void {4333fn allocateAllocSectionsObject(self: *Elf) !void {
4334 _ = self;4334 for (self.shdrs.items) |*shdr| {
4335 if (shdr.sh_type == elf.SHT_NULL) continue;
4336 if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue;
4337 const needed_size = shdr.sh_size;
4338 if (needed_size > self.allocatedSize(shdr.sh_offset)) {
4339 shdr.sh_size = 0;
4340 const new_offset = self.findFreeSpace(needed_size, shdr.sh_addralign);
4341 shdr.sh_offset = new_offset;
4342 shdr.sh_size = needed_size;
4343 }
4344 }
4335}4345}
43364346
4337/// Allocates non-alloc sections (debug info, symtabs, etc.).4347/// Allocates non-alloc sections (debug info, symtabs, etc.).