aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-12-15 00:22:38 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-12-15 14:30:03 -0700
commit19ca2415f26b07b399a60fd17a4cf85f290da0fd (patch)
treedbbd6affde21ad2a59b2b2e1f4d7948e21133a13 /tools
parent1edf8efa4243eb1715ace35b1a99f7eaa0863fdd (diff)
downloadzig-19ca2415f26b07b399a60fd17a4cf85f290da0fd.tar.gz
zig-19ca2415f26b07b399a60fd17a4cf85f290da0fd.zip
update glibc start files to 2.34
This commit introduces tools/update_glibc.zig to update the start files for next time. Some notable changes in recent glibc: * abi-note.S has been changed to abi-note.c but we resist the change to keep it easier to compile the start files. * elf-init.c has been deleted upstream. Further testing should be done to verify that binaries against glibc omitting elf-init.c still run properly on oldel glibc linux systems. Closes #4926
Diffstat (limited to 'tools')
-rw-r--r--tools/update_glibc.zig71
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/update_glibc.zig b/tools/update_glibc.zig
new file mode 100644
index 0000000000..9d4f338956
--- /dev/null
+++ b/tools/update_glibc.zig
@@ -0,0 +1,71 @@
+//! This script updates the .c, .h, .s, and .S files that make up the start
+//! files such as crt1.o. Not to be confused with
+//! https://github.com/ziglang/glibc-abi-tool/ which updates the `abilists`
+//! file.
+//!
+//! Example usage:
+//! `zig run ../tools/update_glibc.zig -- ~/Downloads/glibc ..`
+
+const std = @import("std");
+const mem = std.mem;
+const log = std.log;
+const fs = std.fs;
+
+const exempt_files = [_][]const u8{
+ "abilists",
+ "include/libc-modules.h",
+ "include/config.h",
+ // These are easier to maintain like this, without updating to the abi-note.c
+ // that glibc did upstream.
+ "csu/abi-tag.h",
+ "csu/abi-note.S",
+};
+
+pub fn main() !void {
+ var arena_instance = std.heap.ArenaAllocator.init(std.heap.page_allocator);
+ defer arena_instance.deinit();
+ const arena = arena_instance.allocator();
+
+ const args = try std.process.argsAlloc(arena);
+ const glibc_src_path = args[1];
+ const zig_src_path = args[2];
+
+ const dest_dir_path = try std.fmt.allocPrint(arena, "{s}/lib/libc/glibc", .{zig_src_path});
+
+ var dest_dir = fs.cwd().openDir(dest_dir_path, .{ .iterate = true }) catch |err| {
+ fatal("unable to open destination directory '{s}': {s}", .{
+ dest_dir_path, @errorName(err),
+ });
+ };
+ defer dest_dir.close();
+
+ var glibc_src_dir = try fs.cwd().openDir(glibc_src_path, .{});
+ defer glibc_src_dir.close();
+
+ var walker = try dest_dir.walk(arena);
+ defer walker.deinit();
+
+ walk: while (try walker.next()) |entry| {
+ if (entry.kind != .File) continue;
+ if (mem.startsWith(u8, entry.basename, ".")) continue;
+ for (exempt_files) |p| {
+ if (mem.eql(u8, entry.path, p)) continue :walk;
+ }
+
+ glibc_src_dir.copyFile(entry.path, dest_dir, entry.path, .{}) catch |err| {
+ log.warn("unable to copy '{s}/{s}' to '{s}/{s}': {s}", .{
+ glibc_src_path, entry.path,
+ dest_dir_path, entry.path,
+ @errorName(err),
+ });
+ if (err == error.FileNotFound) {
+ try dest_dir.deleteFile(entry.path);
+ }
+ };
+ }
+}
+
+fn fatal(comptime format: []const u8, args: anytype) noreturn {
+ log.err(format, args);
+ std.process.exit(1);
+}