| ... | @@ -1028,21 +1028,15 @@ pub fn growNonAllocSection( | ... | @@ -1028,21 +1028,15 @@ pub fn growNonAllocSection( |
| 1028 | const shdr = &self.shdrs.items[shdr_index]; | 1028 | const shdr = &self.shdrs.items[shdr_index]; |
| 1029 | | 1029 | |
| 1030 | if (needed_size > self.allocatedSize(shdr.sh_offset)) { | 1030 | if (needed_size > self.allocatedSize(shdr.sh_offset)) { |
| 1031 | const existing_size = if (self.symtab_section_index.? == shdr_index) blk: { | 1031 | const existing_size = shdr.sh_size; |
| 1032 | const sym_size: u64 = switch (self.ptr_width) { | | |
| 1033 | .p32 => @sizeOf(elf.Elf32_Sym), | | |
| 1034 | .p64 => @sizeOf(elf.Elf64_Sym), | | |
| 1035 | }; | | |
| 1036 | break :blk @as(u64, shdr.sh_info) * sym_size; | | |
| 1037 | } else shdr.sh_size; | | |
| 1038 | shdr.sh_size = 0; | 1032 | shdr.sh_size = 0; |
| 1039 | // Move all the symbols to a new file location. | 1033 | // Move all the symbols to a new file location. |
| 1040 | const new_offset = self.findFreeSpace(needed_size, min_alignment); | 1034 | const new_offset = self.findFreeSpace(needed_size, min_alignment); |
| 1041 | | 1035 | |
| 1042 | log.debug("moving '{?s}' from 0x{x} to 0x{x}", .{ | 1036 | log.debug("new '{s}' file offset 0x{x} to 0x{x}", .{ |
| 1043 | self.shstrtab.get(shdr.sh_name), | 1037 | self.shstrtab.getAssumeExists(shdr.sh_name), |
| 1044 | shdr.sh_offset, | | |
| 1045 | new_offset, | 1038 | new_offset, |
| | 1039 | new_offset + existing_size, |
| 1046 | }); | 1040 | }); |
| 1047 | | 1041 | |
| 1048 | if (requires_file_copy) { | 1042 | if (requires_file_copy) { |
| ... | @@ -3505,6 +3499,7 @@ fn updateSymtabSize(self: *Elf) !void { | ... | @@ -3505,6 +3499,7 @@ fn updateSymtabSize(self: *Elf) !void { |
| 3505 | .p64 => @alignOf(elf.Elf64_Sym), | 3499 | .p64 => @alignOf(elf.Elf64_Sym), |
| 3506 | }; | 3500 | }; |
| 3507 | const needed_size = (sizes.nlocals + sizes.nglobals + 1) * sym_size; | 3501 | const needed_size = (sizes.nlocals + sizes.nglobals + 1) * sym_size; |
| | 3502 | shdr.sh_size = needed_size; |
| 3508 | try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true); | 3503 | try self.growNonAllocSection(self.symtab_section_index.?, needed_size, sym_align, true); |
| 3509 | } | 3504 | } |
| 3510 | | 3505 | |