authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-29 22:36:58+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-29 22:37:59+02:00
log6c50ad6e9f0223059d2ef62159e184ac829fc864
tree6eb9007a7dec81363dc509acb721a8eefc56bc58
parente5e69846527d429208462f4c1d278d9899899fd8

elf: set sh_size to 0 for nobit sections in collision detection

`SHT_NOBITS` sections take no file space after all.

1 files changed, 6 insertions(+), 4 deletions(-)

src/link/Elf.zig+6-4
......@@ -367,10 +367,12 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) ?u64 {
367367 }
368368 }
369369
370 for (self.shdrs.items) |section| {
371 const increased_size = padToIdeal(section.sh_size);
372 const test_end = section.sh_offset + increased_size;
373 if (end > section.sh_offset and start < test_end) {
370 for (self.shdrs.items) |shdr| {
371 // SHT_NOBITS takes no physical space in the output file so set its size to 0.
372 const sh_size = if (shdr.sh_type == elf.SHT_NOBITS) 0 else shdr.sh_size;
373 const increased_size = padToIdeal(sh_size);
374 const test_end = shdr.sh_offset + increased_size;
375 if (end > shdr.sh_offset and start < test_end) {
374376 return test_end;
375377 }
376378 }