How tjmers/freestanding-custom-c-library works
This repository is a freestanding Linux x86_64 C library: an application links it instead of system libc, and its custom startup shim initializes runtime state, calls main, then exits through the library. The runtime spans buffered output and formatting, heap allocation, conversions, strings and memory routines, exit callbacks, and raw Linux syscall wrappers. Startup and several documented capabilities were not shown in implementation excerpts, so those links rely on the README; relationships between unsampled internals are omitted.
Main entry points: stdio.c Buffered stdio · stdlib.c Heap allocator · entry.asm Startup shim · exit.c Exit callbacks
Components 20
Startup and exit
- Startup shim
src/entry.asm - Exit callbacks
src/exit.c - Exit API
intf/exit.h
Output and syscalls
- Buffered stdio
src/stdio.c - Stream internals
src/_stdio.h - stdio API
intf/stdio.h - Syscall interface
intf/syscalls.h - Linux syscall wrappers
src/syscalls.asm - Mapping constants
intf/mmap_macros.h
Memory and allocation
- Heap allocator
src/stdlib.c - Memory routines
src/memory.c - Memory API
intf/memory.h - stdlib API
intf/stdlib.h
C utilities
- Integer conversions
src/conversions.c - String routines
src/string - String API
intf/string.h - Assertions
src/assert.c - Core types
intf/stdint.h - Varargs interface
intf/stdarg.h
Other components
- C application
Connections 24
- C application → Startup shim: links against
README.md - Startup shim → Heap allocator: initializes heap
README.md - Startup shim → Buffered stdio: initializes streams
README.md - Startup shim → C application: calls main
README.md - Startup shim → Exit callbacks: routes return to
README.md - Buffered stdio → Stream internals: uses
src/stdio.c - Buffered stdio → Linux syscall wrappers: writes through
src/stdio.c - Buffered stdio → Integer conversions: formats integers with
src/stdio.c - Buffered stdio → String routines: uses string routines
src/stdio.c - Buffered stdio → Exit callbacks: registers flush callback
src/stdio.c - Heap allocator → Linux syscall wrappers: grows heap with
src/stdlib.c - Heap allocator → Memory routines: uses memory routines
src/stdlib.c - Heap allocator → String routines: uses string routines
src/stdlib.c - Heap allocator → Integer conversions: formats diagnostics with
src/stdlib.c - Memory routines → Memory API: implements
src/memory.c - String routines → stdlib API: strdup allocates with
src/string/strdup.c - Assertions → Linux syscall wrappers: uses
src/assert.c - Exit callbacks → Linux syscall wrappers: terminates through
- Syscall interface → Mapping constants: defines mapping flags
intf/syscalls.h - stdio API → Buffered stdio: declares interface for
src/stdio.c - stdlib API → Heap allocator: declares allocator API for
src/stdlib.c - String API → String routines: declares string API for
src/string/strtok.c - Exit API → Exit callbacks: declares exit API for
src/exit.c - Varargs interface → Buffered stdio: supplies formatting arguments
src/stdio.c