| ... | ... | @@ -138,40 +138,40 @@ comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .{}, |
| 138 | 138 | |
| 139 | 139 | /// Tracked section headers with incremental updates to Zig object. |
| 140 | 140 | /// .rela.* sections are only used when emitting a relocatable object file. |
| 141 | | zig_text_section_index: ?u16 = null, |
| 142 | | zig_data_rel_ro_section_index: ?u16 = null, |
| 143 | | zig_data_section_index: ?u16 = null, |
| 144 | | zig_bss_section_index: ?u16 = null, |
| 145 | | zig_got_section_index: ?u16 = null, |
| 146 | | |
| 147 | | debug_info_section_index: ?u16 = null, |
| 148 | | debug_abbrev_section_index: ?u16 = null, |
| 149 | | debug_str_section_index: ?u16 = null, |
| 150 | | debug_aranges_section_index: ?u16 = null, |
| 151 | | debug_line_section_index: ?u16 = null, |
| 152 | | |
| 153 | | copy_rel_section_index: ?u16 = null, |
| 154 | | dynamic_section_index: ?u16 = null, |
| 155 | | dynstrtab_section_index: ?u16 = null, |
| 156 | | dynsymtab_section_index: ?u16 = null, |
| 157 | | eh_frame_section_index: ?u16 = null, |
| 158 | | eh_frame_rela_section_index: ?u16 = null, |
| 159 | | eh_frame_hdr_section_index: ?u16 = null, |
| 160 | | hash_section_index: ?u16 = null, |
| 161 | | gnu_hash_section_index: ?u16 = null, |
| 162 | | got_section_index: ?u16 = null, |
| 163 | | got_plt_section_index: ?u16 = null, |
| 164 | | interp_section_index: ?u16 = null, |
| 165 | | plt_section_index: ?u16 = null, |
| 166 | | plt_got_section_index: ?u16 = null, |
| 167 | | rela_dyn_section_index: ?u16 = null, |
| 168 | | rela_plt_section_index: ?u16 = null, |
| 169 | | versym_section_index: ?u16 = null, |
| 170 | | verneed_section_index: ?u16 = null, |
| 171 | | |
| 172 | | shstrtab_section_index: ?u16 = null, |
| 173 | | strtab_section_index: ?u16 = null, |
| 174 | | symtab_section_index: ?u16 = null, |
| 141 | zig_text_section_index: ?u32 = null, |
| 142 | zig_data_rel_ro_section_index: ?u32 = null, |
| 143 | zig_data_section_index: ?u32 = null, |
| 144 | zig_bss_section_index: ?u32 = null, |
| 145 | zig_got_section_index: ?u32 = null, |
| 146 | |
| 147 | debug_info_section_index: ?u32 = null, |
| 148 | debug_abbrev_section_index: ?u32 = null, |
| 149 | debug_str_section_index: ?u32 = null, |
| 150 | debug_aranges_section_index: ?u32 = null, |
| 151 | debug_line_section_index: ?u32 = null, |
| 152 | |
| 153 | copy_rel_section_index: ?u32 = null, |
| 154 | dynamic_section_index: ?u32 = null, |
| 155 | dynstrtab_section_index: ?u32 = null, |
| 156 | dynsymtab_section_index: ?u32 = null, |
| 157 | eh_frame_section_index: ?u32 = null, |
| 158 | eh_frame_rela_section_index: ?u32 = null, |
| 159 | eh_frame_hdr_section_index: ?u32 = null, |
| 160 | hash_section_index: ?u32 = null, |
| 161 | gnu_hash_section_index: ?u32 = null, |
| 162 | got_section_index: ?u32 = null, |
| 163 | got_plt_section_index: ?u32 = null, |
| 164 | interp_section_index: ?u32 = null, |
| 165 | plt_section_index: ?u32 = null, |
| 166 | plt_got_section_index: ?u32 = null, |
| 167 | rela_dyn_section_index: ?u32 = null, |
| 168 | rela_plt_section_index: ?u32 = null, |
| 169 | versym_section_index: ?u32 = null, |
| 170 | verneed_section_index: ?u32 = null, |
| 171 | |
| 172 | shstrtab_section_index: ?u32 = null, |
| 173 | strtab_section_index: ?u32 = null, |
| 174 | symtab_section_index: ?u32 = null, |
| 175 | 175 | |
| 176 | 176 | // Linker-defined symbols |
| 177 | 177 | dynamic_index: ?Symbol.Index = null, |
| ... | ... | @@ -931,7 +931,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 931 | 931 | try self.base.file.?.pwriteAll(&[1]u8{0}, end_pos); |
| 932 | 932 | } |
| 933 | 933 | |
| 934 | | pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void { |
| 934 | pub fn growAllocSection(self: *Elf, shdr_index: u32, needed_size: u64) !void { |
| 935 | 935 | const shdr = &self.shdrs.items[shdr_index]; |
| 936 | 936 | const maybe_phdr = if (self.phdr_to_shdr_table.get(shdr_index)) |phndx| &self.phdrs.items[phndx] else null; |
| 937 | 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 | 981 | |
| 982 | 982 | pub fn growNonAllocSection( |
| 983 | 983 | self: *Elf, |
| 984 | | shdr_index: u16, |
| 984 | shdr_index: u32, |
| 985 | 985 | needed_size: u64, |
| 986 | 986 | min_alignment: u32, |
| 987 | 987 | requires_file_copy: bool, |
| ... | ... | @@ -1018,7 +1018,7 @@ pub fn growNonAllocSection( |
| 1018 | 1018 | self.markDirty(shdr_index); |
| 1019 | 1019 | } |
| 1020 | 1020 | |
| 1021 | | pub fn markDirty(self: *Elf, shdr_index: u16) void { |
| 1021 | pub fn markDirty(self: *Elf, shdr_index: u32) void { |
| 1022 | 1022 | const zig_object = self.zigObjectPtr().?; |
| 1023 | 1023 | if (zig_object.dwarf) |_| { |
| 1024 | 1024 | if (self.debug_info_section_index.? == shdr_index) { |
| ... | ... | @@ -2969,7 +2969,7 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 2969 | 2969 | mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian); |
| 2970 | 2970 | index += 2; |
| 2971 | 2971 | |
| 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 | 2973 | index += 2; |
| 2974 | 2974 | |
| 2975 | 2975 | assert(index == e_ehsize); |
| ... | ... | @@ -3709,7 +3709,7 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void { |
| 3709 | 3709 | } |
| 3710 | 3710 | } |
| 3711 | 3711 | |
| 3712 | | fn shdrRank(self: *Elf, shndx: u16) u8 { |
| 3712 | fn shdrRank(self: *Elf, shndx: u32) u8 { |
| 3713 | 3713 | const shdr = self.shdrs.items[shndx]; |
| 3714 | 3714 | const name = self.getShString(shdr.sh_name); |
| 3715 | 3715 | const flags = shdr.sh_flags; |
| ... | ... | @@ -3759,7 +3759,7 @@ fn shdrRank(self: *Elf, shndx: u16) u8 { |
| 3759 | 3759 | |
| 3760 | 3760 | pub fn sortShdrs(self: *Elf) !void { |
| 3761 | 3761 | const Entry = struct { |
| 3762 | | shndx: u16, |
| 3762 | shndx: u32, |
| 3763 | 3763 | |
| 3764 | 3764 | pub fn lessThan(elf_file: *Elf, lhs: @This(), rhs: @This()) bool { |
| 3765 | 3765 | return elf_file.shdrRank(lhs.shndx) < elf_file.shdrRank(rhs.shndx); |
| ... | ... | @@ -3770,15 +3770,15 @@ pub fn sortShdrs(self: *Elf) !void { |
| 3770 | 3770 | var entries = try std.ArrayList(Entry).initCapacity(gpa, self.shdrs.items.len); |
| 3771 | 3771 | defer entries.deinit(); |
| 3772 | 3772 | for (0..self.shdrs.items.len) |shndx| { |
| 3773 | | entries.appendAssumeCapacity(.{ .shndx = @as(u16, @intCast(shndx)) }); |
| 3773 | entries.appendAssumeCapacity(.{ .shndx = @intCast(shndx) }); |
| 3774 | 3774 | } |
| 3775 | 3775 | |
| 3776 | 3776 | mem.sort(Entry, entries.items, self, Entry.lessThan); |
| 3777 | 3777 | |
| 3778 | | const backlinks = try gpa.alloc(u16, entries.items.len); |
| 3778 | const backlinks = try gpa.alloc(u32, entries.items.len); |
| 3779 | 3779 | defer gpa.free(backlinks); |
| 3780 | 3780 | for (entries.items, 0..) |entry, i| { |
| 3781 | | backlinks[entry.shndx] = @as(u16, @intCast(i)); |
| 3781 | backlinks[entry.shndx] = @intCast(i); |
| 3782 | 3782 | } |
| 3783 | 3783 | |
| 3784 | 3784 | const slice = try self.shdrs.toOwnedSlice(gpa); |
| ... | ... | @@ -3792,10 +3792,10 @@ pub fn sortShdrs(self: *Elf) !void { |
| 3792 | 3792 | try self.resetShdrIndexes(backlinks); |
| 3793 | 3793 | } |
| 3794 | 3794 | |
| 3795 | | fn resetShdrIndexes(self: *Elf, backlinks: []const u16) !void { |
| 3795 | fn resetShdrIndexes(self: *Elf, backlinks: []const u32) !void { |
| 3796 | 3796 | const gpa = self.base.comp.gpa; |
| 3797 | 3797 | |
| 3798 | | for (&[_]*?u16{ |
| 3798 | for (&[_]*?u32{ |
| 3799 | 3799 | &self.eh_frame_section_index, |
| 3800 | 3800 | &self.eh_frame_rela_section_index, |
| 3801 | 3801 | &self.eh_frame_hdr_section_index, |
| ... | ... | @@ -4191,7 +4191,7 @@ pub fn allocateAllocSections(self: *Elf) error{OutOfMemory}!void { |
| 4191 | 4191 | // virtual and file offsets. However, the simple one will do for one |
| 4192 | 4192 | // as we are more interested in quick turnaround and compatibility |
| 4193 | 4193 | // with `findFreeSpace` mechanics than anything else. |
| 4194 | | const Cover = std.ArrayList(u16); |
| 4194 | const Cover = std.ArrayList(u32); |
| 4195 | 4195 | const gpa = self.base.comp.gpa; |
| 4196 | 4196 | var covers: [max_number_of_object_segments]Cover = undefined; |
| 4197 | 4197 | for (&covers) |*cover| { |
| ... | ... | @@ -4347,7 +4347,7 @@ pub fn allocateNonAllocSections(self: *Elf) !void { |
| 4347 | 4347 | } |
| 4348 | 4348 | |
| 4349 | 4349 | fn allocateSpecialPhdrs(self: *Elf) void { |
| 4350 | | for (&[_]struct { ?u16, ?u16 }{ |
| 4350 | for (&[_]struct { ?u16, ?u32 }{ |
| 4351 | 4351 | .{ self.phdr_interp_index, self.interp_section_index }, |
| 4352 | 4352 | .{ self.phdr_dynamic_index, self.dynamic_section_index }, |
| 4353 | 4353 | .{ self.phdr_gnu_eh_frame_index, self.eh_frame_hdr_section_index }, |
| ... | ... | @@ -4370,7 +4370,7 @@ fn allocateSpecialPhdrs(self: *Elf) void { |
| 4370 | 4370 | if (self.phdr_tls_index) |index| { |
| 4371 | 4371 | const slice = self.shdrs.items; |
| 4372 | 4372 | const phdr = &self.phdrs.items[index]; |
| 4373 | | var shndx: u16 = 0; |
| 4373 | var shndx: u32 = 0; |
| 4374 | 4374 | while (shndx < slice.len) { |
| 4375 | 4375 | const shdr = slice[shndx]; |
| 4376 | 4376 | if (shdr.sh_flags & elf.SHF_TLS == 0) { |
| ... | ... | @@ -5138,8 +5138,8 @@ const CsuObjects = struct { |
| 5138 | 5138 | } |
| 5139 | 5139 | }; |
| 5140 | 5140 | |
| 5141 | | pub fn isZigSection(self: Elf, shndx: u16) bool { |
| 5142 | | inline for (&[_]?u16{ |
| 5141 | pub fn isZigSection(self: Elf, shndx: u32) bool { |
| 5142 | inline for (&[_]?u32{ |
| 5143 | 5143 | self.zig_text_section_index, |
| 5144 | 5144 | self.zig_data_rel_ro_section_index, |
| 5145 | 5145 | self.zig_data_section_index, |
| ... | ... | @@ -5153,8 +5153,8 @@ pub fn isZigSection(self: Elf, shndx: u16) bool { |
| 5153 | 5153 | return false; |
| 5154 | 5154 | } |
| 5155 | 5155 | |
| 5156 | | pub fn isDebugSection(self: Elf, shndx: u16) bool { |
| 5157 | | inline for (&[_]?u16{ |
| 5156 | pub fn isDebugSection(self: Elf, shndx: u32) bool { |
| 5157 | inline for (&[_]?u32{ |
| 5158 | 5158 | self.debug_info_section_index, |
| 5159 | 5159 | self.debug_abbrev_section_index, |
| 5160 | 5160 | self.debug_str_section_index, |
| ... | ... | @@ -5192,7 +5192,7 @@ fn addPhdr(self: *Elf, opts: struct { |
| 5192 | 5192 | return index; |
| 5193 | 5193 | } |
| 5194 | 5194 | |
| 5195 | | pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u16) !u16 { |
| 5195 | pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u32) !u32 { |
| 5196 | 5196 | const entsize: u64 = switch (self.ptr_width) { |
| 5197 | 5197 | .p32 => @sizeOf(elf.Elf32_Rela), |
| 5198 | 5198 | .p64 => @sizeOf(elf.Elf64_Rela), |
| ... | ... | @@ -5223,9 +5223,9 @@ pub const AddSectionOpts = struct { |
| 5223 | 5223 | offset: u64 = 0, |
| 5224 | 5224 | }; |
| 5225 | 5225 | |
| 5226 | | pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 { |
| 5226 | pub fn addSection(self: *Elf, opts: AddSectionOpts) !u32 { |
| 5227 | 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 | 5229 | const shdr = try self.shdrs.addOne(gpa); |
| 5230 | 5230 | shdr.* = .{ |
| 5231 | 5231 | .sh_name = try self.insertShString(opts.name), |
| ... | ... | @@ -5242,10 +5242,10 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u16 { |
| 5242 | 5242 | return index; |
| 5243 | 5243 | } |
| 5244 | 5244 | |
| 5245 | | pub fn sectionByName(self: *Elf, name: [:0]const u8) ?u16 { |
| 5245 | pub fn sectionByName(self: *Elf, name: [:0]const u8) ?u32 { |
| 5246 | 5246 | for (self.shdrs.items, 0..) |*shdr, i| { |
| 5247 | 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 | 5249 | } else return null; |
| 5250 | 5250 | } |
| 5251 | 5251 | |