From 6c50ad6e9f0223059d2ef62159e184ac829fc864 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 29 Sep 2023 22:36:58 +0200 Subject: [PATCH] elf: set sh_size to 0 for nobit sections in collision detection `SHT_NOBITS` sections take no file space after all. --- src/link/Elf.zig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/link/Elf.zig b/src/link/Elf.zig index ca869f550a..6e1453e5ac 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -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; } }