lpsantil/rt0 logo

lpsantil/rt0

Free

A minimal C runtime for Linux i386 & x86_64

FreeFree tier
Type
Open Source

About lpsantil/rt0

rt0 is a minimal C runtime for Linux on i386 and x86_64 architectures, designed to provide the bare essentials for running C programs without a full libc. Implemented in just 202 lines of C code and only 9 lines (i386) or 6 lines (x86_64) of GCC inline assembly, it offers startup components such as argc, argv, envp, __environ, errno, _exit, and memory symbols (_end, _edata, _etext, __executable_start), along with syscall wrappers syscall0 through syscall6. It includes example implementations of sys_brk, brk, and sbrk, and can be linked with the gold linker (Google LD). A minimal "Hello World" program compiles to just 608 bytes on i386 or 792 bytes on x86_64. The runtime has been tested on RHEL 7 and Ubuntu 14.04 for both i386/i686 and x86_64. rt0 is ideal for building extremely small, statically linked Linux binaries and for educational purposes in understanding low-level program startup.

Key Features

Implemented in just 202 SLOC of C code with minimal inline assembly (9 lines for i386, 6 lines for x86_64)
Provides essential runtime components: argc, argv, envp, __environ, errno, _exit, _end, _edata, _etext, __executable_start
Includes syscall wrappers: syscall0, syscall1, syscall2, syscall3, syscall4, syscall5, syscall6
Example implementation of sys_brk, brk, and sbrk memory management
Compatible with gold linker (Google LD) and GNU ld
Produces extremely small binaries: Hello World in 608 bytes (i386) or 792 bytes (x86_64)
Tested on RHEL 7 and Ubuntu 14.04 for i386/i686 and x86_64
Licensed under BSD-2-Clause

Pros & Cons

Pros
  • Extremely small code footprint (202 SLOC) makes it easy to understand and audit
  • Minimal runtime dependencies – only requires a Linux kernel
  • Produces very small binary sizes compared to standard libc implementations
  • Supports both i386 and x86_64 architectures
  • Open source with permissive BSD-2 license
  • Provides essential runtime and syscall wrappers for bare-metal C programming
Cons
  • Only supports Linux on i386 and x86_64 architectures
  • Not a full libc – lacks standard library functions like printf, malloc, file I/O, etc.
  • No dynamic linking support; only static linking is possible
  • Limited testing scope (RHEL 7, Ubuntu 14.04) – may require adjustments on newer distributions
  • Not suitable for complex or portable C programs that depend on libc functionality

Best For

Building minimal, statically linked Linux executables without a full libcLearning about low-level C runtime initialization and system call interfacingCreating prototypes or educational examples for operating system or embedded developmentReducing binary size and dependency footprint for simple command-line tools