From 210b764c03b736a6fe025b5fac030eec0350f0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 4 Sep 2025 00:52:11 +0200 Subject: [PATCH] link.Elf: truncate st_other to u3 before converting to std.elf.STV See 6b6e336e07308fd23f3061b5be11407956b2a460 for context, but note that in gABI 4.3, 3 bits are reserved for the visibility, up from the previous 2. --- src/link/Elf/Object.zig | 4 ++-- src/link/Elf/SharedObject.zig | 2 +- src/link/Elf/ZigObject.zig | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index eddb5c90dd..9e1bd022ba 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -634,7 +634,7 @@ pub fn claimUnresolved(self: *Object, elf_file: *Elf) void { const is_import = blk: { if (!elf_file.isEffectivelyDynLib()) break :blk false; - const vis = @as(elf.STV, @enumFromInt(esym.st_other)); + const vis: elf.STV = @enumFromInt(@as(u3, @truncate(esym.st_other))); if (vis == .HIDDEN) break :blk false; break :blk true; }; @@ -707,7 +707,7 @@ pub fn markImportsExports(self: *Object, elf_file: *Elf) void { const file = sym.file(elf_file).?; // https://github.com/ziglang/zig/issues/21678 if (@as(u16, @bitCast(sym.version_index)) == @as(u16, @bitCast(elf.Versym.LOCAL))) continue; - const vis: elf.STV = @enumFromInt(sym.elfSym(elf_file).st_other); + const vis: elf.STV = @enumFromInt(@as(u3, @truncate(sym.elfSym(elf_file).st_other))); if (vis == .HIDDEN) continue; if (file == .shared_object and !sym.isAbs(elf_file)) { sym.flags.import = true; diff --git a/src/link/Elf/SharedObject.zig b/src/link/Elf/SharedObject.zig index 9ce8c53b2c..8c79def16b 100644 --- a/src/link/Elf/SharedObject.zig +++ b/src/link/Elf/SharedObject.zig @@ -357,7 +357,7 @@ pub fn markImportExports(self: *SharedObject, elf_file: *Elf) void { const ref = self.resolveSymbol(@intCast(i), elf_file); const ref_sym = elf_file.symbol(ref) orelse continue; const ref_file = ref_sym.file(elf_file).?; - const vis = @as(elf.STV, @enumFromInt(ref_sym.elfSym(elf_file).st_other)); + const vis: elf.STV = @enumFromInt(@as(u3, @truncate(ref_sym.elfSym(elf_file).st_other))); if (ref_file != .shared_object and vis != .HIDDEN) ref_sym.flags.@"export" = true; } } diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 93a78ea012..d103ff91db 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -617,7 +617,7 @@ pub fn claimUnresolved(self: *ZigObject, elf_file: *Elf) void { const is_import = blk: { if (!elf_file.isEffectivelyDynLib()) break :blk false; - const vis = @as(elf.STV, @enumFromInt(esym.st_other)); + const vis: elf.STV = @enumFromInt(@as(u3, @truncate(esym.st_other))); if (vis == .HIDDEN) break :blk false; break :blk true; }; @@ -695,7 +695,7 @@ pub fn markImportsExports(self: *ZigObject, elf_file: *Elf) void { const file = sym.file(elf_file).?; // https://github.com/ziglang/zig/issues/21678 if (@as(u16, @bitCast(sym.version_index)) == @as(u16, @bitCast(elf.Versym.LOCAL))) continue; - const vis: elf.STV = @enumFromInt(sym.elfSym(elf_file).st_other); + const vis: elf.STV = @enumFromInt(@as(u3, @truncate(sym.elfSym(elf_file).st_other))); if (vis == .HIDDEN) continue; if (file == .shared_object and !sym.isAbs(elf_file)) { sym.flags.import = true;