authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-10 17:35:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-11 10:33:54-07:00
log2c4e05eda7c3b6e27e83f85ca0a7c501c15775e7
treead351533e5121dff472437c6af922e8c7edada53
parentc3148988a3e1ccbe351b8d51359490eb8258c18f

link.Elf: group section indexes

so they cannot be forgotten when updating them after sorting them.

8 files changed, 229 insertions(+), 251 deletions(-)

src/link/Elf.zig+167-189
......@@ -57,6 +57,7 @@ phdrs: ProgramHeaderList = .empty,
5757
5858/// Special program headers.
5959phdr_indexes: ProgramHeaderIndexes = .{},
60section_indexes: SectionIndexes = .{},
6061
6162page_size: u32,
6263default_sym_version: elf.Elf64_Versym,
......@@ -99,29 +100,6 @@ rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .empty,
99100/// Applies only to a relocatable.
100101comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .empty,
101102
102copy_rel_section_index: ?u32 = null,
103dynamic_section_index: ?u32 = null,
104dynstrtab_section_index: ?u32 = null,
105dynsymtab_section_index: ?u32 = null,
106eh_frame_section_index: ?u32 = null,
107eh_frame_rela_section_index: ?u32 = null,
108eh_frame_hdr_section_index: ?u32 = null,
109hash_section_index: ?u32 = null,
110gnu_hash_section_index: ?u32 = null,
111got_section_index: ?u32 = null,
112got_plt_section_index: ?u32 = null,
113interp_section_index: ?u32 = null,
114plt_section_index: ?u32 = null,
115plt_got_section_index: ?u32 = null,
116rela_dyn_section_index: ?u32 = null,
117rela_plt_section_index: ?u32 = null,
118versym_section_index: ?u32 = null,
119verneed_section_index: ?u32 = null,
120
121shstrtab_section_index: ?u32 = null,
122strtab_section_index: ?u32 = null,
123symtab_section_index: ?u32 = null,
124
125103resolver: SymbolResolver = .{},
126104
127105has_text_reloc: bool = false,
......@@ -136,6 +114,31 @@ comment_merge_section_index: ?MergeSection.Index = null,
136114
137115first_eflags: ?elf.Elf64_Word = null,
138116
117const SectionIndexes = struct {
118 copy_rel: ?u32 = null,
119 dynamic: ?u32 = null,
120 dynstrtab: ?u32 = null,
121 dynsymtab: ?u32 = null,
122 eh_frame: ?u32 = null,
123 eh_frame_rela: ?u32 = null,
124 eh_frame_hdr: ?u32 = null,
125 hash: ?u32 = null,
126 gnu_hash: ?u32 = null,
127 got: ?u32 = null,
128 got_plt: ?u32 = null,
129 interp: ?u32 = null,
130 plt: ?u32 = null,
131 plt_got: ?u32 = null,
132 rela_dyn: ?u32 = null,
133 rela_plt: ?u32 = null,
134 versym: ?u32 = null,
135 verneed: ?u32 = null,
136
137 shstrtab: ?u32 = null,
138 strtab: ?u32 = null,
139 symtab: ?u32 = null,
140};
141
139142const ProgramHeaderList = std.ArrayListUnmanaged(elf.Elf64_Phdr);
140143
141144const OptionalProgramHeaderIndex = enum(u16) {
......@@ -2670,7 +2673,7 @@ pub fn writeElfHeader(self: *Elf) !void {
26702673 mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian);
26712674 index += 2;
26722675
2673 mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.shstrtab_section_index.?), endian);
2676 mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.section_indexes.shstrtab.?), endian);
26742677 index += 2;
26752678
26762679 assert(index == e_ehsize);
......@@ -2888,8 +2891,8 @@ fn initSyntheticSections(self: *Elf) !void {
28882891 } else false;
28892892 };
28902893 if (needs_eh_frame) {
2891 if (self.eh_frame_section_index == null) {
2892 self.eh_frame_section_index = self.sectionByName(".eh_frame") orelse try self.addSection(.{
2894 if (self.section_indexes.eh_frame == null) {
2895 self.section_indexes.eh_frame = self.sectionByName(".eh_frame") orelse try self.addSection(.{
28932896 .name = try self.insertShString(".eh_frame"),
28942897 .type = if (target.cpu.arch == .x86_64)
28952898 elf.SHT_X86_64_UNWIND
......@@ -2899,8 +2902,8 @@ fn initSyntheticSections(self: *Elf) !void {
28992902 .addralign = ptr_size,
29002903 });
29012904 }
2902 if (comp.link_eh_frame_hdr and self.eh_frame_hdr_section_index == null) {
2903 self.eh_frame_hdr_section_index = try self.addSection(.{
2905 if (comp.link_eh_frame_hdr and self.section_indexes.eh_frame_hdr == null) {
2906 self.section_indexes.eh_frame_hdr = try self.addSection(.{
29042907 .name = try self.insertShString(".eh_frame_hdr"),
29052908 .type = elf.SHT_PROGBITS,
29062909 .flags = elf.SHF_ALLOC,
......@@ -2909,8 +2912,8 @@ fn initSyntheticSections(self: *Elf) !void {
29092912 }
29102913 }
29112914
2912 if (self.got.entries.items.len > 0 and self.got_section_index == null) {
2913 self.got_section_index = try self.addSection(.{
2915 if (self.got.entries.items.len > 0 and self.section_indexes.got == null) {
2916 self.section_indexes.got = try self.addSection(.{
29142917 .name = try self.insertShString(".got"),
29152918 .type = elf.SHT_PROGBITS,
29162919 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
......@@ -2918,8 +2921,8 @@ fn initSyntheticSections(self: *Elf) !void {
29182921 });
29192922 }
29202923
2921 if (self.got_plt_section_index == null) {
2922 self.got_plt_section_index = try self.addSection(.{
2924 if (self.section_indexes.got_plt == null) {
2925 self.section_indexes.got_plt = try self.addSection(.{
29232926 .name = try self.insertShString(".got.plt"),
29242927 .type = elf.SHT_PROGBITS,
29252928 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
......@@ -2938,8 +2941,8 @@ fn initSyntheticSections(self: *Elf) !void {
29382941 }
29392942 break :blk false;
29402943 };
2941 if (needs_rela_dyn and self.rela_dyn_section_index == null) {
2942 self.rela_dyn_section_index = try self.addSection(.{
2944 if (needs_rela_dyn and self.section_indexes.rela_dyn == null) {
2945 self.section_indexes.rela_dyn = try self.addSection(.{
29432946 .name = try self.insertShString(".rela.dyn"),
29442947 .type = elf.SHT_RELA,
29452948 .flags = elf.SHF_ALLOC,
......@@ -2949,16 +2952,16 @@ fn initSyntheticSections(self: *Elf) !void {
29492952 }
29502953
29512954 if (self.plt.symbols.items.len > 0) {
2952 if (self.plt_section_index == null) {
2953 self.plt_section_index = try self.addSection(.{
2955 if (self.section_indexes.plt == null) {
2956 self.section_indexes.plt = try self.addSection(.{
29542957 .name = try self.insertShString(".plt"),
29552958 .type = elf.SHT_PROGBITS,
29562959 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
29572960 .addralign = 16,
29582961 });
29592962 }
2960 if (self.rela_plt_section_index == null) {
2961 self.rela_plt_section_index = try self.addSection(.{
2963 if (self.section_indexes.rela_plt == null) {
2964 self.section_indexes.rela_plt = try self.addSection(.{
29622965 .name = try self.insertShString(".rela.plt"),
29632966 .type = elf.SHT_RELA,
29642967 .flags = elf.SHF_ALLOC,
......@@ -2968,8 +2971,8 @@ fn initSyntheticSections(self: *Elf) !void {
29682971 }
29692972 }
29702973
2971 if (self.plt_got.symbols.items.len > 0 and self.plt_got_section_index == null) {
2972 self.plt_got_section_index = try self.addSection(.{
2974 if (self.plt_got.symbols.items.len > 0 and self.section_indexes.plt_got == null) {
2975 self.section_indexes.plt_got = try self.addSection(.{
29732976 .name = try self.insertShString(".plt.got"),
29742977 .type = elf.SHT_PROGBITS,
29752978 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
......@@ -2977,8 +2980,8 @@ fn initSyntheticSections(self: *Elf) !void {
29772980 });
29782981 }
29792982
2980 if (self.copy_rel.symbols.items.len > 0 and self.copy_rel_section_index == null) {
2981 self.copy_rel_section_index = try self.addSection(.{
2983 if (self.copy_rel.symbols.items.len > 0 and self.section_indexes.copy_rel == null) {
2984 self.section_indexes.copy_rel = try self.addSection(.{
29822985 .name = try self.insertShString(".copyrel"),
29832986 .type = elf.SHT_NOBITS,
29842987 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
......@@ -2994,8 +2997,8 @@ fn initSyntheticSections(self: *Elf) !void {
29942997 if (self.base.isStatic() and !comp.config.pie) break :blk false;
29952998 break :blk target.dynamic_linker.get() != null;
29962999 };
2997 if (needs_interp and self.interp_section_index == null) {
2998 self.interp_section_index = try self.addSection(.{
3000 if (needs_interp and self.section_indexes.interp == null) {
3001 self.section_indexes.interp = try self.addSection(.{
29993002 .name = try self.insertShString(".interp"),
30003003 .type = elf.SHT_PROGBITS,
30013004 .flags = elf.SHF_ALLOC,
......@@ -3004,8 +3007,8 @@ fn initSyntheticSections(self: *Elf) !void {
30043007 }
30053008
30063009 if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) {
3007 if (self.dynstrtab_section_index == null) {
3008 self.dynstrtab_section_index = try self.addSection(.{
3010 if (self.section_indexes.dynstrtab == null) {
3011 self.section_indexes.dynstrtab = try self.addSection(.{
30093012 .name = try self.insertShString(".dynstr"),
30103013 .flags = elf.SHF_ALLOC,
30113014 .type = elf.SHT_STRTAB,
......@@ -3013,8 +3016,8 @@ fn initSyntheticSections(self: *Elf) !void {
30133016 .addralign = 1,
30143017 });
30153018 }
3016 if (self.dynamic_section_index == null) {
3017 self.dynamic_section_index = try self.addSection(.{
3019 if (self.section_indexes.dynamic == null) {
3020 self.section_indexes.dynamic = try self.addSection(.{
30183021 .name = try self.insertShString(".dynamic"),
30193022 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
30203023 .type = elf.SHT_DYNAMIC,
......@@ -3022,8 +3025,8 @@ fn initSyntheticSections(self: *Elf) !void {
30223025 .addralign = @alignOf(elf.Elf64_Dyn),
30233026 });
30243027 }
3025 if (self.dynsymtab_section_index == null) {
3026 self.dynsymtab_section_index = try self.addSection(.{
3028 if (self.section_indexes.dynsymtab == null) {
3029 self.section_indexes.dynsymtab = try self.addSection(.{
30273030 .name = try self.insertShString(".dynsym"),
30283031 .flags = elf.SHF_ALLOC,
30293032 .type = elf.SHT_DYNSYM,
......@@ -3032,8 +3035,8 @@ fn initSyntheticSections(self: *Elf) !void {
30323035 .info = 1,
30333036 });
30343037 }
3035 if (self.hash_section_index == null) {
3036 self.hash_section_index = try self.addSection(.{
3038 if (self.section_indexes.hash == null) {
3039 self.section_indexes.hash = try self.addSection(.{
30373040 .name = try self.insertShString(".hash"),
30383041 .flags = elf.SHF_ALLOC,
30393042 .type = elf.SHT_HASH,
......@@ -3041,8 +3044,8 @@ fn initSyntheticSections(self: *Elf) !void {
30413044 .entsize = 4,
30423045 });
30433046 }
3044 if (self.gnu_hash_section_index == null) {
3045 self.gnu_hash_section_index = try self.addSection(.{
3047 if (self.section_indexes.gnu_hash == null) {
3048 self.section_indexes.gnu_hash = try self.addSection(.{
30463049 .name = try self.insertShString(".gnu.hash"),
30473050 .flags = elf.SHF_ALLOC,
30483051 .type = elf.SHT_GNU_HASH,
......@@ -3055,8 +3058,8 @@ fn initSyntheticSections(self: *Elf) !void {
30553058 if (sym.flags.import and sym.version_index & elf.VERSYM_VERSION > elf.VER_NDX_GLOBAL) break true;
30563059 } else false;
30573060 if (needs_versions) {
3058 if (self.versym_section_index == null) {
3059 self.versym_section_index = try self.addSection(.{
3061 if (self.section_indexes.versym == null) {
3062 self.section_indexes.versym = try self.addSection(.{
30603063 .name = try self.insertShString(".gnu.version"),
30613064 .flags = elf.SHF_ALLOC,
30623065 .type = elf.SHT_GNU_VERSYM,
......@@ -3064,8 +3067,8 @@ fn initSyntheticSections(self: *Elf) !void {
30643067 .entsize = @sizeOf(elf.Elf64_Versym),
30653068 });
30663069 }
3067 if (self.verneed_section_index == null) {
3068 self.verneed_section_index = try self.addSection(.{
3070 if (self.section_indexes.verneed == null) {
3071 self.section_indexes.verneed = try self.addSection(.{
30693072 .name = try self.insertShString(".gnu.version_r"),
30703073 .flags = elf.SHF_ALLOC,
30713074 .type = elf.SHT_GNU_VERNEED,
......@@ -3084,16 +3087,16 @@ pub fn initSymtab(self: *Elf) !void {
30843087 .p32 => true,
30853088 .p64 => false,
30863089 };
3087 if (self.symtab_section_index == null) {
3088 self.symtab_section_index = try self.addSection(.{
3090 if (self.section_indexes.symtab == null) {
3091 self.section_indexes.symtab = try self.addSection(.{
30893092 .name = try self.insertShString(".symtab"),
30903093 .type = elf.SHT_SYMTAB,
30913094 .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym),
30923095 .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym),
30933096 });
30943097 }
3095 if (self.strtab_section_index == null) {
3096 self.strtab_section_index = try self.addSection(.{
3098 if (self.section_indexes.strtab == null) {
3099 self.section_indexes.strtab = try self.addSection(.{
30973100 .name = try self.insertShString(".strtab"),
30983101 .type = elf.SHT_STRTAB,
30993102 .entsize = 1,
......@@ -3103,8 +3106,8 @@ pub fn initSymtab(self: *Elf) !void {
31033106}
31043107
31053108pub fn initShStrtab(self: *Elf) !void {
3106 if (self.shstrtab_section_index == null) {
3107 self.shstrtab_section_index = try self.addSection(.{
3109 if (self.section_indexes.shstrtab == null) {
3110 self.section_indexes.shstrtab = try self.addSection(.{
31083111 .name = try self.insertShString(".shstrtab"),
31093112 .type = elf.SHT_STRTAB,
31103113 .entsize = 1,
......@@ -3116,20 +3119,20 @@ pub fn initShStrtab(self: *Elf) !void {
31163119fn initSpecialPhdrs(self: *Elf) !void {
31173120 comptime assert(max_number_of_special_phdrs == 5);
31183121
3119 if (self.interp_section_index != null and self.phdr_indexes.interp == .none) {
3122 if (self.section_indexes.interp != null and self.phdr_indexes.interp == .none) {
31203123 self.phdr_indexes.interp = (try self.addPhdr(.{
31213124 .type = elf.PT_INTERP,
31223125 .flags = elf.PF_R,
31233126 .@"align" = 1,
31243127 })).toOptional();
31253128 }
3126 if (self.dynamic_section_index != null and self.phdr_indexes.dynamic == .none) {
3129 if (self.section_indexes.dynamic != null and self.phdr_indexes.dynamic == .none) {
31273130 self.phdr_indexes.dynamic = (try self.addPhdr(.{
31283131 .type = elf.PT_DYNAMIC,
31293132 .flags = elf.PF_R | elf.PF_W,
31303133 })).toOptional();
31313134 }
3132 if (self.eh_frame_hdr_section_index != null and self.phdr_indexes.gnu_eh_frame == .none) {
3135 if (self.section_indexes.eh_frame_hdr != null and self.phdr_indexes.gnu_eh_frame == .none) {
31333136 self.phdr_indexes.gnu_eh_frame = (try self.addPhdr(.{
31343137 .type = elf.PT_GNU_EH_FRAME,
31353138 .flags = elf.PF_R,
......@@ -3237,7 +3240,7 @@ fn sortInitFini(self: *Elf) !void {
32373240}
32383241
32393242fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void {
3240 if (self.dynamic_section_index == null) return;
3243 if (self.section_indexes.dynamic == null) return;
32413244
32423245 for (self.shared_objects.items) |index| {
32433246 const shared_object = self.file(index).?.shared_object;
......@@ -3255,13 +3258,13 @@ fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void {
32553258}
32563259
32573260fn sortDynamicSymtab(self: *Elf) void {
3258 if (self.gnu_hash_section_index == null) return;
3261 if (self.section_indexes.gnu_hash == null) return;
32593262 self.dynsym.sort(self);
32603263}
32613264
32623265fn setVersionSymtab(self: *Elf) !void {
32633266 const gpa = self.base.comp.gpa;
3264 if (self.versym_section_index == null) return;
3267 if (self.section_indexes.versym == null) return;
32653268 try self.versym.resize(gpa, self.dynsym.count());
32663269 self.versym.items[0] = elf.VER_NDX_LOCAL;
32673270 for (self.dynsym.entries.items, 1..) |entry, i| {
......@@ -3269,7 +3272,7 @@ fn setVersionSymtab(self: *Elf) !void {
32693272 self.versym.items[i] = sym.version_index;
32703273 }
32713274
3272 if (self.verneed_section_index) |shndx| {
3275 if (self.section_indexes.verneed) |shndx| {
32733276 try self.verneed.generate(self);
32743277 const shdr = &self.sections.items(.shdr)[shndx];
32753278 shdr.sh_info = @as(u32, @intCast(self.verneed.verneed.items.len));
......@@ -3277,10 +3280,10 @@ fn setVersionSymtab(self: *Elf) !void {
32773280}
32783281
32793282fn setHashSections(self: *Elf) !void {
3280 if (self.hash_section_index != null) {
3283 if (self.section_indexes.hash != null) {
32813284 try self.hash.generate(self);
32823285 }
3283 if (self.gnu_hash_section_index != null) {
3286 if (self.section_indexes.gnu_hash != null) {
32843287 try self.gnu_hash.calcSize(self);
32853288 }
32863289}
......@@ -3420,47 +3423,22 @@ pub fn sortShdrs(self: *Elf) !void {
34203423
34213424 const backlinks = try gpa.alloc(u32, entries.items.len);
34223425 defer gpa.free(backlinks);
3423 for (entries.items, 0..) |entry, i| {
3424 backlinks[entry.shndx] = @intCast(i);
3425 }
3426
3427 var slice = self.sections.toOwnedSlice();
3428 defer slice.deinit(gpa);
3429
3430 try self.sections.ensureTotalCapacity(gpa, slice.len);
3431 for (entries.items) |sorted| {
3432 self.sections.appendAssumeCapacity(slice.get(sorted.shndx));
3433 }
3434
3435 self.resetShdrIndexes(backlinks);
3436}
3437
3438fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void {
3439 for (&[_]*?u32{
3440 &self.eh_frame_section_index,
3441 &self.eh_frame_rela_section_index,
3442 &self.eh_frame_hdr_section_index,
3443 &self.got_section_index,
3444 &self.symtab_section_index,
3445 &self.strtab_section_index,
3446 &self.shstrtab_section_index,
3447 &self.interp_section_index,
3448 &self.dynamic_section_index,
3449 &self.dynsymtab_section_index,
3450 &self.dynstrtab_section_index,
3451 &self.hash_section_index,
3452 &self.gnu_hash_section_index,
3453 &self.plt_section_index,
3454 &self.got_plt_section_index,
3455 &self.plt_got_section_index,
3456 &self.rela_dyn_section_index,
3457 &self.rela_plt_section_index,
3458 &self.copy_rel_section_index,
3459 &self.versym_section_index,
3460 &self.verneed_section_index,
3461 }) |maybe_index| {
3462 if (maybe_index.*) |*index| {
3463 index.* = backlinks[index.*];
3426 {
3427 var slice = self.sections.toOwnedSlice();
3428 defer slice.deinit(gpa);
3429 try self.sections.resize(gpa, slice.len);
3430
3431 for (entries.items, 0..) |entry, i| {
3432 backlinks[entry.shndx] = @intCast(i);
3433 self.sections.set(i, slice.get(entry.shndx));
3434 }
3435 }
3436
3437 const special_indexes = &self.section_indexes;
3438
3439 inline for (@typeInfo(SectionIndexes).@"struct".fields) |field| {
3440 if (@field(special_indexes, field.name)) |special_index| {
3441 @field(special_indexes, field.name) = backlinks[special_index];
34643442 }
34653443 }
34663444
......@@ -3478,7 +3456,7 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void {
34783456 // FIXME:JK we should spin up .symtab potentially earlier, or set all non-dynamic RELA sections
34793457 // to point at symtab
34803458 // shdr.sh_link = backlinks[shdr.sh_link];
3481 shdr.sh_link = self.symtab_section_index.?;
3459 shdr.sh_link = self.section_indexes.symtab.?;
34823460 shdr.sh_info = backlinks[shdr.sh_info];
34833461 }
34843462 }
......@@ -3489,56 +3467,56 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void {
34893467 cg.shndx = backlinks[cg.shndx];
34903468 }
34913469
3492 if (self.symtab_section_index) |index| {
3470 if (self.section_indexes.symtab) |index| {
34933471 const shdr = &slice.items(.shdr)[index];
3494 shdr.sh_link = self.strtab_section_index.?;
3472 shdr.sh_link = self.section_indexes.strtab.?;
34953473 }
34963474
3497 if (self.dynamic_section_index) |index| {
3475 if (self.section_indexes.dynamic) |index| {
34983476 const shdr = &slice.items(.shdr)[index];
3499 shdr.sh_link = self.dynstrtab_section_index.?;
3477 shdr.sh_link = self.section_indexes.dynstrtab.?;
35003478 }
35013479
3502 if (self.dynsymtab_section_index) |index| {
3480 if (self.section_indexes.dynsymtab) |index| {
35033481 const shdr = &slice.items(.shdr)[index];
3504 shdr.sh_link = self.dynstrtab_section_index.?;
3482 shdr.sh_link = self.section_indexes.dynstrtab.?;
35053483 }
35063484
3507 if (self.hash_section_index) |index| {
3485 if (self.section_indexes.hash) |index| {
35083486 const shdr = &slice.items(.shdr)[index];
3509 shdr.sh_link = self.dynsymtab_section_index.?;
3487 shdr.sh_link = self.section_indexes.dynsymtab.?;
35103488 }
35113489
3512 if (self.gnu_hash_section_index) |index| {
3490 if (self.section_indexes.gnu_hash) |index| {
35133491 const shdr = &slice.items(.shdr)[index];
3514 shdr.sh_link = self.dynsymtab_section_index.?;
3492 shdr.sh_link = self.section_indexes.dynsymtab.?;
35153493 }
35163494
3517 if (self.versym_section_index) |index| {
3495 if (self.section_indexes.versym) |index| {
35183496 const shdr = &slice.items(.shdr)[index];
3519 shdr.sh_link = self.dynsymtab_section_index.?;
3497 shdr.sh_link = self.section_indexes.dynsymtab.?;
35203498 }
35213499
3522 if (self.verneed_section_index) |index| {
3500 if (self.section_indexes.verneed) |index| {
35233501 const shdr = &slice.items(.shdr)[index];
3524 shdr.sh_link = self.dynstrtab_section_index.?;
3502 shdr.sh_link = self.section_indexes.dynstrtab.?;
35253503 }
35263504
3527 if (self.rela_dyn_section_index) |index| {
3505 if (self.section_indexes.rela_dyn) |index| {
35283506 const shdr = &slice.items(.shdr)[index];
3529 shdr.sh_link = self.dynsymtab_section_index orelse 0;
3507 shdr.sh_link = self.section_indexes.dynsymtab orelse 0;
35303508 }
35313509
3532 if (self.rela_plt_section_index) |index| {
3510 if (self.section_indexes.rela_plt) |index| {
35333511 const shdr = &slice.items(.shdr)[index];
3534 shdr.sh_link = self.dynsymtab_section_index.?;
3535 shdr.sh_info = self.plt_section_index.?;
3512 shdr.sh_link = self.section_indexes.dynsymtab.?;
3513 shdr.sh_info = self.section_indexes.plt.?;
35363514 }
35373515
3538 if (self.eh_frame_rela_section_index) |index| {
3516 if (self.section_indexes.eh_frame_rela) |index| {
35393517 const shdr = &slice.items(.shdr)[index];
3540 shdr.sh_link = self.symtab_section_index.?;
3541 shdr.sh_info = self.eh_frame_section_index.?;
3518 shdr.sh_link = self.section_indexes.symtab.?;
3519 shdr.sh_info = self.section_indexes.eh_frame.?;
35423520 }
35433521}
35443522
......@@ -3572,31 +3550,31 @@ fn updateSectionSizes(self: *Elf) !void {
35723550 }
35733551
35743552 const shdrs = slice.items(.shdr);
3575 if (self.eh_frame_section_index) |index| {
3553 if (self.section_indexes.eh_frame) |index| {
35763554 shdrs[index].sh_size = try eh_frame.calcEhFrameSize(self);
35773555 }
35783556
3579 if (self.eh_frame_hdr_section_index) |index| {
3557 if (self.section_indexes.eh_frame_hdr) |index| {
35803558 shdrs[index].sh_size = eh_frame.calcEhFrameHdrSize(self);
35813559 }
35823560
3583 if (self.got_section_index) |index| {
3561 if (self.section_indexes.got) |index| {
35843562 shdrs[index].sh_size = self.got.size(self);
35853563 }
35863564
3587 if (self.plt_section_index) |index| {
3565 if (self.section_indexes.plt) |index| {
35883566 shdrs[index].sh_size = self.plt.size(self);
35893567 }
35903568
3591 if (self.got_plt_section_index) |index| {
3569 if (self.section_indexes.got_plt) |index| {
35923570 shdrs[index].sh_size = self.got_plt.size(self);
35933571 }
35943572
3595 if (self.plt_got_section_index) |index| {
3573 if (self.section_indexes.plt_got) |index| {
35963574 shdrs[index].sh_size = self.plt_got.size(self);
35973575 }
35983576
3599 if (self.rela_dyn_section_index) |shndx| {
3577 if (self.section_indexes.rela_dyn) |shndx| {
36003578 var num = self.got.numRela(self) + self.copy_rel.numRela();
36013579 if (self.zigObjectPtr()) |zig_object| {
36023580 num += zig_object.num_dynrelocs;
......@@ -3607,43 +3585,43 @@ fn updateSectionSizes(self: *Elf) !void {
36073585 shdrs[shndx].sh_size = num * @sizeOf(elf.Elf64_Rela);
36083586 }
36093587
3610 if (self.rela_plt_section_index) |index| {
3588 if (self.section_indexes.rela_plt) |index| {
36113589 shdrs[index].sh_size = self.plt.numRela() * @sizeOf(elf.Elf64_Rela);
36123590 }
36133591
3614 if (self.copy_rel_section_index) |index| {
3592 if (self.section_indexes.copy_rel) |index| {
36153593 try self.copy_rel.updateSectionSize(index, self);
36163594 }
36173595
3618 if (self.interp_section_index) |index| {
3596 if (self.section_indexes.interp) |index| {
36193597 shdrs[index].sh_size = self.getTarget().dynamic_linker.get().?.len + 1;
36203598 }
36213599
3622 if (self.hash_section_index) |index| {
3600 if (self.section_indexes.hash) |index| {
36233601 shdrs[index].sh_size = self.hash.size();
36243602 }
36253603
3626 if (self.gnu_hash_section_index) |index| {
3604 if (self.section_indexes.gnu_hash) |index| {
36273605 shdrs[index].sh_size = self.gnu_hash.size();
36283606 }
36293607
3630 if (self.dynamic_section_index) |index| {
3608 if (self.section_indexes.dynamic) |index| {
36313609 shdrs[index].sh_size = self.dynamic.size(self);
36323610 }
36333611
3634 if (self.dynsymtab_section_index) |index| {
3612 if (self.section_indexes.dynsymtab) |index| {
36353613 shdrs[index].sh_size = self.dynsym.size();
36363614 }
36373615
3638 if (self.dynstrtab_section_index) |index| {
3616 if (self.section_indexes.dynstrtab) |index| {
36393617 shdrs[index].sh_size = self.dynstrtab.items.len;
36403618 }
36413619
3642 if (self.versym_section_index) |index| {
3620 if (self.section_indexes.versym) |index| {
36433621 shdrs[index].sh_size = self.versym.items.len * @sizeOf(elf.Elf64_Versym);
36443622 }
36453623
3646 if (self.verneed_section_index) |index| {
3624 if (self.section_indexes.verneed) |index| {
36473625 shdrs[index].sh_size = self.verneed.size();
36483626 }
36493627
......@@ -3653,7 +3631,7 @@ fn updateSectionSizes(self: *Elf) !void {
36533631
36543632// FIXME:JK this is very much obsolete, remove!
36553633pub fn updateShStrtabSize(self: *Elf) void {
3656 if (self.shstrtab_section_index) |index| {
3634 if (self.section_indexes.shstrtab) |index| {
36573635 self.sections.items(.shdr)[index].sh_size = self.shstrtab.items.len;
36583636 }
36593637}
......@@ -3936,9 +3914,9 @@ fn allocateSpecialPhdrs(self: *Elf) void {
39363914 const slice = self.sections.slice();
39373915
39383916 for (&[_]struct { OptionalProgramHeaderIndex, ?u32 }{
3939 .{ self.phdr_indexes.interp, self.interp_section_index },
3940 .{ self.phdr_indexes.dynamic, self.dynamic_section_index },
3941 .{ self.phdr_indexes.gnu_eh_frame, self.eh_frame_hdr_section_index },
3917 .{ self.phdr_indexes.interp, self.section_indexes.interp },
3918 .{ self.phdr_indexes.dynamic, self.section_indexes.dynamic },
3919 .{ self.phdr_indexes.gnu_eh_frame, self.section_indexes.eh_frame_hdr },
39423920 }) |pair| {
39433921 if (pair[0].int()) |index| {
39443922 const shdr = slice.items(.shdr)[pair[1].?];
......@@ -4075,7 +4053,7 @@ pub fn updateSymtabSize(self: *Elf) !void {
40754053 strsize += ctx.strsize;
40764054 }
40774055
4078 if (self.got_section_index) |_| {
4056 if (self.section_indexes.got) |_| {
40794057 self.got.output_symtab_ctx.reset();
40804058 self.got.output_symtab_ctx.ilocal = nlocals;
40814059 self.got.updateSymtabSize(self);
......@@ -4083,7 +4061,7 @@ pub fn updateSymtabSize(self: *Elf) !void {
40834061 strsize += self.got.output_symtab_ctx.strsize;
40844062 }
40854063
4086 if (self.plt_section_index) |_| {
4064 if (self.section_indexes.plt) |_| {
40874065 self.plt.output_symtab_ctx.reset();
40884066 self.plt.output_symtab_ctx.ilocal = nlocals;
40894067 self.plt.updateSymtabSize(self);
......@@ -4091,7 +4069,7 @@ pub fn updateSymtabSize(self: *Elf) !void {
40914069 strsize += self.plt.output_symtab_ctx.strsize;
40924070 }
40934071
4094 if (self.plt_got_section_index) |_| {
4072 if (self.section_indexes.plt_got) |_| {
40954073 self.plt_got.output_symtab_ctx.reset();
40964074 self.plt_got.output_symtab_ctx.ilocal = nlocals;
40974075 self.plt_got.updateSymtabSize(self);
......@@ -4108,9 +4086,9 @@ pub fn updateSymtabSize(self: *Elf) !void {
41084086 }
41094087
41104088 const slice = self.sections.slice();
4111 const symtab_shdr = &slice.items(.shdr)[self.symtab_section_index.?];
4089 const symtab_shdr = &slice.items(.shdr)[self.section_indexes.symtab.?];
41124090 symtab_shdr.sh_info = nlocals;
4113 symtab_shdr.sh_link = self.strtab_section_index.?;
4091 symtab_shdr.sh_link = self.section_indexes.strtab.?;
41144092
41154093 const sym_size: u64 = switch (self.ptr_width) {
41164094 .p32 => @sizeOf(elf.Elf32_Sym),
......@@ -4119,7 +4097,7 @@ pub fn updateSymtabSize(self: *Elf) !void {
41194097 const needed_size = (nlocals + nglobals) * sym_size;
41204098 symtab_shdr.sh_size = needed_size;
41214099
4122 const strtab = &slice.items(.shdr)[self.strtab_section_index.?];
4100 const strtab = &slice.items(.shdr)[self.section_indexes.strtab.?];
41234101 strtab.sh_size = strsize + 1;
41244102}
41254103
......@@ -4127,7 +4105,7 @@ fn writeSyntheticSections(self: *Elf) !void {
41274105 const gpa = self.base.comp.gpa;
41284106 const slice = self.sections.slice();
41294107
4130 if (self.interp_section_index) |shndx| {
4108 if (self.section_indexes.interp) |shndx| {
41314109 var buffer: [256]u8 = undefined;
41324110 const interp = self.getTarget().dynamic_linker.get().?;
41334111 @memcpy(buffer[0..interp.len], interp);
......@@ -4138,12 +4116,12 @@ fn writeSyntheticSections(self: *Elf) !void {
41384116 try self.base.file.?.pwriteAll(contents, shdr.sh_offset);
41394117 }
41404118
4141 if (self.hash_section_index) |shndx| {
4119 if (self.section_indexes.hash) |shndx| {
41424120 const shdr = slice.items(.shdr)[shndx];
41434121 try self.base.file.?.pwriteAll(self.hash.buffer.items, shdr.sh_offset);
41444122 }
41454123
4146 if (self.gnu_hash_section_index) |shndx| {
4124 if (self.section_indexes.gnu_hash) |shndx| {
41474125 const shdr = slice.items(.shdr)[shndx];
41484126 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.gnu_hash.size());
41494127 defer buffer.deinit();
......@@ -4151,12 +4129,12 @@ fn writeSyntheticSections(self: *Elf) !void {
41514129 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
41524130 }
41534131
4154 if (self.versym_section_index) |shndx| {
4132 if (self.section_indexes.versym) |shndx| {
41554133 const shdr = slice.items(.shdr)[shndx];
41564134 try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.versym.items), shdr.sh_offset);
41574135 }
41584136
4159 if (self.verneed_section_index) |shndx| {
4137 if (self.section_indexes.verneed) |shndx| {
41604138 const shdr = slice.items(.shdr)[shndx];
41614139 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.verneed.size());
41624140 defer buffer.deinit();
......@@ -4164,7 +4142,7 @@ fn writeSyntheticSections(self: *Elf) !void {
41644142 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
41654143 }
41664144
4167 if (self.dynamic_section_index) |shndx| {
4145 if (self.section_indexes.dynamic) |shndx| {
41684146 const shdr = slice.items(.shdr)[shndx];
41694147 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynamic.size(self));
41704148 defer buffer.deinit();
......@@ -4172,7 +4150,7 @@ fn writeSyntheticSections(self: *Elf) !void {
41724150 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
41734151 }
41744152
4175 if (self.dynsymtab_section_index) |shndx| {
4153 if (self.section_indexes.dynsymtab) |shndx| {
41764154 const shdr = slice.items(.shdr)[shndx];
41774155 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynsym.size());
41784156 defer buffer.deinit();
......@@ -4180,12 +4158,12 @@ fn writeSyntheticSections(self: *Elf) !void {
41804158 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
41814159 }
41824160
4183 if (self.dynstrtab_section_index) |shndx| {
4161 if (self.section_indexes.dynstrtab) |shndx| {
41844162 const shdr = slice.items(.shdr)[shndx];
41854163 try self.base.file.?.pwriteAll(self.dynstrtab.items, shdr.sh_offset);
41864164 }
41874165
4188 if (self.eh_frame_section_index) |shndx| {
4166 if (self.section_indexes.eh_frame) |shndx| {
41894167 const existing_size = existing_size: {
41904168 const zo = self.zigObjectPtr() orelse break :existing_size 0;
41914169 const sym = zo.symbol(zo.eh_frame_index orelse break :existing_size 0);
......@@ -4200,7 +4178,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42004178 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset + existing_size);
42014179 }
42024180
4203 if (self.eh_frame_hdr_section_index) |shndx| {
4181 if (self.section_indexes.eh_frame_hdr) |shndx| {
42044182 const shdr = slice.items(.shdr)[shndx];
42054183 const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow;
42064184 var buffer = try std.ArrayList(u8).initCapacity(gpa, sh_size);
......@@ -4209,7 +4187,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42094187 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
42104188 }
42114189
4212 if (self.got_section_index) |index| {
4190 if (self.section_indexes.got) |index| {
42134191 const shdr = slice.items(.shdr)[index];
42144192 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got.size(self));
42154193 defer buffer.deinit();
......@@ -4217,7 +4195,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42174195 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
42184196 }
42194197
4220 if (self.rela_dyn_section_index) |shndx| {
4198 if (self.section_indexes.rela_dyn) |shndx| {
42214199 const shdr = slice.items(.shdr)[shndx];
42224200 try self.got.addRela(self);
42234201 try self.copy_rel.addRela(self);
......@@ -4225,7 +4203,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42254203 try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_dyn.items), shdr.sh_offset);
42264204 }
42274205
4228 if (self.plt_section_index) |shndx| {
4206 if (self.section_indexes.plt) |shndx| {
42294207 const shdr = slice.items(.shdr)[shndx];
42304208 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt.size(self));
42314209 defer buffer.deinit();
......@@ -4233,7 +4211,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42334211 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
42344212 }
42354213
4236 if (self.got_plt_section_index) |shndx| {
4214 if (self.section_indexes.got_plt) |shndx| {
42374215 const shdr = slice.items(.shdr)[shndx];
42384216 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got_plt.size(self));
42394217 defer buffer.deinit();
......@@ -4241,7 +4219,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42414219 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
42424220 }
42434221
4244 if (self.plt_got_section_index) |shndx| {
4222 if (self.section_indexes.plt_got) |shndx| {
42454223 const shdr = slice.items(.shdr)[shndx];
42464224 var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt_got.size(self));
42474225 defer buffer.deinit();
......@@ -4249,7 +4227,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42494227 try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset);
42504228 }
42514229
4252 if (self.rela_plt_section_index) |shndx| {
4230 if (self.section_indexes.rela_plt) |shndx| {
42534231 const shdr = slice.items(.shdr)[shndx];
42544232 try self.plt.addRela(self);
42554233 try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_plt.items), shdr.sh_offset);
......@@ -4261,7 +4239,7 @@ fn writeSyntheticSections(self: *Elf) !void {
42614239
42624240// FIXME:JK again, why is this needed?
42634241pub fn writeShStrtab(self: *Elf) !void {
4264 if (self.shstrtab_section_index) |index| {
4242 if (self.section_indexes.shstrtab) |index| {
42654243 const shdr = self.sections.items(.shdr)[index];
42664244 log.debug("writing .shstrtab from 0x{x} to 0x{x}", .{ shdr.sh_offset, shdr.sh_offset + shdr.sh_size });
42674245 try self.base.file.?.pwriteAll(self.shstrtab.items, shdr.sh_offset);
......@@ -4271,8 +4249,8 @@ pub fn writeShStrtab(self: *Elf) !void {
42714249pub fn writeSymtab(self: *Elf) !void {
42724250 const gpa = self.base.comp.gpa;
42734251 const slice = self.sections.slice();
4274 const symtab_shdr = slice.items(.shdr)[self.symtab_section_index.?];
4275 const strtab_shdr = slice.items(.shdr)[self.strtab_section_index.?];
4252 const symtab_shdr = slice.items(.shdr)[self.section_indexes.symtab.?];
4253 const strtab_shdr = slice.items(.shdr)[self.section_indexes.strtab.?];
42764254 const sym_size: u64 = switch (self.ptr_width) {
42774255 .p32 => @sizeOf(elf.Elf32_Sym),
42784256 .p64 => @sizeOf(elf.Elf64_Sym),
......@@ -4330,15 +4308,15 @@ pub fn writeSymtab(self: *Elf) !void {
43304308 obj.asFile().writeSymtab(self);
43314309 }
43324310
4333 if (self.got_section_index) |_| {
4311 if (self.section_indexes.got) |_| {
43344312 self.got.writeSymtab(self);
43354313 }
43364314
4337 if (self.plt_section_index) |_| {
4315 if (self.section_indexes.plt) |_| {
43384316 self.plt.writeSymtab(self);
43394317 }
43404318
4341 if (self.plt_got_section_index) |_| {
4319 if (self.section_indexes.plt_got) |_| {
43424320 self.plt_got.writeSymtab(self);
43434321 }
43444322
......@@ -4778,9 +4756,9 @@ pub fn mergeSection(self: *Elf, index: MergeSection.Index) *MergeSection {
47784756
47794757pub fn gotAddress(self: *Elf) i64 {
47804758 const shndx = blk: {
4781 if (self.getTarget().cpu.arch == .x86_64 and self.got_plt_section_index != null)
4782 break :blk self.got_plt_section_index.?;
4783 break :blk if (self.got_section_index) |shndx| shndx else null;
4759 if (self.getTarget().cpu.arch == .x86_64 and self.section_indexes.got_plt != null)
4760 break :blk self.section_indexes.got_plt.?;
4761 break :blk if (self.section_indexes.got) |shndx| shndx else null;
47844762 };
47854763 return if (shndx) |index| @intCast(self.sections.items(.shdr)[index].sh_addr) else 0;
47864764}
src/link/Elf/LinkerDefined.zig+6-6
......@@ -205,7 +205,7 @@ pub fn allocateSymbols(self: *LinkerDefined, elf_file: *Elf) void {
205205 }.allocSymbol;
206206
207207 // _DYNAMIC
208 if (elf_file.dynamic_section_index) |shndx| {
208 if (elf_file.section_indexes.dynamic) |shndx| {
209209 const shdr = shdrs[shndx];
210210 allocSymbol(self, self.dynamic_index.?, shdr.sh_addr, shndx, elf_file);
211211 }
......@@ -236,19 +236,19 @@ pub fn allocateSymbols(self: *LinkerDefined, elf_file: *Elf) void {
236236
237237 // _GLOBAL_OFFSET_TABLE_
238238 if (elf_file.getTarget().cpu.arch == .x86_64) {
239 if (elf_file.got_plt_section_index) |shndx| {
239 if (elf_file.section_indexes.got_plt) |shndx| {
240240 const shdr = shdrs[shndx];
241241 allocSymbol(self, self.got_index.?, shdr.sh_addr, shndx, elf_file);
242242 }
243243 } else {
244 if (elf_file.got_section_index) |shndx| {
244 if (elf_file.section_indexes.got) |shndx| {
245245 const shdr = shdrs[shndx];
246246 allocSymbol(self, self.got_index.?, shdr.sh_addr, shndx, elf_file);
247247 }
248248 }
249249
250250 // _PROCEDURE_LINKAGE_TABLE_
251 if (elf_file.plt_section_index) |shndx| {
251 if (elf_file.section_indexes.plt) |shndx| {
252252 const shdr = shdrs[shndx];
253253 allocSymbol(self, self.plt_index.?, shdr.sh_addr, shndx, elf_file);
254254 }
......@@ -262,13 +262,13 @@ pub fn allocateSymbols(self: *LinkerDefined, elf_file: *Elf) void {
262262 }
263263
264264 // __GNU_EH_FRAME_HDR
265 if (elf_file.eh_frame_hdr_section_index) |shndx| {
265 if (elf_file.section_indexes.eh_frame_hdr) |shndx| {
266266 const shdr = shdrs[shndx];
267267 allocSymbol(self, self.gnu_eh_frame_hdr_index.?, shdr.sh_addr, shndx, elf_file);
268268 }
269269
270270 // __rela_iplt_start, __rela_iplt_end
271 if (elf_file.rela_dyn_section_index) |shndx| blk: {
271 if (elf_file.section_indexes.rela_dyn) |shndx| blk: {
272272 if (link_mode != .static or comp.config.pie) break :blk;
273273 const shdr = shdrs[shndx];
274274 const end_addr = shdr.sh_addr + shdr.sh_size;
src/link/Elf/Object.zig+3-3
......@@ -927,7 +927,7 @@ pub fn initRelaSections(self: *Object, elf_file: *Elf) !void {
927927 for (self.atoms_indexes.items) |atom_index| {
928928 const atom_ptr = self.atom(atom_index) orelse continue;
929929 if (!atom_ptr.alive) continue;
930 if (atom_ptr.output_section_index == elf_file.eh_frame_section_index) continue;
930 if (atom_ptr.output_section_index == elf_file.section_indexes.eh_frame) continue;
931931 const shndx = atom_ptr.relocsShndx() orelse continue;
932932 const shdr = self.shdrs.items[shndx];
933933 const out_shndx = try elf_file.initOutputSection(.{
......@@ -947,7 +947,7 @@ pub fn addAtomsToRelaSections(self: *Object, elf_file: *Elf) !void {
947947 for (self.atoms_indexes.items) |atom_index| {
948948 const atom_ptr = self.atom(atom_index) orelse continue;
949949 if (!atom_ptr.alive) continue;
950 if (atom_ptr.output_section_index == elf_file.eh_frame_section_index) continue;
950 if (atom_ptr.output_section_index == elf_file.section_indexes.eh_frame) continue;
951951 const shndx = blk: {
952952 const shndx = atom_ptr.relocsShndx() orelse continue;
953953 const shdr = self.shdrs.items[shndx];
......@@ -960,7 +960,7 @@ pub fn addAtomsToRelaSections(self: *Object, elf_file: *Elf) !void {
960960 const slice = elf_file.sections.slice();
961961 const shdr = &slice.items(.shdr)[shndx];
962962 shdr.sh_info = atom_ptr.output_section_index;
963 shdr.sh_link = elf_file.symtab_section_index.?;
963 shdr.sh_link = elf_file.section_indexes.symtab.?;
964964 const gpa = elf_file.base.comp.gpa;
965965 const atom_list = &elf_file.sections.items(.atom_list)[shndx];
966966 try atom_list.append(gpa, .{ .index = atom_index, .file = self.index });
src/link/Elf/Symbol.zig+6-6
......@@ -128,7 +128,7 @@ pub fn address(symbol: Symbol, opts: struct { plt: bool = true, trampoline: bool
128128 if (mem.eql(u8, atom_ptr.name(elf_file), ".eh_frame")) {
129129 const sym_name = symbol.name(elf_file);
130130 const sh_addr, const sh_size = blk: {
131 const shndx = elf_file.eh_frame_section_index orelse break :blk .{ 0, 0 };
131 const shndx = elf_file.section_indexes.eh_frame orelse break :blk .{ 0, 0 };
132132 const shdr = elf_file.sections.items(.shdr)[shndx];
133133 break :blk .{ shdr.sh_addr, shdr.sh_size };
134134 };
......@@ -176,7 +176,7 @@ pub fn gotAddress(symbol: Symbol, elf_file: *Elf) i64 {
176176pub fn pltGotAddress(symbol: Symbol, elf_file: *Elf) i64 {
177177 if (!symbol.flags.has_pltgot) return 0;
178178 const extras = symbol.extra(elf_file);
179 const shdr = elf_file.sections.items(.shdr)[elf_file.plt_got_section_index.?];
179 const shdr = elf_file.sections.items(.shdr)[elf_file.section_indexes.plt_got.?];
180180 const cpu_arch = elf_file.getTarget().cpu.arch;
181181 return @intCast(shdr.sh_addr + extras.plt_got * PltGotSection.entrySize(cpu_arch));
182182}
......@@ -184,7 +184,7 @@ pub fn pltGotAddress(symbol: Symbol, elf_file: *Elf) i64 {
184184pub fn pltAddress(symbol: Symbol, elf_file: *Elf) i64 {
185185 if (!symbol.flags.has_plt) return 0;
186186 const extras = symbol.extra(elf_file);
187 const shdr = elf_file.sections.items(.shdr)[elf_file.plt_section_index.?];
187 const shdr = elf_file.sections.items(.shdr)[elf_file.section_indexes.plt.?];
188188 const cpu_arch = elf_file.getTarget().cpu.arch;
189189 return @intCast(shdr.sh_addr + extras.plt * PltSection.entrySize(cpu_arch) + PltSection.preambleSize(cpu_arch));
190190}
......@@ -192,13 +192,13 @@ pub fn pltAddress(symbol: Symbol, elf_file: *Elf) i64 {
192192pub fn gotPltAddress(symbol: Symbol, elf_file: *Elf) i64 {
193193 if (!symbol.flags.has_plt) return 0;
194194 const extras = symbol.extra(elf_file);
195 const shdr = elf_file.sections.items(.shdr)[elf_file.got_plt_section_index.?];
195 const shdr = elf_file.sections.items(.shdr)[elf_file.section_indexes.got_plt.?];
196196 return @intCast(shdr.sh_addr + extras.plt * 8 + GotPltSection.preamble_size);
197197}
198198
199199pub fn copyRelAddress(symbol: Symbol, elf_file: *Elf) i64 {
200200 if (!symbol.flags.has_copy_rel) return 0;
201 const shdr = elf_file.sections.items(.shdr)[elf_file.copy_rel_section_index.?];
201 const shdr = elf_file.sections.items(.shdr)[elf_file.section_indexes.copy_rel.?];
202202 return @as(i64, @intCast(shdr.sh_addr)) + symbol.value;
203203}
204204
......@@ -289,7 +289,7 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
289289 break :blk esym.st_bind();
290290 };
291291 const st_shndx: u16 = blk: {
292 if (symbol.flags.has_copy_rel) break :blk @intCast(elf_file.copy_rel_section_index.?);
292 if (symbol.flags.has_copy_rel) break :blk @intCast(elf_file.section_indexes.copy_rel.?);
293293 if (file_ptr == .shared_object or esym.st_shndx == elf.SHN_UNDEF) break :blk elf.SHN_UNDEF;
294294 if (elf_file.base.isRelocatable() and esym.st_shndx == elf.SHN_COMMON) break :blk elf.SHN_COMMON;
295295 if (symbol.mergeSubsection(elf_file)) |msub| break :blk @intCast(msub.mergeSection(elf_file).output_section_index);
src/link/Elf/ZigObject.zig+3-3
......@@ -791,7 +791,7 @@ pub fn initRelaSections(self: *ZigObject, elf_file: *Elf) !void {
791791 for (self.atoms_indexes.items) |atom_index| {
792792 const atom_ptr = self.atom(atom_index) orelse continue;
793793 if (!atom_ptr.alive) continue;
794 if (atom_ptr.output_section_index == elf_file.eh_frame_section_index) continue;
794 if (atom_ptr.output_section_index == elf_file.section_indexes.eh_frame) continue;
795795 const rela_shndx = atom_ptr.relocsShndx() orelse continue;
796796 // TODO this check will become obsolete when we rework our relocs mechanism at the ZigObject level
797797 if (self.relocs.items[rela_shndx].items.len == 0) continue;
......@@ -812,7 +812,7 @@ pub fn addAtomsToRelaSections(self: *ZigObject, elf_file: *Elf) !void {
812812 for (self.atoms_indexes.items) |atom_index| {
813813 const atom_ptr = self.atom(atom_index) orelse continue;
814814 if (!atom_ptr.alive) continue;
815 if (atom_ptr.output_section_index == elf_file.eh_frame_section_index) continue;
815 if (atom_ptr.output_section_index == elf_file.section_indexes.eh_frame) continue;
816816 const rela_shndx = atom_ptr.relocsShndx() orelse continue;
817817 // TODO this check will become obsolete when we rework our relocs mechanism at the ZigObject level
818818 if (self.relocs.items[rela_shndx].items.len == 0) continue;
......@@ -826,7 +826,7 @@ pub fn addAtomsToRelaSections(self: *ZigObject, elf_file: *Elf) !void {
826826 const out_rela_shndx = elf_file.sectionByName(rela_sect_name).?;
827827 const out_rela_shdr = &elf_file.sections.items(.shdr)[out_rela_shndx];
828828 out_rela_shdr.sh_info = out_shndx;
829 out_rela_shdr.sh_link = elf_file.symtab_section_index.?;
829 out_rela_shdr.sh_link = elf_file.section_indexes.symtab.?;
830830 const atom_list = &elf_file.sections.items(.atom_list)[out_rela_shndx];
831831 try atom_list.append(gpa, .{ .index = atom_index, .file = self.index });
832832 }
src/link/Elf/eh_frame.zig+6-6
......@@ -12,7 +12,7 @@ pub const Fde = struct {
1212 out_offset: u64 = 0,
1313
1414 pub fn address(fde: Fde, elf_file: *Elf) u64 {
15 const base: u64 = if (elf_file.eh_frame_section_index) |shndx|
15 const base: u64 = if (elf_file.section_indexes.eh_frame) |shndx|
1616 elf_file.sections.items(.shdr)[shndx].sh_addr
1717 else
1818 0;
......@@ -111,7 +111,7 @@ pub const Cie = struct {
111111 alive: bool = false,
112112
113113 pub fn address(cie: Cie, elf_file: *Elf) u64 {
114 const base: u64 = if (elf_file.eh_frame_section_index) |shndx|
114 const base: u64 = if (elf_file.section_indexes.eh_frame) |shndx|
115115 elf_file.sections.items(.shdr)[shndx].sh_addr
116116 else
117117 0;
......@@ -337,7 +337,7 @@ fn resolveReloc(rec: anytype, sym: *const Symbol, rel: elf.Elf64_Rela, elf_file:
337337
338338pub fn writeEhFrame(elf_file: *Elf, writer: anytype) !void {
339339 relocs_log.debug("{x}: .eh_frame", .{
340 elf_file.sections.items(.shdr)[elf_file.eh_frame_section_index.?].sh_addr,
340 elf_file.sections.items(.shdr)[elf_file.section_indexes.eh_frame.?].sh_addr,
341341 });
342342
343343 var has_reloc_errors = false;
......@@ -458,7 +458,7 @@ fn emitReloc(elf_file: *Elf, r_offset: u64, sym: *const Symbol, rel: elf.Elf64_R
458458
459459pub fn writeEhFrameRelocs(elf_file: *Elf, writer: anytype) !void {
460460 relocs_log.debug("{x}: .eh_frame", .{
461 elf_file.sections.items(.shdr)[elf_file.eh_frame_section_index.?].sh_addr,
461 elf_file.sections.items(.shdr)[elf_file.section_indexes.eh_frame.?].sh_addr,
462462 });
463463
464464 if (elf_file.zigObjectPtr()) |zo| zo: {
......@@ -511,8 +511,8 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
511511 try writer.writeByte(DW_EH_PE.datarel | DW_EH_PE.sdata4);
512512
513513 const shdrs = elf_file.sections.items(.shdr);
514 const eh_frame_shdr = shdrs[elf_file.eh_frame_section_index.?];
515 const eh_frame_hdr_shdr = shdrs[elf_file.eh_frame_hdr_section_index.?];
514 const eh_frame_shdr = shdrs[elf_file.section_indexes.eh_frame.?];
515 const eh_frame_hdr_shdr = shdrs[elf_file.section_indexes.eh_frame_hdr.?];
516516 const num_fdes = @as(u32, @intCast(@divExact(eh_frame_hdr_shdr.sh_size - eh_frame_hdr_header_size, 8)));
517517 const existing_size = existing_size: {
518518 const zo = elf_file.zigObjectPtr() orelse break :existing_size 0;
src/link/Elf/relocatable.zig+11-11
......@@ -288,8 +288,8 @@ fn initSections(elf_file: *Elf) !void {
288288 } else false;
289289 };
290290 if (needs_eh_frame) {
291 if (elf_file.eh_frame_section_index == null) {
292 elf_file.eh_frame_section_index = elf_file.sectionByName(".eh_frame") orelse
291 if (elf_file.section_indexes.eh_frame == null) {
292 elf_file.section_indexes.eh_frame = elf_file.sectionByName(".eh_frame") orelse
293293 try elf_file.addSection(.{
294294 .name = try elf_file.insertShString(".eh_frame"),
295295 .type = if (elf_file.getTarget().cpu.arch == .x86_64)
......@@ -300,10 +300,10 @@ fn initSections(elf_file: *Elf) !void {
300300 .addralign = elf_file.ptrWidthBytes(),
301301 });
302302 }
303 elf_file.eh_frame_rela_section_index = elf_file.sectionByName(".rela.eh_frame") orelse
303 elf_file.section_indexes.eh_frame_rela = elf_file.sectionByName(".rela.eh_frame") orelse
304304 try elf_file.addRelaShdr(
305305 try elf_file.insertShString(".rela.eh_frame"),
306 elf_file.eh_frame_section_index.?,
306 elf_file.section_indexes.eh_frame.?,
307307 );
308308 }
309309
......@@ -346,7 +346,7 @@ fn updateSectionSizes(elf_file: *Elf) !void {
346346 for (slice.items(.shdr), 0..) |*shdr, shndx| {
347347 const atom_list = slice.items(.atom_list)[shndx];
348348 if (shdr.sh_type != elf.SHT_RELA) continue;
349 if (@as(u32, @intCast(shndx)) == elf_file.eh_frame_section_index) continue;
349 if (@as(u32, @intCast(shndx)) == elf_file.section_indexes.eh_frame) continue;
350350 for (atom_list.items) |ref| {
351351 const atom_ptr = elf_file.atom(ref) orelse continue;
352352 if (!atom_ptr.alive) continue;
......@@ -357,10 +357,10 @@ fn updateSectionSizes(elf_file: *Elf) !void {
357357 if (shdr.sh_size == 0) shdr.sh_offset = 0;
358358 }
359359
360 if (elf_file.eh_frame_section_index) |index| {
360 if (elf_file.section_indexes.eh_frame) |index| {
361361 slice.items(.shdr)[index].sh_size = try eh_frame.calcEhFrameSize(elf_file);
362362 }
363 if (elf_file.eh_frame_rela_section_index) |index| {
363 if (elf_file.section_indexes.eh_frame_rela) |index| {
364364 const shdr = &slice.items(.shdr)[index];
365365 shdr.sh_size = eh_frame.calcEhFrameRelocs(elf_file) * shdr.sh_entsize;
366366 }
......@@ -374,7 +374,7 @@ fn updateComdatGroupsSizes(elf_file: *Elf) void {
374374 for (elf_file.comdat_group_sections.items) |cg| {
375375 const shdr = &elf_file.sections.items(.shdr)[cg.shndx];
376376 shdr.sh_size = cg.size(elf_file);
377 shdr.sh_link = elf_file.symtab_section_index.?;
377 shdr.sh_link = elf_file.section_indexes.symtab.?;
378378
379379 const sym = cg.symbol(elf_file);
380380 shdr.sh_info = sym.outputSymtabIndex(elf_file) orelse sym.outputShndx(elf_file).?;
......@@ -439,7 +439,7 @@ fn writeSyntheticSections(elf_file: *Elf) !void {
439439 for (slice.items(.shdr), slice.items(.atom_list), 0..) |shdr, atom_list, shndx| {
440440 if (shdr.sh_type != elf.SHT_RELA) continue;
441441 if (atom_list.items.len == 0) continue;
442 if (@as(u32, @intCast(shndx)) == elf_file.eh_frame_section_index) continue;
442 if (@as(u32, @intCast(shndx)) == elf_file.section_indexes.eh_frame) continue;
443443
444444 const num_relocs = math.cast(usize, @divExact(shdr.sh_size, shdr.sh_entsize)) orelse
445445 return error.Overflow;
......@@ -471,7 +471,7 @@ fn writeSyntheticSections(elf_file: *Elf) !void {
471471 try elf_file.base.file.?.pwriteAll(mem.sliceAsBytes(relocs.items), shdr.sh_offset);
472472 }
473473
474 if (elf_file.eh_frame_section_index) |shndx| {
474 if (elf_file.section_indexes.eh_frame) |shndx| {
475475 const existing_size = existing_size: {
476476 const zo = elf_file.zigObjectPtr() orelse break :existing_size 0;
477477 const sym = zo.symbol(zo.eh_frame_index orelse break :existing_size 0);
......@@ -489,7 +489,7 @@ fn writeSyntheticSections(elf_file: *Elf) !void {
489489 assert(buffer.items.len == sh_size - existing_size);
490490 try elf_file.base.file.?.pwriteAll(buffer.items, shdr.sh_offset + existing_size);
491491 }
492 if (elf_file.eh_frame_rela_section_index) |shndx| {
492 if (elf_file.section_indexes.eh_frame_rela) |shndx| {
493493 const shdr = slice.items(.shdr)[shndx];
494494 const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow;
495495 var buffer = try std.ArrayList(u8).initCapacity(gpa, sh_size);
src/link/Elf/synthetic_sections.zig+27-27
......@@ -75,18 +75,18 @@ pub const DynamicSection = struct {
7575 if (elf_file.sectionByName(".fini") != null) nentries += 1; // FINI
7676 if (elf_file.sectionByName(".init_array") != null) nentries += 2; // INIT_ARRAY
7777 if (elf_file.sectionByName(".fini_array") != null) nentries += 2; // FINI_ARRAY
78 if (elf_file.rela_dyn_section_index != null) nentries += 3; // RELA
79 if (elf_file.rela_plt_section_index != null) nentries += 3; // JMPREL
80 if (elf_file.got_plt_section_index != null) nentries += 1; // PLTGOT
78 if (elf_file.section_indexes.rela_dyn != null) nentries += 3; // RELA
79 if (elf_file.section_indexes.rela_plt != null) nentries += 3; // JMPREL
80 if (elf_file.section_indexes.got_plt != null) nentries += 1; // PLTGOT
8181 nentries += 1; // HASH
82 if (elf_file.gnu_hash_section_index != null) nentries += 1; // GNU_HASH
82 if (elf_file.section_indexes.gnu_hash != null) nentries += 1; // GNU_HASH
8383 if (elf_file.has_text_reloc) nentries += 1; // TEXTREL
8484 nentries += 1; // SYMTAB
8585 nentries += 1; // SYMENT
8686 nentries += 1; // STRTAB
8787 nentries += 1; // STRSZ
88 if (elf_file.versym_section_index != null) nentries += 1; // VERSYM
89 if (elf_file.verneed_section_index != null) nentries += 2; // VERNEED
88 if (elf_file.section_indexes.versym != null) nentries += 1; // VERSYM
89 if (elf_file.section_indexes.verneed != null) nentries += 2; // VERNEED
9090 if (dt.getFlags(elf_file) != null) nentries += 1; // FLAGS
9191 if (dt.getFlags1(elf_file) != null) nentries += 1; // FLAGS_1
9292 if (!elf_file.isEffectivelyDynLib()) nentries += 1; // DEBUG
......@@ -139,7 +139,7 @@ pub const DynamicSection = struct {
139139 }
140140
141141 // RELA
142 if (elf_file.rela_dyn_section_index) |shndx| {
142 if (elf_file.section_indexes.rela_dyn) |shndx| {
143143 const shdr = shdrs[shndx];
144144 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_RELA, .d_val = shdr.sh_addr });
145145 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_RELASZ, .d_val = shdr.sh_size });
......@@ -147,7 +147,7 @@ pub const DynamicSection = struct {
147147 }
148148
149149 // JMPREL
150 if (elf_file.rela_plt_section_index) |shndx| {
150 if (elf_file.section_indexes.rela_plt) |shndx| {
151151 const shdr = shdrs[shndx];
152152 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_JMPREL, .d_val = shdr.sh_addr });
153153 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_PLTRELSZ, .d_val = shdr.sh_size });
......@@ -155,18 +155,18 @@ pub const DynamicSection = struct {
155155 }
156156
157157 // PLTGOT
158 if (elf_file.got_plt_section_index) |shndx| {
158 if (elf_file.section_indexes.got_plt) |shndx| {
159159 const addr = shdrs[shndx].sh_addr;
160160 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_PLTGOT, .d_val = addr });
161161 }
162162
163163 {
164 assert(elf_file.hash_section_index != null);
165 const addr = shdrs[elf_file.hash_section_index.?].sh_addr;
164 assert(elf_file.section_indexes.hash != null);
165 const addr = shdrs[elf_file.section_indexes.hash.?].sh_addr;
166166 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_HASH, .d_val = addr });
167167 }
168168
169 if (elf_file.gnu_hash_section_index) |shndx| {
169 if (elf_file.section_indexes.gnu_hash) |shndx| {
170170 const addr = shdrs[shndx].sh_addr;
171171 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_GNU_HASH, .d_val = addr });
172172 }
......@@ -178,28 +178,28 @@ pub const DynamicSection = struct {
178178
179179 // SYMTAB + SYMENT
180180 {
181 assert(elf_file.dynsymtab_section_index != null);
182 const shdr = shdrs[elf_file.dynsymtab_section_index.?];
181 assert(elf_file.section_indexes.dynsymtab != null);
182 const shdr = shdrs[elf_file.section_indexes.dynsymtab.?];
183183 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_SYMTAB, .d_val = shdr.sh_addr });
184184 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_SYMENT, .d_val = shdr.sh_entsize });
185185 }
186186
187187 // STRTAB + STRSZ
188188 {
189 assert(elf_file.dynstrtab_section_index != null);
190 const shdr = shdrs[elf_file.dynstrtab_section_index.?];
189 assert(elf_file.section_indexes.dynstrtab != null);
190 const shdr = shdrs[elf_file.section_indexes.dynstrtab.?];
191191 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_STRTAB, .d_val = shdr.sh_addr });
192192 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_STRSZ, .d_val = shdr.sh_size });
193193 }
194194
195195 // VERSYM
196 if (elf_file.versym_section_index) |shndx| {
196 if (elf_file.section_indexes.versym) |shndx| {
197197 const addr = shdrs[shndx].sh_addr;
198198 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_VERSYM, .d_val = addr });
199199 }
200200
201201 // VERNEED + VERNEEDNUM
202 if (elf_file.verneed_section_index) |shndx| {
202 if (elf_file.section_indexes.verneed) |shndx| {
203203 const addr = shdrs[shndx].sh_addr;
204204 try writer.writeStruct(elf.Elf64_Dyn{ .d_tag = elf.DT_VERNEED, .d_val = addr });
205205 try writer.writeStruct(elf.Elf64_Dyn{
......@@ -261,7 +261,7 @@ pub const GotSection = struct {
261261
262262 pub fn address(entry: Entry, elf_file: *Elf) i64 {
263263 const ptr_bytes = elf_file.archPtrWidthBytes();
264 const shdr = &elf_file.sections.items(.shdr)[elf_file.got_section_index.?];
264 const shdr = &elf_file.sections.items(.shdr)[elf_file.section_indexes.got.?];
265265 return @as(i64, @intCast(shdr.sh_addr)) + entry.cell_index * ptr_bytes;
266266 }
267267 };
......@@ -599,7 +599,7 @@ pub const GotSection = struct {
599599 .st_name = st_name,
600600 .st_info = elf.STT_OBJECT,
601601 .st_other = 0,
602 .st_shndx = @intCast(elf_file.got_section_index.?),
602 .st_shndx = @intCast(elf_file.section_indexes.got.?),
603603 .st_value = @intCast(st_value),
604604 .st_size = st_size,
605605 };
......@@ -742,7 +742,7 @@ pub const PltSection = struct {
742742 .st_name = st_name,
743743 .st_info = elf.STT_FUNC,
744744 .st_other = 0,
745 .st_shndx = @intCast(elf_file.plt_section_index.?),
745 .st_shndx = @intCast(elf_file.section_indexes.plt.?),
746746 .st_value = @intCast(sym.pltAddress(elf_file)),
747747 .st_size = entrySize(cpu_arch),
748748 };
......@@ -784,8 +784,8 @@ pub const PltSection = struct {
784784 const x86_64 = struct {
785785 fn write(plt: PltSection, elf_file: *Elf, writer: anytype) !void {
786786 const shdrs = elf_file.sections.items(.shdr);
787 const plt_addr = shdrs[elf_file.plt_section_index.?].sh_addr;
788 const got_plt_addr = shdrs[elf_file.got_plt_section_index.?].sh_addr;
787 const plt_addr = shdrs[elf_file.section_indexes.plt.?].sh_addr;
788 const got_plt_addr = shdrs[elf_file.section_indexes.got_plt.?].sh_addr;
789789 var preamble = [_]u8{
790790 0xf3, 0x0f, 0x1e, 0xfa, // endbr64
791791 0x41, 0x53, // push r11
......@@ -820,8 +820,8 @@ pub const PltSection = struct {
820820 fn write(plt: PltSection, elf_file: *Elf, writer: anytype) !void {
821821 {
822822 const shdrs = elf_file.sections.items(.shdr);
823 const plt_addr: i64 = @intCast(shdrs[elf_file.plt_section_index.?].sh_addr);
824 const got_plt_addr: i64 = @intCast(shdrs[elf_file.got_plt_section_index.?].sh_addr);
823 const plt_addr: i64 = @intCast(shdrs[elf_file.section_indexes.plt.?].sh_addr);
824 const got_plt_addr: i64 = @intCast(shdrs[elf_file.section_indexes.got_plt.?].sh_addr);
825825 // TODO: relax if possible
826826 // .got.plt[2]
827827 const pages = try aarch64_util.calcNumberOfPages(plt_addr + 4, got_plt_addr + 16);
......@@ -894,7 +894,7 @@ pub const GotPltSection = struct {
894894 // [2]: 0x0
895895 try writer.writeInt(u64, 0x0, .little);
896896 try writer.writeInt(u64, 0x0, .little);
897 if (elf_file.plt_section_index) |shndx| {
897 if (elf_file.section_indexes.plt) |shndx| {
898898 const plt_addr = elf_file.sections.items(.shdr)[shndx].sh_addr;
899899 for (0..elf_file.plt.symbols.items.len) |_| {
900900 // [N]: .plt
......@@ -962,7 +962,7 @@ pub const PltGotSection = struct {
962962 .st_name = st_name,
963963 .st_info = elf.STT_FUNC,
964964 .st_other = 0,
965 .st_shndx = @intCast(elf_file.plt_got_section_index.?),
965 .st_shndx = @intCast(elf_file.section_indexes.plt_got.?),
966966 .st_value = @intCast(sym.pltGotAddress(elf_file)),
967967 .st_size = 16,
968968 };