| ... | ... | @@ -407,7 +407,7 @@ fn updateComdatGroupsSizes(elf_file: *Elf) void { |
| 407 | 407 | |
| 408 | 408 | /// Allocates alloc sections when merging relocatable objects files together. |
| 409 | 409 | fn allocateAllocSections(elf_file: *Elf) !void { |
| 410 | | for (elf_file.sections.items(.shdr)) |*shdr| { |
| 410 | for (elf_file.sections.items(.shdr), 0..) |*shdr, shndx| { |
| 411 | 411 | if (shdr.sh_type == elf.SHT_NULL) continue; |
| 412 | 412 | if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue; |
| 413 | 413 | if (shdr.sh_type == elf.SHT_NOBITS) { |
| ... | ... | @@ -418,6 +418,34 @@ fn allocateAllocSections(elf_file: *Elf) !void { |
| 418 | 418 | if (needed_size > elf_file.allocatedSize(shdr.sh_offset)) { |
| 419 | 419 | shdr.sh_size = 0; |
| 420 | 420 | const new_offset = try elf_file.findFreeSpace(needed_size, shdr.sh_addralign); |
| 421 | |
| 422 | if (elf_file.zigObjectPtr()) |zo| blk: { |
| 423 | const existing_size = for ([_]?Symbol.Index{ |
| 424 | zo.text_index, |
| 425 | zo.rodata_index, |
| 426 | zo.data_relro_index, |
| 427 | zo.data_index, |
| 428 | zo.tdata_index, |
| 429 | zo.eh_frame_index, |
| 430 | }) |maybe_sym_index| { |
| 431 | const sect_sym_index = maybe_sym_index orelse continue; |
| 432 | const sect_atom_ptr = zo.symbol(sect_sym_index).atom(elf_file).?; |
| 433 | if (sect_atom_ptr.output_section_index == shndx) break sect_atom_ptr.size; |
| 434 | } else break :blk; |
| 435 | log.debug("moving {s} from 0x{x} to 0x{x}", .{ |
| 436 | elf_file.getShString(shdr.sh_name), |
| 437 | shdr.sh_offset, |
| 438 | new_offset, |
| 439 | }); |
| 440 | const amt = try elf_file.base.file.?.copyRangeAll( |
| 441 | shdr.sh_offset, |
| 442 | elf_file.base.file.?, |
| 443 | new_offset, |
| 444 | existing_size, |
| 445 | ); |
| 446 | if (amt != existing_size) return error.InputOutput; |
| 447 | } |
| 448 | |
| 421 | 449 | shdr.sh_offset = new_offset; |
| 422 | 450 | shdr.sh_size = needed_size; |
| 423 | 451 | } |