A minimal C runtime for Linux i386 & x86_64
- Implemented in just 87 SLOC of C code.
- Just 2 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
,_exit
, andsyscall0/1/2/3/4/5/6
- Small binary sizes vs. other libc's
Binary | Arch | Size | Purpose | Compile Args |
---|---|---|---|---|
librt0.a | i386 | 4390 | Startup code+syscall | -Os -nostdlib -fomit-frame-pointer |
librt0.a | x86_64 | 6086 | Startup code+syscall | -Os -nostdlib -fomit-frame-pointer |
t/hello.exe | i386 | 1272 | Hello World\n | -Os -s -nostdlib -fomit-frame-pointer |
t/hello.exe | x86_64 | 1520 | Hello World\n | -Os -s -nostdlib -fomit-frame-pointer |
hello.exe | i386 | 5532 | Hello World\n with glibc | -Os -s -fomit-frame-pointer |
hello.exe | x86_64 | 6240 | Hello World\n with glibc | -Os -s -fomit-frame-pointer |
Compiler: GCC 4.8.2, OS: Ubuntu 14.04.1, Source: Author
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
- 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
- Link with librt0, e.g.,
cc prog.o -nostdlib -lrt0 -o prog