A simple dynamic library loader for Linux capable of loading simple binaries using simple shared libraries.
- Actually readable codebase for a dynamic loader
- Loads simple shared objects (no glibc or musl support*)
- Calls initializers and finalizers
- Performs relocations at load-time (no lazy loading supported yet)
- Supports
dlopen()
,dlsym()
, anddlclose()
- no support for threads or TLS, though rudimentary thread-safety is supported in the loader
* glibc and musl provide their own dynamic library loader that they expect to be loaded with:
ld-linux-x86_64.so.2
(akald.so
) for glibcld-musl-x86_64.so.1
(a symlink to musl'slibc.so
) for musl
libmusl.a
andmusl-gcc
(arch:musl
, debian:musl musl-tools
)elf.h
(arch: part ofbase
, debian:libelf-dev
)
cmake -B build
cd build
make
- run
build/loader/libloader.so
or any of the binaries inbuild/tests/bin/
This loader was written mostly by using specifications from refspecs.linuxbase.org, mainly the ELF spec and the x86_64 processor supplement.
For some parts of the early loader startup code (mainly the code in crt/
), I
also read the source code of musl libc to get a better
understanding of typical ways to handle early loader init. To understand ELF
symbol hash tables, I used multiple sources, but
this blog post on flagpenguin.me was most
useful.
This project is licensed under the MIT License (SPDX MIT). The full license text can also be found in the LICENSE file.