commit f219286573a7a1edafe3e1b5bc1e521a379ee2e2 (tree)
parent 38e0f049c531e83ec2eec80d50b624e6c3b8c486
Author: Andrew Kelley <andrew@ziglang.org>
Date: Mon, 29 Jul 2024 18:40:27 -0700
Merge pull request #20852 from ziglang/init-array-start-code
start code: implement __init_array_start, __init_array_end
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/lib/std/start.zig b/lib/std/start.zig
@@ -464,6 +464,23 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {
// Here we look for the stack size in our program headers and use setrlimit
// to ask for more stack space.
expandStackSize(phdrs);
+
+ // Disabled with the riscv backend because it cannot handle this code yet.
+ if (builtin.zig_backend != .stage2_riscv64) {
+ const opt_init_array_start = @extern([*]*const fn () callconv(.C) void, .{
+ .name = "__init_array_start",
+ .linkage = .weak,
+ });
+ const opt_init_array_end = @extern([*]*const fn () callconv(.C) void, .{
+ .name = "__init_array_end",
+ .linkage = .weak,
+ });
+ if (opt_init_array_start) |init_array_start| {
+ const init_array_end = opt_init_array_end.?;
+ const slice = init_array_start[0 .. init_array_end - init_array_start];
+ for (slice) |func| func();
+ }
+ }
}
std.posix.exit(callMainWithArgs(argc, argv, envp));