authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-13 17:24:46+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-13 20:33:08+01:00
log216a5594f62aca7524012e0a2bbf226c4064fae4
treedb3497aaf292af43f3dffbabfa124a678c176363
parente401930fa862e3b9b3eedc8eb405c501fbf3de30

elf: use u32 for all section indexes


6 files changed, 78 insertions(+), 78 deletions(-)

src/link/Elf.zig+57-57
...@@ -138,40 +138,40 @@ comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .{},...@@ -138,40 +138,40 @@ comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .{},
138138
139/// Tracked section headers with incremental updates to Zig object.139/// Tracked section headers with incremental updates to Zig object.
140/// .rela.* sections are only used when emitting a relocatable object file.140/// .rela.* sections are only used when emitting a relocatable object file.
141zig_text_section_index: ?u16 = null,141zig_text_section_index: ?u32 = null,
142zig_data_rel_ro_section_index: ?u16 = null,142zig_data_rel_ro_section_index: ?u32 = null,
143zig_data_section_index: ?u16 = null,143zig_data_section_index: ?u32 = null,
144zig_bss_section_index: ?u16 = null,144zig_bss_section_index: ?u32 = null,
145zig_got_section_index: ?u16 = null,145zig_got_section_index: ?u32 = null,
146146
147debug_info_section_index: ?u16 = null,147debug_info_section_index: ?u32 = null,
148debug_abbrev_section_index: ?u16 = null,148debug_abbrev_section_index: ?u32 = null,
149debug_str_section_index: ?u16 = null,149debug_str_section_index: ?u32 = null,
150debug_aranges_section_index: ?u16 = null,150debug_aranges_section_index: ?u32 = null,
151debug_line_section_index: ?u16 = null,151debug_line_section_index: ?u32 = null,
152152
153copy_rel_section_index: ?u16 = null,153copy_rel_section_index: ?u32 = null,
154dynamic_section_index: ?u16 = null,154dynamic_section_index: ?u32 = null,
155dynstrtab_section_index: ?u16 = null,155dynstrtab_section_index: ?u32 = null,
156dynsymtab_section_index: ?u16 = null,156dynsymtab_section_index: ?u32 = null,
157eh_frame_section_index: ?u16 = null,157eh_frame_section_index: ?u32 = null,
158eh_frame_rela_section_index: ?u16 = null,158eh_frame_rela_section_index: ?u32 = null,
159eh_frame_hdr_section_index: ?u16 = null,159eh_frame_hdr_section_index: ?u32 = null,
160hash_section_index: ?u16 = null,160hash_section_index: ?u32 = null,
161gnu_hash_section_index: ?u16 = null,161gnu_hash_section_index: ?u32 = null,
162got_section_index: ?u16 = null,162got_section_index: ?u32 = null,
163got_plt_section_index: ?u16 = null,163got_plt_section_index: ?u32 = null,
164interp_section_index: ?u16 = null,164interp_section_index: ?u32 = null,
165plt_section_index: ?u16 = null,165plt_section_index: ?u32 = null,
166plt_got_section_index: ?u16 = null,166plt_got_section_index: ?u32 = null,
167rela_dyn_section_index: ?u16 = null,167rela_dyn_section_index: ?u32 = null,
168rela_plt_section_index: ?u16 = null,168rela_plt_section_index: ?u32 = null,
169versym_section_index: ?u16 = null,169versym_section_index: ?u32 = null,
170verneed_section_index: ?u16 = null,170verneed_section_index: ?u32 = null,
171171
172shstrtab_section_index: ?u16 = null,172shstrtab_section_index: ?u32 = null,
173strtab_section_index: ?u16 = null,173strtab_section_index: ?u32 = null,
174symtab_section_index: ?u16 = null,174symtab_section_index: ?u32 = null,
175175
176// Linker-defined symbols176// Linker-defined symbols
177dynamic_index: ?Symbol.Index = null,177dynamic_index: ?Symbol.Index = null,
...@@ -931,7 +931,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {...@@ -931,7 +931,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void {
931 try self.base.file.?.pwriteAll(&[1]u8{0}, end_pos);931 try self.base.file.?.pwriteAll(&[1]u8{0}, end_pos);
932}932}
933933
934pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {934pub fn growAllocSection(self: *Elf, shdr_index: u32, needed_size: u64) !void {
935 const shdr = &self.shdrs.items[shdr_index];935 const shdr = &self.shdrs.items[shdr_index];
936 const maybe_phdr = if (self.phdr_to_shdr_table.get(shdr_index)) |phndx| &self.phdrs.items[phndx] else null;936 const maybe_phdr = if (self.phdr_to_shdr_table.get(shdr_index)) |phndx| &self.phdrs.items[phndx] else null;
937 const is_zerofill = shdr.sh_type == elf.SHT_NOBITS;937 const is_zerofill = shdr.sh_type == elf.SHT_NOBITS;
...@@ -981,7 +981,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {...@@ -981,7 +981,7 @@ pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {
981981
982pub fn growNonAllocSection(982pub fn growNonAllocSection(
983 self: *Elf,983 self: *Elf,
984 shdr_index: u16,984 shdr_index: u32,
985 needed_size: u64,985 needed_size: u64,
986 min_alignment: u32,986 min_alignment: u32,
987 requires_file_copy: bool,987 requires_file_copy: bool,
...@@ -1018,7 +1018,7 @@ pub fn growNonAllocSection(...@@ -1018,7 +1018,7 @@ pub fn growNonAllocSection(
1018 self.markDirty(shdr_index);1018 self.markDirty(shdr_index);
1019}1019}
10201020
1021pub fn markDirty(self: *Elf, shdr_index: u16) void {1021pub fn markDirty(self: *Elf, shdr_index: u32) void {
1022 const zig_object = self.zigObjectPtr().?;1022 const zig_object = self.zigObjectPtr().?;
1023 if (zig_object.dwarf) |_| {1023 if (zig_object.dwarf) |_| {
1024 if (self.debug_info_section_index.? == shdr_index) {1024 if (self.debug_info_section_index.? == shdr_index) {
...@@ -2969,7 +2969,7 @@ pub fn writeElfHeader(self: *Elf) !void {...@@ -2969,7 +2969,7 @@ pub fn writeElfHeader(self: *Elf) !void {
2969 mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian);2969 mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian);
2970 index += 2;2970 index += 2;
29712971
2972 mem.writeInt(u16, hdr_buf[index..][0..2], self.shstrtab_section_index.?, endian);2972 mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.shstrtab_section_index.?), endian);
2973 index += 2;2973 index += 2;
29742974
2975 assert(index == e_ehsize);2975 assert(index == e_ehsize);
...@@ -3709,7 +3709,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void {...@@ -3709,7 +3709,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void {
3709 }3709 }
3710}3710}
37113711
3712fn shdrRank(self: *Elf, shndx: u16) u8 {3712fn shdrRank(self: *Elf, shndx: u32) u8 {
3713 const shdr = self.shdrs.items[shndx];3713 const shdr = self.shdrs.items[shndx];
3714 const name = self.getShString(shdr.sh_name);3714 const name = self.getShString(shdr.sh_name);
3715 const flags = shdr.sh_flags;3715 const flags = shdr.sh_flags;
...@@ -3759,7 +3759,7 @@ fn shdrRank(self: *Elf, shndx: u16) u8 {...@@ -3759,7 +3759,7 @@ fn shdrRank(self: *Elf, shndx: u16) u8 {
37593759
3760pub fn sortShdrs(self: *Elf) !void {3760pub fn sortShdrs(self: *Elf) !void {
3761 const Entry = struct {3761 const Entry = struct {
3762 shndx: u16,3762 shndx: u32,
37633763
3764 pub fn lessThan(elf_file: *Elf, lhs: @This(), rhs: @This()) bool {3764 pub fn lessThan(elf_file: *Elf, lhs: @This(), rhs: @This()) bool {
3765 return elf_file.shdrRank(lhs.shndx) < elf_file.shdrRank(rhs.shndx);3765 return elf_file.shdrRank(lhs.shndx) < elf_file.shdrRank(rhs.shndx);
...@@ -3770,15 +3770,15 @@ pub fn sortShdrs(self: *Elf) !void {...@@ -3770,15 +3770,15 @@ pub fn sortShdrs(self: *Elf) !void {
3770 var entries = try std.ArrayList(Entry).initCapacity(gpa, self.shdrs.items.len);3770 var entries = try std.ArrayList(Entry).initCapacity(gpa, self.shdrs.items.len);
3771 defer entries.deinit();3771 defer entries.deinit();
3772 for (0..self.shdrs.items.len) |shndx| {3772 for (0..self.shdrs.items.len) |shndx| {
3773 entries.appendAssumeCapacity(.{ .shndx = @as(u16, @intCast(shndx)) });3773 entries.appendAssumeCapacity(.{ .shndx = @intCast(shndx) });
3774 }3774 }
37753775
3776 mem.sort(Entry, entries.items, self, Entry.lessThan);3776 mem.sort(Entry, entries.items, self, Entry.lessThan);
37773777
3778 const backlinks = try gpa.alloc(u16, entries.items.len);3778 const backlinks = try gpa.alloc(u32, entries.items.len);
3779 defer gpa.free(backlinks);3779 defer gpa.free(backlinks);
3780 for (entries.items, 0..) |entry, i| {3780 for (entries.items, 0..) |entry, i| {
3781 backlinks[entry.shndx] = @as(u16, @intCast(i));3781 backlinks[entry.shndx] = @intCast(i);
3782 }3782 }
37833783
3784 const slice = try self.shdrs.toOwnedSlice(gpa);3784 const slice = try self.shdrs.toOwnedSlice(gpa);
...@@ -3792,10 +3792,10 @@ pub fn sortShdrs(self: *Elf) !void {...@@ -3792,10 +3792,10 @@ pub fn sortShdrs(self: *Elf) !void {
3792 try self.resetShdrIndexes(backlinks);3792 try self.resetShdrIndexes(backlinks);
3793}3793}
37943794
3795fn resetShdrIndexes(self: *Elf, backlinks: []const u16) !void {3795fn resetShdrIndexes(self: *Elf, backlinks: []const u32) !void {
3796 const gpa = self.base.comp.gpa;3796 const gpa = self.base.comp.gpa;
37973797
3798 for (&[_]*?u16{3798 for (&[_]*?u32{
3799 &self.eh_frame_section_index,3799 &self.eh_frame_section_index,
3800 &self.eh_frame_rela_section_index,3800 &self.eh_frame_rela_section_index,
3801 &self.eh_frame_hdr_section_index,3801 &self.eh_frame_hdr_section_index,
...@@ -4191,7 +4191,7 @@ pub fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {...@@ -4191,7 +4191,7 @@ pub fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void {
4191 // virtual and file offsets. However, the simple one will do for one4191 // virtual and file offsets. However, the simple one will do for one
4192 // as we are more interested in quick turnaround and compatibility4192 // as we are more interested in quick turnaround and compatibility
4193 // with `findFreeSpace` mechanics than anything else.4193 // with `findFreeSpace` mechanics than anything else.
4194 const Cover = std.ArrayList(u16);4194 const Cover = std.ArrayList(u32);
4195 const gpa = self.base.comp.gpa;4195 const gpa = self.base.comp.gpa;
4196 var covers: [max_number_of_object_segments]Cover = undefined;4196 var covers: [max_number_of_object_segments]Cover = undefined;
4197 for (&covers) |*cover| {4197 for (&covers) |*cover| {
...@@ -4347,7 +4347,7 @@ pub fn allocateNonAllocSections(self: *Elf) !void {...@@ -4347,7 +4347,7 @@ pub fn allocateNonAllocSections(self: *Elf) !void {
4347}4347}
43484348
4349fn allocateSpecialPhdrs(self: *Elf) void {4349fn allocateSpecialPhdrs(self: *Elf) void {
4350 for (&[_]struct { ?u16, ?u16 }{4350 for (&[_]struct { ?u16, ?u32 }{
4351 .{ self.phdr_interp_index, self.interp_section_index },4351 .{ self.phdr_interp_index, self.interp_section_index },
4352 .{ self.phdr_dynamic_index, self.dynamic_section_index },4352 .{ self.phdr_dynamic_index, self.dynamic_section_index },
4353 .{ self.phdr_gnu_eh_frame_index, self.eh_frame_hdr_section_index },4353 .{ self.phdr_gnu_eh_frame_index, self.eh_frame_hdr_section_index },
...@@ -4370,7 +4370,7 @@ fn allocateSpecialPhdrs(self: *Elf) void {...@@ -4370,7 +4370,7 @@ fn allocateSpecialPhdrs(self: *Elf) void {
4370 if (self.phdr_tls_index) |index| {4370 if (self.phdr_tls_index) |index| {
4371 const slice = self.shdrs.items;4371 const slice = self.shdrs.items;
4372 const phdr = &self.phdrs.items[index];4372 const phdr = &self.phdrs.items[index];
4373 var shndx: u16 = 0;4373 var shndx: u32 = 0;
4374 while (shndx < slice.len) {4374 while (shndx < slice.len) {
4375 const shdr = slice[shndx];4375 const shdr = slice[shndx];
4376 if (shdr.sh_flags & elf.SHF_TLS == 0) {4376 if (shdr.sh_flags & elf.SHF_TLS == 0) {
...@@ -5138,8 +5138,8 @@ const CsuObjects = struct {...@@ -5138,8 +5138,8 @@ const CsuObjects = struct {
5138 }5138 }
5139};5139};
51405140
5141pub fn isZigSection(self: Elf, shndx: u16) bool {5141pub fn isZigSection(self: Elf, shndx: u32) bool {
5142 inline for (&[_]?u16{5142 inline for (&[_]?u32{
5143 self.zig_text_section_index,5143 self.zig_text_section_index,
5144 self.zig_data_rel_ro_section_index,5144 self.zig_data_rel_ro_section_index,
5145 self.zig_data_section_index,5145 self.zig_data_section_index,
...@@ -5153,8 +5153,8 @@ pub fn isZigSection(self: Elf, shndx: u16) bool {...@@ -5153,8 +5153,8 @@ pub fn isZigSection(self: Elf, shndx: u16) bool {
5153 return false;5153 return false;
5154}5154}
51555155
5156pub fn isDebugSection(self: Elf, shndx: u16) bool {5156pub fn isDebugSection(self: Elf, shndx: u32) bool {
5157 inline for (&[_]?u16{5157 inline for (&[_]?u32{
5158 self.debug_info_section_index,5158 self.debug_info_section_index,
5159 self.debug_abbrev_section_index,5159 self.debug_abbrev_section_index,
5160 self.debug_str_section_index,5160 self.debug_str_section_index,
...@@ -5192,7 +5192,7 @@ fn addPhdr(self: *Elf, opts: struct {...@@ -5192,7 +5192,7 @@ fn addPhdr(self: *Elf, opts: struct {
5192 return index;5192 return index;
5193}5193}
51945194
5195pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u16) !u16 {5195pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u32) !u32 {
5196 const entsize: u64 = switch (self.ptr_width) {5196 const entsize: u64 = switch (self.ptr_width) {
5197 .p32 => @sizeOf(elf.Elf32_Rela),5197 .p32 => @sizeOf(elf.Elf32_Rela),
5198 .p64 => @sizeOf(elf.Elf64_Rela),5198 .p64 => @sizeOf(elf.Elf64_Rela),
...@@ -5223,9 +5223,9 @@ pub const AddSectionOpts = struct {...@@ -5223,9 +5223,9 @@ pub const AddSectionOpts = struct {
5223 offset: u64 = 0,5223 offset: u64 = 0,
5224};5224};
52255225
5226pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 {5226pub fn addSection(self: *Elf, opts: AddSectionOpts) !u32 {
5227 const gpa = self.base.comp.gpa;5227 const gpa = self.base.comp.gpa;
5228 const index = @as(u16, @intCast(self.shdrs.items.len));5228 const index = @as(u32, @intCast(self.shdrs.items.len));
5229 const shdr = try self.shdrs.addOne(gpa);5229 const shdr = try self.shdrs.addOne(gpa);
5230 shdr.* = .{5230 shdr.* = .{
5231 .sh_name = try self.insertShString(opts.name),5231 .sh_name = try self.insertShString(opts.name),
...@@ -5242,10 +5242,10 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 {...@@ -5242,10 +5242,10 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 {
5242 return index;5242 return index;
5243}5243}
52445244
5245pub fn sectionByName(self: *Elf, name: [:0]const u8) ?u16 {5245pub fn sectionByName(self: *Elf, name: [:0]const u8) ?u32 {
5246 for (self.shdrs.items, 0..) |*shdr, i| {5246 for (self.shdrs.items, 0..) |*shdr, i| {
5247 const this_name = self.getShString(shdr.sh_name);5247 const this_name = self.getShString(shdr.sh_name);
5248 if (mem.eql(u8, this_name, name)) return @as(u16, @intCast(i));5248 if (mem.eql(u8, this_name, name)) return @intCast(i);
5249 } else return null;5249 } else return null;
5250}5250}
52515251
src/link/Elf/Atom.zig+2-2
...@@ -17,7 +17,7 @@ alignment: Alignment = .@"1",...@@ -17,7 +17,7 @@ alignment: Alignment = .@"1",
17input_section_index: u32 = 0,17input_section_index: u32 = 0,
1818
19/// Index of the output section.19/// Index of the output section.
20output_section_index: u16 = 0,20output_section_index: u32 = 0,
2121
22/// Index of the input section containing this atom's relocs.22/// Index of the input section containing this atom's relocs.
23relocs_section_index: u32 = 0,23relocs_section_index: u32 = 0,
...@@ -77,7 +77,7 @@ pub fn relocsShndx(self: Atom) ?u32 {...@@ -77,7 +77,7 @@ pub fn relocsShndx(self: Atom) ?u32 {
77 return self.relocs_section_index;77 return self.relocs_section_index;
78}78}
7979
80pub fn outputShndx(self: Atom) ?u16 {80pub fn outputShndx(self: Atom) ?u32 {
81 if (self.output_section_index == 0) return null;81 if (self.output_section_index == 0) return null;
82 return self.output_section_index;82 return self.output_section_index;
83}83}
src/link/Elf/Object.zig+5-5
...@@ -126,7 +126,7 @@ fn parseCommon(self: *Object, allocator: Allocator, handle: std.fs.File, elf_fil...@@ -126,7 +126,7 @@ fn parseCommon(self: *Object, allocator: Allocator, handle: std.fs.File, elf_fil
126 try self.strtab.appendSlice(allocator, shstrtab);126 try self.strtab.appendSlice(allocator, shstrtab);
127127
128 const symtab_index = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) {128 const symtab_index = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) {
129 elf.SHT_SYMTAB => break @as(u16, @intCast(i)),129 elf.SHT_SYMTAB => break @as(u32, @intCast(i)),
130 else => {},130 else => {},
131 } else null;131 } else null;
132132
...@@ -223,7 +223,7 @@ fn initAtoms(self: *Object, allocator: Allocator, handle: std.fs.File, elf_file:...@@ -223,7 +223,7 @@ fn initAtoms(self: *Object, allocator: Allocator, handle: std.fs.File, elf_file:
223 => {},223 => {},
224224
225 else => {225 else => {
226 const shndx = @as(u16, @intCast(i));226 const shndx = @as(u32, @intCast(i));
227 if (self.skipShdr(shndx, elf_file)) continue;227 if (self.skipShdr(shndx, elf_file)) continue;
228 try self.addAtom(allocator, handle, shdr, shndx, elf_file);228 try self.addAtom(allocator, handle, shdr, shndx, elf_file);
229 },229 },
...@@ -268,7 +268,7 @@ fn addAtom(self: *Object, allocator: Allocator, handle: std.fs.File, shdr: elf.E...@@ -268,7 +268,7 @@ fn addAtom(self: *Object, allocator: Allocator, handle: std.fs.File, shdr: elf.E
268 }268 }
269}269}
270270
271fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{OutOfMemory}!u16 {271fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{OutOfMemory}!u32 {
272 const name = blk: {272 const name = blk: {
273 const name = self.getString(shdr.sh_name);273 const name = self.getString(shdr.sh_name);
274 if (elf_file.base.isRelocatable()) break :blk name;274 if (elf_file.base.isRelocatable()) break :blk name;
...@@ -316,7 +316,7 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{O...@@ -316,7 +316,7 @@ fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{O
316 return out_shndx;316 return out_shndx;
317}317}
318318
319fn skipShdr(self: *Object, index: u16, elf_file: *Elf) bool {319fn skipShdr(self: *Object, index: u32, elf_file: *Elf) bool {
320 const comp = elf_file.base.comp;320 const comp = elf_file.base.comp;
321 const shdr = self.shdrs.items[index];321 const shdr = self.shdrs.items[index];
322 const name = self.getString(shdr.sh_name);322 const name = self.getString(shdr.sh_name);
...@@ -673,7 +673,7 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {...@@ -673,7 +673,7 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {
673673
674 var sh_flags: u32 = elf.SHF_ALLOC | elf.SHF_WRITE;674 var sh_flags: u32 = elf.SHF_ALLOC | elf.SHF_WRITE;
675 if (is_tls) sh_flags |= elf.SHF_TLS;675 if (is_tls) sh_flags |= elf.SHF_TLS;
676 const shndx = @as(u16, @intCast(self.shdrs.items.len));676 const shndx = @as(u32, @intCast(self.shdrs.items.len));
677 const shdr = try self.shdrs.addOne(gpa);677 const shdr = try self.shdrs.addOne(gpa);
678 const sh_size = math.cast(usize, this_sym.st_size) orelse return error.Overflow;678 const sh_size = math.cast(usize, this_sym.st_size) orelse return error.Overflow;
679 shdr.* = .{679 shdr.* = .{
src/link/Elf/Symbol.zig+5-5
...@@ -15,7 +15,7 @@ file_index: File.Index = 0,...@@ -15,7 +15,7 @@ file_index: File.Index = 0,
15atom_index: Atom.Index = 0,15atom_index: Atom.Index = 0,
1616
17/// Assigned output section index for this atom.17/// Assigned output section index for this atom.
18output_section_index: u16 = 0,18output_section_index: u32 = 0,
1919
20/// Index of the source symbol this symbol references.20/// Index of the source symbol this symbol references.
21/// Use `elfSym` to pull the source symbol from the relevant file.21/// Use `elfSym` to pull the source symbol from the relevant file.
...@@ -37,7 +37,7 @@ pub fn isAbs(symbol: Symbol, elf_file: *Elf) bool {...@@ -37,7 +37,7 @@ pub fn isAbs(symbol: Symbol, elf_file: *Elf) bool {
37 file_ptr != .linker_defined;37 file_ptr != .linker_defined;
38}38}
3939
40pub fn outputShndx(symbol: Symbol) ?u16 {40pub fn outputShndx(symbol: Symbol) ?u32 {
41 if (symbol.output_section_index == 0) return null;41 if (symbol.output_section_index == 0) return null;
42 return symbol.output_section_index;42 return symbol.output_section_index;
43}43}
...@@ -237,12 +237,12 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {...@@ -237,12 +237,12 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void {
237 if (file_ptr == .shared_object) break :blk elf.STB_GLOBAL;237 if (file_ptr == .shared_object) break :blk elf.STB_GLOBAL;
238 break :blk esym.st_bind();238 break :blk esym.st_bind();
239 };239 };
240 const st_shndx = blk: {240 const st_shndx: u16 = blk: {
241 if (symbol.flags.has_copy_rel) break :blk elf_file.copy_rel_section_index.?;241 if (symbol.flags.has_copy_rel) break :blk @intCast(elf_file.copy_rel_section_index.?);
242 if (file_ptr == .shared_object or esym.st_shndx == elf.SHN_UNDEF) break :blk elf.SHN_UNDEF;242 if (file_ptr == .shared_object or esym.st_shndx == elf.SHN_UNDEF) break :blk elf.SHN_UNDEF;
243 if (elf_file.base.isRelocatable() and esym.st_shndx == elf.SHN_COMMON) break :blk elf.SHN_COMMON;243 if (elf_file.base.isRelocatable() and esym.st_shndx == elf.SHN_COMMON) break :blk elf.SHN_COMMON;
244 if (symbol.atom(elf_file) == null and file_ptr != .linker_defined) break :blk elf.SHN_ABS;244 if (symbol.atom(elf_file) == null and file_ptr != .linker_defined) break :blk elf.SHN_ABS;
245 break :blk symbol.outputShndx() orelse elf.SHN_UNDEF;245 break :blk @intCast(symbol.outputShndx() orelse elf.SHN_UNDEF);
246 };246 };
247 const st_value = blk: {247 const st_value = blk: {
248 if (symbol.flags.has_copy_rel) break :blk symbol.address(.{}, elf_file);248 if (symbol.flags.has_copy_rel) break :blk symbol.address(.{}, elf_file);
src/link/Elf/ZigObject.zig+4-4
...@@ -840,7 +840,7 @@ fn getDeclShdrIndex(...@@ -840,7 +840,7 @@ fn getDeclShdrIndex(
840 elf_file: *Elf,840 elf_file: *Elf,
841 decl: *const Module.Decl,841 decl: *const Module.Decl,
842 code: []const u8,842 code: []const u8,
843) error{OutOfMemory}!u16 {843) error{OutOfMemory}!u32 {
844 _ = self;844 _ = self;
845 const mod = elf_file.base.comp.module.?;845 const mod = elf_file.base.comp.module.?;
846 const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;846 const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;
...@@ -894,7 +894,7 @@ fn updateDeclCode(...@@ -894,7 +894,7 @@ fn updateDeclCode(
894 elf_file: *Elf,894 elf_file: *Elf,
895 decl_index: InternPool.DeclIndex,895 decl_index: InternPool.DeclIndex,
896 sym_index: Symbol.Index,896 sym_index: Symbol.Index,
897 shdr_index: u16,897 shdr_index: u32,
898 code: []const u8,898 code: []const u8,
899 stt_bits: u8,899 stt_bits: u8,
900) !void {900) !void {
...@@ -993,7 +993,7 @@ fn updateTlv(...@@ -993,7 +993,7 @@ fn updateTlv(
993 elf_file: *Elf,993 elf_file: *Elf,
994 decl_index: InternPool.DeclIndex,994 decl_index: InternPool.DeclIndex,
995 sym_index: Symbol.Index,995 sym_index: Symbol.Index,
996 shndx: u16,996 shndx: u32,
997 code: []const u8,997 code: []const u8,
998) !void {998) !void {
999 const gpa = elf_file.base.comp.gpa;999 const gpa = elf_file.base.comp.gpa;
...@@ -1334,7 +1334,7 @@ fn lowerConst(...@@ -1334,7 +1334,7 @@ fn lowerConst(
1334 name: []const u8,1334 name: []const u8,
1335 tv: TypedValue,1335 tv: TypedValue,
1336 required_alignment: InternPool.Alignment,1336 required_alignment: InternPool.Alignment,
1337 output_section_index: u16,1337 output_section_index: u32,
1338 src_loc: Module.SrcLoc,1338 src_loc: Module.SrcLoc,
1339) !LowerConstResult {1339) !LowerConstResult {
1340 const gpa = elf_file.base.comp.gpa;1340 const gpa = elf_file.base.comp.gpa;
src/link/Elf/synthetic_sections.zig+5-5
...@@ -388,7 +388,7 @@ pub const ZigGotSection = struct {...@@ -388,7 +388,7 @@ pub const ZigGotSection = struct {
388 .st_name = st_name,388 .st_name = st_name,
389 .st_info = elf.STT_OBJECT,389 .st_info = elf.STT_OBJECT,
390 .st_other = 0,390 .st_other = 0,
391 .st_shndx = elf_file.zig_got_section_index.?,391 .st_shndx = @intCast(elf_file.zig_got_section_index.?),
392 .st_value = st_value,392 .st_value = st_value,
393 .st_size = st_size,393 .st_size = st_size,
394 };394 };
...@@ -813,7 +813,7 @@ pub const GotSection = struct {...@@ -813,7 +813,7 @@ pub const GotSection = struct {
813 .st_name = st_name,813 .st_name = st_name,
814 .st_info = elf.STT_OBJECT,814 .st_info = elf.STT_OBJECT,
815 .st_other = 0,815 .st_other = 0,
816 .st_shndx = elf_file.got_section_index.?,816 .st_shndx = @intCast(elf_file.got_section_index.?),
817 .st_value = st_value,817 .st_value = st_value,
818 .st_size = st_size,818 .st_size = st_size,
819 };819 };
...@@ -953,7 +953,7 @@ pub const PltSection = struct {...@@ -953,7 +953,7 @@ pub const PltSection = struct {
953 .st_name = st_name,953 .st_name = st_name,
954 .st_info = elf.STT_FUNC,954 .st_info = elf.STT_FUNC,
955 .st_other = 0,955 .st_other = 0,
956 .st_shndx = elf_file.plt_section_index.?,956 .st_shndx = @intCast(elf_file.plt_section_index.?),
957 .st_value = sym.pltAddress(elf_file),957 .st_value = sym.pltAddress(elf_file),
958 .st_size = 16,958 .st_size = 16,
959 };959 };
...@@ -1082,7 +1082,7 @@ pub const PltGotSection = struct {...@@ -1082,7 +1082,7 @@ pub const PltGotSection = struct {
1082 .st_name = st_name,1082 .st_name = st_name,
1083 .st_info = elf.STT_FUNC,1083 .st_info = elf.STT_FUNC,
1084 .st_other = 0,1084 .st_other = 0,
1085 .st_shndx = elf_file.plt_got_section_index.?,1085 .st_shndx = @intCast(elf_file.plt_got_section_index.?),
1086 .st_value = sym.pltGotAddress(elf_file),1086 .st_value = sym.pltGotAddress(elf_file),
1087 .st_size = 16,1087 .st_size = 16,
1088 };1088 };
...@@ -1132,7 +1132,7 @@ pub const CopyRelSection = struct {...@@ -1132,7 +1132,7 @@ pub const CopyRelSection = struct {
1132 }1132 }
1133 }1133 }
11341134
1135 pub fn updateSectionSize(copy_rel: CopyRelSection, shndx: u16, elf_file: *Elf) !void {1135 pub fn updateSectionSize(copy_rel: CopyRelSection, shndx: u32, elf_file: *Elf) !void {
1136 const shdr = &elf_file.shdrs.items[shndx];1136 const shdr = &elf_file.shdrs.items[shndx];
1137 for (copy_rel.symbols.items) |sym_index| {1137 for (copy_rel.symbols.items) |sym_index| {
1138 const symbol = elf_file.symbol(sym_index);1138 const symbol = elf_file.symbol(sym_index);