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

`SHT_NOBITS` sections take no file space after all.
This commit is contained in:
Jakub Konka 2023-09-29 22:36:58 +02:00
parent e5e6984652
commit 6c50ad6e9f

View File

@ -367,10 +367,12 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) ?u64 {
}
}
for (self.shdrs.items) |section| {
const increased_size = padToIdeal(section.sh_size);
const test_end = section.sh_offset + increased_size;
if (end > section.sh_offset and start < test_end) {
for (self.shdrs.items) |shdr| {
// SHT_NOBITS takes no physical space in the output file so set its size to 0.
const sh_size = if (shdr.sh_type == elf.SHT_NOBITS) 0 else shdr.sh_size;
const increased_size = padToIdeal(sh_size);
const test_end = shdr.sh_offset + increased_size;
if (end > shdr.sh_offset and start < test_end) {
return test_end;
}
}