diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-02 18:24:05 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-10-16 19:33:04 +0200 |
| commit | 679accd8873ab08ebb0e8d7b2b537c18bd77d821 (patch) | |
| tree | 2bd0e9bf6aa95d82e7ce01ec81b0f346ae9f8399 /src/link/Elf/Object.zig | |
| parent | 509da2316c2f8ec3a3939df09ca288f92dc55905 (diff) | |
| download | zig-679accd8873ab08ebb0e8d7b2b537c18bd77d821.tar.gz zig-679accd8873ab08ebb0e8d7b2b537c18bd77d821.zip | |
elf: initialize output sections from input objects in a separate step
Diffstat (limited to 'src/link/Elf/Object.zig')
| -rw-r--r-- | src/link/Elf/Object.zig | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index 191f6774a5..f6c8306f3b 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -194,10 +194,10 @@ fn addAtom( } } -fn getOutputSectionIndex(self: *Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{OutOfMemory}!u16 { +pub fn getOutputSectionIndex(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{OutOfMemory}!u16 { const name = blk: { const name = self.strings.getAssumeExists(shdr.sh_name); - // if (shdr.sh_flags & elf.SHF_MERGE != 0) break :blk name; + if (shdr.sh_flags & elf.SHF_MERGE != 0) break :blk name; const sh_name_prefixes: []const [:0]const u8 = &.{ ".text", ".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss", ".init_array", ".fini_array", ".tbss", ".tdata", ".gcc_except_table", ".ctors", @@ -231,32 +231,11 @@ fn getOutputSectionIndex(self: *Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) er else => flags, }; }; - const out_shndx = elf_file.sectionByName(name) orelse blk: { - const is_alloc = flags & elf.SHF_ALLOC != 0; - const is_write = flags & elf.SHF_WRITE != 0; - const is_exec = flags & elf.SHF_EXECINSTR != 0; - if (!is_alloc) { - log.err("{}: output section {s} not found", .{ self.fmtPath(), name }); - @panic("TODO: missing output section!"); - } - var phdr_flags: u32 = elf.PF_R; - if (is_write) phdr_flags |= elf.PF_W; - if (is_exec) phdr_flags |= elf.PF_X; - const phdr_index = try elf_file.allocateSegment(.{ - .size = Elf.padToIdeal(shdr.sh_size), - .alignment = elf_file.page_size, - .flags = phdr_flags, - }); - const shndx = try elf_file.allocateAllocSection(.{ - .name = name, - .phdr_index = phdr_index, - .alignment = shdr.sh_addralign, - .flags = flags, - .type = @"type", - }); - try elf_file.last_atom_and_free_list_table.putNoClobber(elf_file.base.allocator, shndx, .{}); - break :blk shndx; - }; + const out_shndx = elf_file.sectionByName(name) orelse try elf_file.addSection(.{ + .type = @"type", + .flags = flags, + .name = name, + }); return out_shndx; } |
