Skip to content

Commit

Permalink
src/glibc: Do some arch-specific glibc version checks
Browse files Browse the repository at this point in the history
Some architectures are only supported, by glibc, at more recent versions.
So add some checks for these systems.

Issue #17769
  • Loading branch information
rootbeer committed Oct 30, 2023
1 parent 0ad7318 commit 313d1cc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
42 changes: 42 additions & 0 deletions src/glibc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
return error.InvalidTargetGLibCVersion;
}

try isArchSupportedGlibcVersion(target, target_version);

{
var map_contents = std.ArrayList(u8).init(arena);
for (metadata.all_versions[0 .. target_ver_index + 1]) |ver| {
Expand Down Expand Up @@ -1142,3 +1144,43 @@ pub fn needsCrtiCrtn(target: std.Target) bool {
pub fn isSupportedGlibcVersion(ver: Version) bool {
return (ver.major > 2) or ((ver.major == 2) and (ver.minor >= 17));
}

// Check if given glibc version is supported by target's architecture. Note that
// target.zig's `available_libcs` should filter out many architectures before this.
pub fn isArchSupportedGlibcVersion(target: std.Target, ver: Version) !void {
// See https://github.com/ziglang/zig/issues/17769
switch (target.cpu.arch) {
.powerpc64le => {
if ((ver.major < 2) or ((ver.major == 2) and (ver.minor < 19))) {
log.warn("{s} only supported on glibc v2.19+", .{@tagName(target.cpu.arch)});
return error.InvalidTargetGLibCVersion;
}
},
.riscv64 => {
if ((ver.major < 2) or ((ver.major == 2) and (ver.minor < 27))) {
log.warn("{s} only supported on glibc v2.27+", .{@tagName(target.cpu.arch)});
return error.InvalidTargetGLibCVersion;
}
},

// For many architectures, glibc support is older than the Zig
// minimum (v2.17), so we don't need to check specifics.
.aarch64,
.aarch64_be,
.arm,
.m68k,
.powerpc64,
.powerpc,
.sparc,
.sparc64,
.x86,
.x86_64,
=> return,

// Other platforms are ... unknown?
else => {
log.warn("{s} has undefined glibc support. Please file a bug.", .{@tagName(target.cpu.arch)});
return error.InvalidTargetGLibCVersion;
},
}
}
6 changes: 3 additions & 3 deletions src/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub const ArchOsAbi = struct {
};

pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .aarch64_be, .os = .linux, .abi = .gnu },
.{ .arch = .aarch64_be, .os = .linux, .abi = .gnu }, // glibc aarch64 v2.17+
.{ .arch = .aarch64_be, .os = .linux, .abi = .musl },
.{ .arch = .aarch64_be, .os = .windows, .abi = .gnu },
.{ .arch = .aarch64, .os = .linux, .abi = .gnu },
Expand Down Expand Up @@ -51,14 +51,14 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .mips, .os = .linux, .abi = .gnueabi },
.{ .arch = .mips, .os = .linux, .abi = .gnueabihf },
.{ .arch = .mips, .os = .linux, .abi = .musl },
.{ .arch = .powerpc64le, .os = .linux, .abi = .gnu },
.{ .arch = .powerpc64le, .os = .linux, .abi = .gnu }, // glibc powerpc64le v2.19+
.{ .arch = .powerpc64le, .os = .linux, .abi = .musl },
.{ .arch = .powerpc64, .os = .linux, .abi = .gnu },
.{ .arch = .powerpc64, .os = .linux, .abi = .musl },
.{ .arch = .powerpc, .os = .linux, .abi = .gnueabi },
.{ .arch = .powerpc, .os = .linux, .abi = .gnueabihf },
.{ .arch = .powerpc, .os = .linux, .abi = .musl },
.{ .arch = .riscv64, .os = .linux, .abi = .gnu },
.{ .arch = .riscv64, .os = .linux, .abi = .gnu }, // glibc riscv v2.27+
.{ .arch = .riscv64, .os = .linux, .abi = .musl },
.{ .arch = .s390x, .os = .linux, .abi = .gnu },
.{ .arch = .s390x, .os = .linux, .abi = .musl },
Expand Down

0 comments on commit 313d1cc

Please sign in to comment.