Skip to content

Commit f219286

Browse files
authored
Merge pull request #20852 from ziglang/init-array-start-code
start code: implement __init_array_start, __init_array_end
2 parents 38e0f04 + 3f2d1b1 commit f219286

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/std/start.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,23 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {
464464
// Here we look for the stack size in our program headers and use setrlimit
465465
// to ask for more stack space.
466466
expandStackSize(phdrs);
467+
468+
// Disabled with the riscv backend because it cannot handle this code yet.
469+
if (builtin.zig_backend != .stage2_riscv64) {
470+
const opt_init_array_start = @extern([*]*const fn () callconv(.C) void, .{
471+
.name = "__init_array_start",
472+
.linkage = .weak,
473+
});
474+
const opt_init_array_end = @extern([*]*const fn () callconv(.C) void, .{
475+
.name = "__init_array_end",
476+
.linkage = .weak,
477+
});
478+
if (opt_init_array_start) |init_array_start| {
479+
const init_array_end = opt_init_array_end.?;
480+
const slice = init_array_start[0 .. init_array_end - init_array_start];
481+
for (slice) |func| func();
482+
}
483+
}
467484
}
468485

469486
std.posix.exit(callMainWithArgs(argc, argv, envp));

0 commit comments

Comments
 (0)