Executable Is a SQLite Database
The author has been fascinated by the concepts of Nix and using SQLite as an executable format for the past few years. During their PhD, they considered replacing the ELF (Executable and Linkable Format) with SQLite, but found little interest in their idea. They developed a prototype called SELF (Structured Executable & Linkable Format), which is available on GitHub.
The SELF format consists of two tables: self_meta, which stores the ELF header as key/value pairs, and segments, which contains the program's load image with each row representing a program header and the bytes stored in a BLOB.
The SELF format aims to replace ELF by leveraging SQLite's self-describing, stable, and performant design. By converting ELF into a SQLite database, many tools that operate on ELF files can be transformed into database queries. For instance, modifying an ELF file with tools like strip or patchelf becomes a transactional operation within the database. The SELF format also simplifies dynamic linking, as SQLite's indexing capabilities can replace the traditional .gnu.hash and .hash structures found in ELF.
To implement SELF, the author has created the elf2self tool, which converts an ELF file into a SELF file. Additionally, self-exec is a small C program linked against libsqlite3 that acts as an interpreter for the SELF format, fetching the program headers and symbol table from the database instead of reading them from the ELF file. The implementation of self-exec is similar to that of ld.so but fetches data from the database, making it easier to dynamically link programs.
Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
Also reported by 1 other outlet
- Executable Is a SQLite Database fzakaria.com