Rt0
A minimal C runtime for Linux i386 & x86_64
Install / Use
/learn @lpsantil/Rt0README
rt0
A minimal C runtime for Linux on i386 & x86_64
Features
- Implemented in just 202 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,_end,_edata,_etext,__executable_startandsyscall0/1/2/3/4/5/6 - An example implementation of
sys_brk,brk, andsbrk - Can be used with gold (Google LD, part of GNU Binutils)
- Hello World in just 608 bytes (i386) or 792 bytes (x86_64)
- Small binary sizes vs. other libc's
- Tested with RHEL 7, Ubuntu 14.04, i386/i686, x86_64
See STATS.md to see how rt0 fares. See the musl libc comparison to see how other libc's fare.
You might be interested in Linux native/built-in and fairly portable nolibc header.
Building
Try:
makemake librt0.amake testmake runtestmake DESTDIR=/usr/local install, or simply,make install- You can also do
make uninstall - It is highly recommended that you build using
WITH_FAST_SYSCALL=1, e.g.,make WITH_FAST_SYSCALL=1
Usage
- Include
rt0/rt0.hfor__environ,_exit - Include
rt0/syscall.hforSYS_*,syscall0/1/2/3/4/5/6 - Define
mainasint main( int, char**, char** ) - Compile your code with at least
-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 Google ld, type
make LD=gold - To enable GNU ld, type
make LD=ld(default) - To enable a slightly faster version of the syscalls, type
make WITH_FAST_SYSCALL=1 - To enable
-fdata-sections -ffunction-sections, typemake WITH_SECTIONS=1 - To enable a debug build, type
make WITH_DEBUG=1
References
- Hello from a libc free world!
- musl libc
- Minimum C prgram
- SmallerC
- GCC Inline Assembly HOWTO
- System V ABI/Calling Convention
- Linux syscall interface
- gold - Google ld
- brk(2) man page
- malloc implementation@Stack Overflow
- A Quick Tutorial on Implementing and Debugging Malloc, Free, Calloc, and Realloc
- Tips of malloc & free
- Writing C software without the standard library - Linux Edition
Other small libc's and runtimes
Related Skills
node-connect
353.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
353.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
353.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
