| ... | @@ -4623,18 +4623,6 @@ fn allocateAllocSectionsInFile(self: *Elf, base_offset: u64) void { | ... | @@ -4623,18 +4623,6 @@ fn allocateAllocSectionsInFile(self: *Elf, base_offset: u64) void { |
| 4623 | } | 4623 | } |
| 4624 | } | 4624 | } |
| 4625 | | 4625 | |
| 4626 | fn allocateNonAllocSectionsInFile(self: *Elf, base_offset: u64) void { | | |
| 4627 | var offset = base_offset; | | |
| 4628 | var i: usize = 0; | | |
| 4629 | while (i < self.shdrs.items.len) : (i += 1) { | | |
| 4630 | const first = &self.shdrs.items[i]; | | |
| 4631 | if (shdrIsAlloc(first) or first.sh_type == elf.SHT_NULL) continue; | | |
| 4632 | // Non-alloc sections don't need congruency with their allocated virtual memory addresses | | |
| 4633 | first.sh_offset = mem.alignForward(u64, offset, first.sh_addralign); | | |
| 4634 | offset = first.sh_offset + first.sh_size; | | |
| 4635 | } | | |
| 4636 | } | | |
| 4637 | | | |
| 4638 | fn initAndAllocateSegments(self: *Elf) !void { | 4626 | fn initAndAllocateSegments(self: *Elf) !void { |
| 4639 | const ehsize: u64 = switch (self.ptr_width) { | 4627 | const ehsize: u64 = switch (self.ptr_width) { |
| 4640 | .p32 => @sizeOf(elf.Elf32_Ehdr), | 4628 | .p32 => @sizeOf(elf.Elf32_Ehdr), |
| ... | @@ -4658,13 +4646,16 @@ fn initAndAllocateSegments(self: *Elf) !void { | ... | @@ -4658,13 +4646,16 @@ fn initAndAllocateSegments(self: *Elf) !void { |
| 4658 | } | 4646 | } |
| 4659 | | 4647 | |
| 4660 | fn allocateNonAllocSections(self: *Elf) void { | 4648 | fn allocateNonAllocSections(self: *Elf) void { |
| 4661 | var off: u64 = 0; | 4649 | for (self.shdrs.items) |*shdr| { |
| 4662 | for (self.shdrs.items) |shdr| { | | |
| 4663 | if (shdr.sh_type == elf.SHT_NULL) continue; | 4650 | if (shdr.sh_type == elf.SHT_NULL) continue; |
| 4664 | if (shdr.sh_flags & elf.SHF_ALLOC == 0) break; | 4651 | if (shdr.sh_flags & elf.SHF_ALLOC != 0) continue; |
| 4665 | off = @max(off, shdr.sh_offset + shdr.sh_size); | 4652 | const needed_size = shdr.sh_size; |
| | 4653 | if (needed_size > self.allocatedSize(shdr.sh_offset)) { |
| | 4654 | shdr.sh_size = 0; |
| | 4655 | shdr.sh_offset = self.findFreeSpace(needed_size, shdr.sh_addralign); |
| | 4656 | shdr.sh_size = needed_size; |
| | 4657 | } |
| 4666 | } | 4658 | } |
| 4667 | self.allocateNonAllocSectionsInFile(off); | | |
| 4668 | } | 4659 | } |
| 4669 | | 4660 | |
| 4670 | fn allocateSpecialPhdrs(self: *Elf) void { | 4661 | fn allocateSpecialPhdrs(self: *Elf) void { |