Skip to content

Commit

Permalink
src/glibc: Only support glibc v2.17 and later as linking targets
Browse files Browse the repository at this point in the history
Earlier glibc's do not contain symbols (e.g., getauxval()) used by the Zig
standard library.

Filter the list shown by Zig targets, too:

  $ zig targets | jq -c '.glibc'
  ["2.17.0","2.18.0","2.19.0","2.20.0","2.21.0","2.22.0","2.23.0","2.24.0","2.25.0","2.26.0","2.27.0","2.28.0","2.29.0","2.30.0","2.31.0","2.32.0","2.33.0","2.34.0","2.35.0","2.36.0","2.37.0","2.38.0"]

Fixes #17769
  • Loading branch information
rootbeer committed Oct 30, 2023
1 parent ee56a9c commit 0ad7318
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/glibc.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub const Lib = struct {
};

pub const ABI = struct {
all_versions: []const Version,
all_versions: []const Version, // all defined versions (one abilist from v2.0.0 up to current)
all_targets: []const target_util.ArchOsAbi,
/// The bytes from the file verbatim, starting from the u16 number
/// of function inclusions.
Expand Down Expand Up @@ -741,6 +741,11 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: *std.Progress.Node) !vo
break :blk latest_index;
};

if (!isSupportedGlibcVersion(target_version)) { // only a subset of all_versions are supported
log.warn("Unsupported target glibc version: {}", .{target_version});
return error.InvalidTargetGLibCVersion;
}

{
var map_contents = std.ArrayList(u8).init(arena);
for (metadata.all_versions[0 .. target_ver_index + 1]) |ver| {
Expand Down Expand Up @@ -1131,3 +1136,9 @@ pub fn needsCrtiCrtn(target: std.Target) bool {
else => true,
};
}

// Glibc v2.17 is the oldest supported linking target due to dependencies
// from the Zig standard library.
pub fn isSupportedGlibcVersion(ver: Version) bool {
return (ver.major > 2) or ((ver.major == 2) and (ver.minor >= 17));
}
8 changes: 5 additions & 3 deletions src/print_targets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ pub fn cmdTargets(
try jws.objectField("glibc");
try jws.beginArray();
for (glibc_abi.all_versions) |ver| {
const tmp = try std.fmt.allocPrint(allocator, "{}", .{ver});
defer allocator.free(tmp);
try jws.write(tmp);
if (glibc.isSupportedGlibcVersion(ver)) {
const tmp = try std.fmt.allocPrint(allocator, "{}", .{ver});
defer allocator.free(tmp);
try jws.write(tmp);
}
}
try jws.endArray();

Expand Down

0 comments on commit 0ad7318

Please sign in to comment.