Skip to content
/ rt0 Public
forked from lpsantil/rt0

A minimal C runtime for Linux i386 & x86_64

License

Notifications You must be signed in to change notification settings

zhdaniel/rt0

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

67 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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_start and syscall0/1/2/3/4/5/6
  • An example implementation of sys_brk, brk, and sbrk
  • 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

See STATS.md to see how rt0 fares. See the musl libc comparison to see how other libc's fare.

Branch Status
master Build Status

Building

Try:

  • make
  • make librt0.a
  • make test
  • make runtest
  • make 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.h for __environ, _exit
  • Include rt0/syscall.h for SYS_*, syscall0/1/2/3/4/5/6
  • Define main as int 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, type make WITH_SECTIONS=1
  • To enable a debug build, type make WITH_DEBUG=1

References

Other small libc's and runtimes

About

A minimal C runtime for Linux i386 & x86_64

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 82.5%
  • Makefile 17.5%