{"id":13751777,"url":"https://github.com/akawashiro/sloader","last_synced_at":"2025-04-10T00:43:22.601Z","repository":{"id":38370154,"uuid":"389086398","full_name":"akawashiro/sloader","owner":"akawashiro","description":"sloader is an ELF loader which aims to replace ld-linux.so of glibc.","archived":false,"fork":false,"pushed_at":"2023-11-05T09:25:07.000Z","size":534,"stargazers_count":153,"open_issues_count":3,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-10T00:43:16.600Z","etag":null,"topics":["elf","elf-binaries","elf-loader","glibc","linux"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/akawashiro.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-07-24T11:54:32.000Z","updated_at":"2025-04-06T12:17:53.000Z","dependencies_parsed_at":"2023-10-11T12:38:49.097Z","dependency_job_id":"f0237e2e-6619-42ed-a85f-579af058399c","html_url":"https://github.com/akawashiro/sloader","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akawashiro%2Fsloader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akawashiro%2Fsloader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akawashiro%2Fsloader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akawashiro%2Fsloader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akawashiro","download_url":"https://codeload.github.com/akawashiro/sloader/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248137998,"owners_count":21053775,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elf","elf-binaries","elf-loader","glibc","linux"],"created_at":"2024-08-03T09:00:54.557Z","updated_at":"2025-04-10T00:43:22.581Z","avatar_url":"https://github.com/akawashiro.png","language":"C++","readme":"# sloader \u003c!-- omit in toc --\u003e\n`sloader` is an ELF loader that aims to replace `ld-linux.so.2` of glibc. \n\n## Notice\n`sloader` haven't implmented almost all security related features. Please be careful.\n\n## Table of Contents \u003c!-- omit in toc --\u003e\n- [Current status](#current-status)\n- [How to build and use](#how-to-build-and-use)\n- [Why I am making alternative loader](#why-i-am-making-alternative-loader)\n  - [What is a loader](#what-is-a-loader)\n  - [Problem of `ld-linux.so`](#problem-of-ld-linuxso)\n  - [Motivation of making sloader](#motivation-of-making-sloader)\n  - [Developement principles of sloader](#developement-principles-of-sloader)\n- [For developpers](#for-developpers)\n  - [How to build and run tests](#how-to-build-and-run-tests)\n  - [Test using custom build glibc](#test-using-custom-build-glibc)\n\n## Current status\n`sloader` can load many practical programs such as `cmake`, `g++`, `ld`, `htop`, etc. Furthermore, `sloader` can launche some GUI applications.\n![GUI applications launched by sloader](./xapps-launched-by-sloader.png)\n\nHowever, `sloader` depends on `ld-linux.so` because I cannot statically link `sloader` now. \n\n## How to build and use\n```\n$ git clone https://github.com/akawashiro/sloader.git\n$ cd sloader\n$ mkdir build\n$ cmake -S . -B build -G Ninja\n$ cmake --build build\n$ ./build/sloader ls\n```\n\n## Why I am making alternative loader\n### What is a loader\nWhen you run an executable binary file on Linux using execve(2), there are two execution paths.\n- Linux kernel loads the file to the memory space.\n- The loader specified by the file loads the file to the memory space.\n\nYou can check the specified loader path using `readelf -l`. In most cases,  you will find `Requesting program interpreter: /lib64/ld-linux-x86-64.so.2` which means the loader loads the binary. Although the path includes `-x86-64` because my machine is x86-64, I call it `ld-linux.so` from now for generality.\n\n```\n$ readelf -l $(which nvim) | grep INTERP -A 2\n  INTERP         0x0000000000000318 0x0000000000000318 0x0000000000000318\n                 0x000000000000001c 0x000000000000001c  R      0x1\n      [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2]\n```\n\n`ld-linux.so` does three things when loading binary files.\n- Seaches shared libraries that the file needs.\n- Loads all shared libraries and the file to the memory.\n- Resolves symbols of shared libraries and the file.\n\nIt is important to understand precisely how `ld-linux.so` works. For example, valuable hacks with environment variables such as LD_PRELOAD and LD_AUDIT are implemented by changing their behavior. Understanding the behavior of `ld-linux.so` will allow you to infer what these environment variables can and cannot do. Also, understanding it is essential for creating software like [https://github.com/akawashiro/sold](https://github.com/akawashiro/sold) that forcibly links shared libraries.\n\n### Problem of `ld-linux.so`\n`ld-linux.so` is installed on Linux as part of GNU libc, and its complete source code is publicly available. However, two problems exist in understanding the behavior of `ld-linux.so` from the published source code.\n\nThe first problem is that the GNU libc source code is hard to read. GNU libc is a software with a long history written in C language. It also requires portability to multiple architectures such as x86-84, Alpha, ARM, and PowerPC. As a result, macros are used extensively throughout the source code, making it difficult to follow the flow of the program.\n\nThe second problem is that `libc.so` is simultaneously initialized when `ld-linux.so` loads an executable file. And it is hard to understand the initialization and the loading process separately. libc.so is the so-called standard C library, which is almost certainly loaded when the binary file is loaded by `ld-linux.so`. `libc.so` and `ld-linux.so` are in the same package, and glibc doesn't explicitly document the relationship between the two components.\n\n### Motivation of making sloader\nTo solve the above problems and understand `ld-linux.so` behavior, I decided to develop a new loader that can replace `ld-linux.so` . In other words, I am trying to load all the programs that start on Linux (`systemd`, `cat`, `find`, `firefox`, etc.). \n\n### Developement principles of sloader\nI decided the following two principles when I started the development.\n\nThe first principle is to use modern C++ instead of C. I try to use modern C++ features up to C++20 to improve readability. I considered using Rust, but I decided that a language compatible with the C language would be better because I would be developing while referring to the GNU libc source code.\n\nThe second principle is not to initialize `libc.so`. The purpose is to understand only the load part, so I will not do the complicated `libc.so`.\n\n## For developpers\n### How to build and run tests\n```\n$ git clone https://github.com/akawashiro/sloader.git\n$ cd sloader\n$ mkdir build\n$ cmake -S . -B build -G Ninja\n$ cmake --build build\n$ cd build\n$ ctest -V\n```\n\n### Test using custom build glibc\n```\n$ git clone https://github.com/akawashiro/sloader.git\n$ cd sloader\n$ mkdir build\n$ cmake -S . -B build -G Ninja\n$ cmake --build build\n$ ./misc/clone_glibc.sh\n$ ./misc/build_glibc.sh\n$ SLOADER_LIBRARY_PATH=/home/akira/sloader/glibc-install/lib ./build/sloader ./build/tests/hello_glibc/hello_glibc\n```\n","funding_links":[],"categories":["C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakawashiro%2Fsloader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakawashiro%2Fsloader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakawashiro%2Fsloader/lists"}