https://github.com/ferdi265/dynamic-loader
A simple Linux dynamic loader capable of loading simple binaries using simple shared libraries (no glibc support)
https://github.com/ferdi265/dynamic-loader
c cmake dynamic-linking dynamic-loading linux musl systems-programming
Last synced: 3 months ago
JSON representation
A simple Linux dynamic loader capable of loading simple binaries using simple shared libraries (no glibc support)
- Host: GitHub
- URL: https://github.com/ferdi265/dynamic-loader
- Owner: Ferdi265
- Created: 2019-07-13T15:17:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-12-30T10:30:37.000Z (over 1 year ago)
- Last Synced: 2024-07-24T00:13:56.278Z (9 months ago)
- Topics: c, cmake, dynamic-linking, dynamic-loading, linux, musl, systems-programming
- Language: C
- Homepage:
- Size: 43 KB
- Stars: 19
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# dynamic-loader
A simple dynamic library loader for Linux capable of loading simple binaries using simple shared libraries.
## Features
- 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()`, and `dlclose()`
- 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` (aka `ld.so`) for glibc
- `ld-musl-x86_64.so.1` (a symlink to musl's `libc.so`) for musl## Dependencies
- `libmusl.a` and `musl-gcc` (arch: `musl`, debian: `musl musl-tools`)
- `elf.h` (arch: part of `base`, debian: `libelf-dev`)## Building
- `cmake -B build`
- `cd build`
- `make`
- run `build/loader/libloader.so` or any of the binaries in `build/tests/bin/`## Resources
This loader was written mostly by using specifications from
[refspecs.linuxbase.org](https://refspecs.linuxbase.org/), mainly the
[ELF spec](https://refspecs.linuxfoundation.org/elf/elf.pdf) and the
[x86\_64 processor supplement](https://refspecs.linuxfoundation.org/elf/x86_64-abi-0.95.pdf).For some parts of the early loader startup code (mainly the code in `crt/`), I
also read the source code of [musl libc](musl-libc.org/) 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](https://flapenguin.me/elf-dt-hash) was most
useful.