Skip to content

Commit

Permalink
start code: implement __init_array_start, __init_array_end
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jul 29, 2024
1 parent 390c7d8 commit 728024f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/std/start.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit 728024f

Please sign in to comment.