A minimal C runtime for Linux on i386 & x86_64
- Implemented in just 195 SLOC of C code.
- Just 9 lines of GCC inline ASM for i386, or,
- Just 6 lines GCC inline ASM for x86_64
- Small runtime providing just
argc
,argv
,envp
,__environ
,errno
,_exit
, andsyscall0/1/2/3/4/5/6
- Small binary sizes vs. other libc's
See STATS.md to see how rt0 fares. See the musl libc comparison to see how other libc's fare.
Try:
make
make librt0.a
make test
make runtest
- In bash,
DEST=/ PREFIX=usr/local make install
, or simply,make install
- You can also do
make uninstall
- Include
rt0/rt0.h
for__environ
,_exit
- Include
rt0/syscall.h
forSYS_*
,syscall0/1/2/3/4/5/6
- Define
main
asint main( int, char**, char** )
- Compile your code with
-nostdlib
, e.g.,cc -c prog.c -nostdlib -o prog.o
- On Linux, link with librt0, e.g.,
cc prog.o -nostdlib -lrt0 -o prog
- On FreeBSD, link with librt0 using,
cc prog.o -Wl,-u_start -nostdlib -lrt0 -o prog
- To enable a slightly faster version of the syscalls, in the
Makefile
, comment line 30 and uncomment line 31, and add#define __RT0_WITH_FASTER_SYSCALL__
before you includert0/syscall.h
- To enable
-fdata-sections -ffunction-sections
, in theMakefile
, comment line 30 and uncomment line 32 - To enable a debug build, in the
Makefile
, comment line 30 & 36, then uncomment line 33 & 38