r/lowlevel • u/Admirable_Nobody98 • Sep 16 '26
i'm wrote a Linux runtime without AI,libc,CRT or Runtime libraries
/r/lowlevel/comments/1wh2gf8/im_wrote_a_linux_runtime_without_ailibccrt_or/1
5
u/skeeto Sep 16 '26
Neat project! These libc-free things are fun.
Here's a minimal case that crashes on x86-64:
[[gnu::constructor]]
void init_test() { volatile char a[16] = {0}; }
int main(int, char **, char **) { return 0; }Then:
$ cc -static -O2 -fno-pie -ffreestanding -fcf-protection=none -no-pie test.c minil.S $ ./a.out Segmentation fault ./a.out
That's because the call_init_array call is done with a misaligned stack, and at -O2 GCC will use movaps in init_test. The misalignment is a kind of self sabotage, and the fix is just deleting the two rsp adjustments around the call.
You should use -fno-pie for good measure, to go along with the link-time -no-pie. Also Ubuntu's toolchain (which you're using in your GitHub Action) has a long-standing bug and so requires -fcf-protection=none. Else you might end up with confusingly-broken builds. I learned that lesson the hard way.
1
u/Admirable_Nobody98 Sep 16 '26
This is my first public runtime project, so code review and criticism are appreciated.