Open
Description
SLoC for crt0 code in some of the libcs we vendor:
- FreeBSD libc: 825
- MinGW-w64: 524
- musl: 321
- NetBSD libc: 467
- wasi-libc: 56
(glibc is a bit harder to quantify because its organization is incredibly horrible, which results in us having a bunch of probably unnecessary code in lib/libc/glibc
. I would be surprised if it's actually more than 2-3k lines of necessary crt0 code after pruning.)
This is really not a lot of code, so rewriting it in Zig would make a lot of sense, and would make progress towards #16270.
A secondary benefit would be finding any areas of the language that make writing this sort of code harder than it should be. In that regard, I can list these upfront:
- We need a way to export variables with "common" (i.e.
__attribute__((common))
) semantics. @jacobly0 suggested modeling this with@extern
and a newstd.builtin.GlobalLinkage.common
tag. A separate proposal needs to be typed up for this. - Almost every crt0 needs constructors/destructors in order to satisfy the Itanium C++ ABI - see Program coredump on exit when
dlclose
a dynamic loaded library which has atexit function calls #17908. While it's technically possible to emit these in Zig today, Proposal: Ability to append functions to.init_array
/.fini_array
#23574 would make doing so nicer and less error-prone.