Skip to content

Commit 728024f

Browse files
committed
start code: implement __init_array_start, __init_array_end
1 parent 390c7d8 commit 728024f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/std/start.zig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,22 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.C) noreturn {
435435
// Here we look for the stack size in our program headers and use setrlimit
436436
// to ask for more stack space.
437437
expandStackSize(phdrs);
438+
439+
{
440+
const opt_init_array_start = @extern([*]*const fn () callconv(.C) void, .{
441+
.name = "__init_array_start",
442+
.linkage = .weak,
443+
});
444+
const opt_init_array_end = @extern([*]*const fn () callconv(.C) void, .{
445+
.name = "__init_array_end",
446+
.linkage = .weak,
447+
});
448+
if (opt_init_array_start) |init_array_start| {
449+
const init_array_end = opt_init_array_end.?;
450+
const slice = init_array_start[0 .. init_array_end - init_array_start];
451+
for (slice) |func| func();
452+
}
453+
}
438454
}
439455

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

0 commit comments

Comments
 (0)