diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-13 17:24:46 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-13 20:33:08 +0100 |
| commit | 216a5594f62aca7524012e0a2bbf226c4064fae4 (patch) | |
| tree | db3497aaf292af43f3dffbabfa124a678c176363 /src/link/Elf | |
| parent | e401930fa862e3b9b3eedc8eb405c501fbf3de30 (diff) | |
| download | zig-216a5594f62aca7524012e0a2bbf226c4064fae4.tar.gz zig-216a5594f62aca7524012e0a2bbf226c4064fae4.zip | |
elf: use u32 for all section indexes
Diffstat (limited to 'src/link/Elf')
| -rw-r--r-- | src/link/Elf/Atom.zig | 4 | ||||
| -rw-r--r-- | src/link/Elf/Object.zig | 10 | ||||
| -rw-r--r-- | src/link/Elf/Symbol.zig | 10 | ||||
| -rw-r--r-- | src/link/Elf/ZigObject.zig | 8 | ||||
| -rw-r--r-- | src/link/Elf/synthetic_sections.zig | 10 |
5 files changed, 21 insertions, 21 deletions
diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index b1b07e569f..330544d8bb 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -17,7 +17,7 @@ alignment: Alignment = .@"1", input_section_index: u32 = 0, /// Index of the output section. -output_section_index: u16 = 0, +output_section_index: u32 = 0, /// Index of the input section containing this atom's relocs. relocs_section_index: u32 = 0, @@ -77,7 +77,7 @@ pub fn relocsShndx(self: Atom) ?u32 { return self.relocs_section_index; } -pub fn outputShndx(self: Atom) ?u16 { +pub fn outputShndx(self: Atom) ?u32 { if (self.output_section_index == 0) return null; return self.output_section_index; } diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index 246fd9a155..395e6680a1 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -126,7 +126,7 @@ fn parseCommon(self: *Object, allocator: Allocator, handle: std.fs.File, elf_fil try self.strtab.appendSlice(allocator, shstrtab); const symtab_index = for (self.shdrs.items, 0..) |shdr, i| switch (shdr.sh_type) { - elf.SHT_SYMTAB => break @as(u16, @intCast(i)), + elf.SHT_SYMTAB => break @as(u32, @intCast(i)), else => {}, } else null; @@ -223,7 +223,7 @@ fn initAtoms(self: *Object, allocator: Allocator, handle: std.fs.File, elf_file: => {}, else => { - const shndx = @as(u16, @intCast(i)); + const shndx = @as(u32, @intCast(i)); if (self.skipShdr(shndx, elf_file)) continue; try self.addAtom(allocator, handle, shdr, shndx, elf_file); }, @@ -268,7 +268,7 @@ fn addAtom(self: *Object, allocator: Allocator, handle: std.fs.File, shdr: elf.E } } -fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{OutOfMemory}!u16 { +fn initOutputSection(self: Object, elf_file: *Elf, shdr: elf.Elf64_Shdr) error{OutOfMemory}!u32 { const name = blk: { const name = self.getString(shdr.sh_name); 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 return out_shndx; } -fn skipShdr(self: *Object, index: u16, elf_file: *Elf) bool { +fn skipShdr(self: *Object, index: u32, elf_file: *Elf) bool { const comp = elf_file.base.comp; const shdr = self.shdrs.items[index]; const name = self.getString(shdr.sh_name); @@ -673,7 +673,7 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void { var sh_flags: u32 = elf.SHF_ALLOC | elf.SHF_WRITE; if (is_tls) sh_flags |= elf.SHF_TLS; - const shndx = @as(u16, @intCast(self.shdrs.items.len)); + const shndx = @as(u32, @intCast(self.shdrs.items.len)); const shdr = try self.shdrs.addOne(gpa); const sh_size = math.cast(usize, this_sym.st_size) orelse return error.Overflow; shdr.* = .{ diff --git a/src/link/Elf/Symbol.zig b/src/link/Elf/Symbol.zig index b2eee739ed..ea1b4f4b6b 100644 --- a/src/link/Elf/Symbol.zig +++ b/src/link/Elf/Symbol.zig @@ -15,7 +15,7 @@ file_index: File.Index = 0, atom_index: Atom.Index = 0, /// Assigned output section index for this atom. -output_section_index: u16 = 0, +output_section_index: u32 = 0, /// Index of the source symbol this symbol references. /// Use `elfSym` to pull the source symbol from the relevant file. @@ -37,7 +37,7 @@ pub fn isAbs(symbol: Symbol, elf_file: *Elf) bool { file_ptr != .linker_defined; } -pub fn outputShndx(symbol: Symbol) ?u16 { +pub fn outputShndx(symbol: Symbol) ?u32 { if (symbol.output_section_index == 0) return null; return symbol.output_section_index; } @@ -237,12 +237,12 @@ pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void { if (file_ptr == .shared_object) break :blk elf.STB_GLOBAL; break :blk esym.st_bind(); }; - const st_shndx = blk: { - if (symbol.flags.has_copy_rel) break :blk elf_file.copy_rel_section_index.?; + const st_shndx: u16 = blk: { + if (symbol.flags.has_copy_rel) break :blk @intCast(elf_file.copy_rel_section_index.?); if (file_ptr == .shared_object or esym.st_shndx == elf.SHN_UNDEF) break :blk elf.SHN_UNDEF; if (elf_file.base.isRelocatable() and esym.st_shndx == elf.SHN_COMMON) break :blk elf.SHN_COMMON; if (symbol.atom(elf_file) == null and file_ptr != .linker_defined) break :blk elf.SHN_ABS; - break :blk symbol.outputShndx() orelse elf.SHN_UNDEF; + break :blk @intCast(symbol.outputShndx() orelse elf.SHN_UNDEF); }; const st_value = blk: { if (symbol.flags.has_copy_rel) break :blk symbol.address(.{}, elf_file); diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 6febd30fc4..9367395460 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -840,7 +840,7 @@ fn getDeclShdrIndex( elf_file: *Elf, decl: *const Module.Decl, code: []const u8, -) error{OutOfMemory}!u16 { +) error{OutOfMemory}!u32 { _ = self; const mod = elf_file.base.comp.module.?; const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded; @@ -894,7 +894,7 @@ fn updateDeclCode( elf_file: *Elf, decl_index: InternPool.DeclIndex, sym_index: Symbol.Index, - shdr_index: u16, + shdr_index: u32, code: []const u8, stt_bits: u8, ) !void { @@ -993,7 +993,7 @@ fn updateTlv( elf_file: *Elf, decl_index: InternPool.DeclIndex, sym_index: Symbol.Index, - shndx: u16, + shndx: u32, code: []const u8, ) !void { const gpa = elf_file.base.comp.gpa; @@ -1334,7 +1334,7 @@ fn lowerConst( name: []const u8, tv: TypedValue, required_alignment: InternPool.Alignment, - output_section_index: u16, + output_section_index: u32, src_loc: Module.SrcLoc, ) !LowerConstResult { const gpa = elf_file.base.comp.gpa; diff --git a/src/link/Elf/synthetic_sections.zig b/src/link/Elf/synthetic_sections.zig index 47e10281fa..93516764bc 100644 --- a/src/link/Elf/synthetic_sections.zig +++ b/src/link/Elf/synthetic_sections.zig @@ -388,7 +388,7 @@ pub const ZigGotSection = struct { .st_name = st_name, .st_info = elf.STT_OBJECT, .st_other = 0, - .st_shndx = elf_file.zig_got_section_index.?, + .st_shndx = @intCast(elf_file.zig_got_section_index.?), .st_value = st_value, .st_size = st_size, }; @@ -813,7 +813,7 @@ pub const GotSection = struct { .st_name = st_name, .st_info = elf.STT_OBJECT, .st_other = 0, - .st_shndx = elf_file.got_section_index.?, + .st_shndx = @intCast(elf_file.got_section_index.?), .st_value = st_value, .st_size = st_size, }; @@ -953,7 +953,7 @@ pub const PltSection = struct { .st_name = st_name, .st_info = elf.STT_FUNC, .st_other = 0, - .st_shndx = elf_file.plt_section_index.?, + .st_shndx = @intCast(elf_file.plt_section_index.?), .st_value = sym.pltAddress(elf_file), .st_size = 16, }; @@ -1082,7 +1082,7 @@ pub const PltGotSection = struct { .st_name = st_name, .st_info = elf.STT_FUNC, .st_other = 0, - .st_shndx = elf_file.plt_got_section_index.?, + .st_shndx = @intCast(elf_file.plt_got_section_index.?), .st_value = sym.pltGotAddress(elf_file), .st_size = 16, }; @@ -1132,7 +1132,7 @@ pub const CopyRelSection = struct { } } - pub fn updateSectionSize(copy_rel: CopyRelSection, shndx: u16, elf_file: *Elf) !void { + pub fn updateSectionSize(copy_rel: CopyRelSection, shndx: u32, elf_file: *Elf) !void { const shdr = &elf_file.shdrs.items[shndx]; for (copy_rel.symbols.items) |sym_index| { const symbol = elf_file.symbol(sym_index); |
