Better way to -nostdlib
Opened this issue · 2 comments
lpsantil commented
Saw your recent threading blog on HN. The Linux kernel now has a nolibc header that takes care of a lot of SYSCALL interfacing.
https://github.com/torvalds/linux/blob/master/tools/include/nolibc/nolibc.h
skeeto commented
Thanks, lpsantil! I didn't know about this little library, and I see it's
fairly new. It's exactly the sort of thing I've been wanting. Here's a LWN
article filling in the details:
Nolibc: a minimal C-library replacement shipped with the kernel
https://lwn.net/Articles/920158/
More specifically, "arch.h" is almost exactly what I want. The additional
libc emulation takes it too far, but it's optional. Unfortunately its
string.h is tangled up in it. It would be nice to have that memset() and
memmove() present when GCC stubbornly generates such calls.
Notably, it does not support MIPS64, any SPARC, any PowerPC, any HPPA,
Alpha, SH4, nor m68k. I list them because my system has Linux-targeting
compilers for each, along with QEMU User Mode emulation.
Also, it's too bad none of the distributions I checked package these
headers. I've love if I could simply "#include <nolibc/arch.h>" in a
program and get rolling. (I suppose that means I should take point on
making this happen.)
lpsantil commented
Several years back, I took a crack at this for Ubuntu and i386, x86_64 (https://github.com/lpsantil/rt0). I should update it to work on Fedora. I had some notes about that somewhere.
rt0 is very, very minimal. I reference a bunch of other work I learned from in writing rt0. Maybe combine your ideas, my ideas, and nolibc. I tend to only care about ARM, ARM64, i386, and x86_64 these days.
Funny, I think I was inspired to write rt0 after reading some of your older blogs.