authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-31 19:26:16+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-09-03 17:33:23-07:00
log290ccb160e2d884f70ac92d2eb16d56efd380533
treeb997efaac7edd9aac56ca5ae5d5dcf4647f8da76
parent7a4d69983a6ac7ab91f71910cec5886ed5bec745

glibc: Avoid building and linking stub libraries that were emptied in 2.34.

Closes #20919.

2 files changed, 21 insertions(+), 4 deletions(-)

src/glibc.zig+9-4
...@@ -16,6 +16,7 @@ const Module = @import("Package/Module.zig");...@@ -16,6 +16,7 @@ const Module = @import("Package/Module.zig");
16pub const Lib = struct {16pub const Lib = struct {
17 name: []const u8,17 name: []const u8,
18 sover: u8,18 sover: u8,
19 removed_in: ?Version = null,
19};20};
2021
21pub const ABI = struct {22pub const ABI = struct {
...@@ -34,12 +35,12 @@ pub const ABI = struct {...@@ -34,12 +35,12 @@ pub const ABI = struct {
34// The order of the elements in this array defines the linking order.35// The order of the elements in this array defines the linking order.
35pub const libs = [_]Lib{36pub const libs = [_]Lib{
36 .{ .name = "m", .sover = 6 },37 .{ .name = "m", .sover = 6 },
37 .{ .name = "pthread", .sover = 0 },38 .{ .name = "pthread", .sover = 0, .removed_in = .{ .major = 2, .minor = 34, .patch = 0 } },
38 .{ .name = "c", .sover = 6 },39 .{ .name = "c", .sover = 6 },
39 .{ .name = "dl", .sover = 2 },40 .{ .name = "dl", .sover = 2, .removed_in = .{ .major = 2, .minor = 34, .patch = 0 } },
40 .{ .name = "rt", .sover = 1 },41 .{ .name = "rt", .sover = 1, .removed_in = .{ .major = 2, .minor = 34, .patch = 0 } },
41 .{ .name = "ld", .sover = 2 },42 .{ .name = "ld", .sover = 2 },
42 .{ .name = "util", .sover = 1 },43 .{ .name = "util", .sover = 1, .removed_in = .{ .major = 2, .minor = 34, .patch = 0 } },
43 .{ .name = "resolv", .sover = 2 },44 .{ .name = "resolv", .sover = 2 },
44};45};
4546
...@@ -797,6 +798,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi...@@ -797,6 +798,10 @@ pub fn buildSharedObjects(comp: *Compilation, prog_node: std.Progress.Node) !voi
797 defer stubs_asm.deinit();798 defer stubs_asm.deinit();
798799
799 for (libs, 0..) |lib, lib_i| {800 for (libs, 0..) |lib, lib_i| {
801 if (lib.removed_in) |rem_in| {
802 if (target_version.order(rem_in) != .lt) continue;
803 }
804
800 stubs_asm.shrinkRetainingCapacity(0);805 stubs_asm.shrinkRetainingCapacity(0);
801 try stubs_asm.appendSlice(".text\n");806 try stubs_asm.appendSlice(".text\n");
802807
src/link/Elf.zig+12
...@@ -840,6 +840,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod...@@ -840,6 +840,10 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
840 } else if (target.isGnuLibC()) {840 } else if (target.isGnuLibC()) {
841 try system_libs.ensureUnusedCapacity(glibc.libs.len + 1);841 try system_libs.ensureUnusedCapacity(glibc.libs.len + 1);
842 for (glibc.libs) |lib| {842 for (glibc.libs) |lib| {
843 if (lib.removed_in) |rem_in| {
844 if (target.os.version_range.linux.glibc.order(rem_in) != .lt) continue;
845 }
846
843 const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{847 const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{
844 comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,848 comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,
845 });849 });
...@@ -1286,6 +1290,10 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {...@@ -1286,6 +1290,10 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
1286 if (needs_grouping) try argv.append("--end-group");1290 if (needs_grouping) try argv.append("--end-group");
1287 } else if (target.isGnuLibC()) {1291 } else if (target.isGnuLibC()) {
1288 for (glibc.libs) |lib| {1292 for (glibc.libs) |lib| {
1293 if (lib.removed_in) |rem_in| {
1294 if (target.os.version_range.linux.glibc.order(rem_in) != .lt) continue;
1295 }
1296
1289 const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{1297 const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{
1290 comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,1298 comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,
1291 });1299 });
...@@ -2288,6 +2296,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s...@@ -2288,6 +2296,10 @@ fn linkWithLLD(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: s
2288 if (needs_grouping) try argv.append("--end-group");2296 if (needs_grouping) try argv.append("--end-group");
2289 } else if (target.isGnuLibC()) {2297 } else if (target.isGnuLibC()) {
2290 for (glibc.libs) |lib| {2298 for (glibc.libs) |lib| {
2299 if (lib.removed_in) |rem_in| {
2300 if (target.os.version_range.linux.glibc.order(rem_in) != .lt) continue;
2301 }
2302
2291 const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{2303 const lib_path = try std.fmt.allocPrint(arena, "{s}{c}lib{s}.so.{d}", .{
2292 comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,2304 comp.glibc_so_files.?.dir_path, fs.path.sep, lib.name, lib.sover,
2293 });2305 });