From 728024f9f3fc4f454c91cf29c169acb660a13c21 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 28 Jul 2024 23:53:06 -0700 Subject: [PATCH 1/2] start code: implement __init_array_start, __init_array_end --- lib/std/start.zig | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/std/start.zig b/lib/std/start.zig index aeefbaffc0..7449d2d5bc 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -435,6 +435,22 @@ 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); + + { + 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)); From 3f2d1b17fc304c8a71e6fcce4a17500b19c3fbac Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 29 Jul 2024 11:38:11 -0700 Subject: [PATCH 2/2] disable the new code for self-hosted riscv backend --- lib/std/start.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/std/start.zig b/lib/std/start.zig index 7449d2d5bc..ba02652db7 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -436,7 +436,8 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn { // 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,