Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
S

superlinker

> 编程语言
Open source

a tool for reinterpreting ELF executables and shared libraries

355 stars0 likes0 views
WebsiteGitHub

About

a tool for reinterpreting ELF executables and shared libraries

superlinker

Superlinker is a tool that can combine executables and shared libraries into even larger products, just like object files are combined into executables and shared libraries. It works well enough for building a self-contained Python distribution from off-the-shelf packages.

Why?

Wouldn't it be funny if your entire OS image consisted of only one shared object that was really, really large?

How?

Superlinker is structured essentially like a compiler whose inputs and outputs are interpreted programs (ELF ET_DYN PIE executables or shared libraries). Its frontend lifts an ELF ET_DYN object into an abstract and simple intermediate representation, and its backend lowers this representation back to an ELF ET_DYN object. While memory mappings (PT_LOAD segments) are retained essentially intact, none of the ELF headers are copied from the inputs to the outputs. Of the many possible transformations, the currently implemented one rebases and merges several ELF objects. This approach is quite robust.

Additionally, Superlinker is able to merge the dynamic linker itself into an executable, which enables transforming system-dependent executables into executables that run anywhere. (The resulting executable is still an ET_DYN object to retain the benefits of ASLR, but it has no load-time dependencies.) This is implemented with an executable shim that emulates the kernel ABI for PT_INTERP loaded objects, and so is not tied to a specific libc, but currently only tested with musl libc.

The intermediate representation features architecture-, target-, and (somewhat) format-independent model of loadable segments, relocations, symbols, and image interpreters, biased towards ELF without directly requiring it. The frontend and backend are currently ported to amd64 only. Although not strictly required for functioning, section headers are emitted as a courtesy for libbfd based tools (e.g. objdump).

Use?

First, install Rust and run cargo build.

Usage: ./target/debug/superlinker   [ [ ...]]

Show?

…

Flaws?

Although the core approach is sound, this implementation has flaws, most of which are fixable:

  • All of the code continues to use the dynamic linking ABI, i.e. procedure calls go through PLT and global accesses go through GOT. This is the only flaw inherent to the approach.
  • Executable and shared object formats are notoriously complex and this implementation is bound to have bugs.
    • Moreover, some of the more obscure features are not implemented rigorously or at all (e.g. symbol scoping, visibility, and versioning).
  • All GOT and PLT optimizations are disabled. (This means that DT_JMPREL, DT_PLTREL, and DT_PLTRELSZ entries are stripped.)
    • PLT optimizations at least could be added back with additional work.
  • Only the global-dynamic TLS model is supported.
  • Only "Rela" relocations are implemented and tested, though "Rel" relocations would be trivial to add.
  • DT_GNU_HASH is not supported, and the number of DT_HASH buckets is randomly fixed at 4.
  • Although ASLR is supported (Superlinker only produces position independent executables), PT_GNU_STACK and PT_GNU_RELRO are not supported and stripped.
  • Exception handling currently isn't supported, and PT_GNU_EH_FRAME is stripped.
  • Some of the internal book-keeping probably has O(n²) complexity.

The implementation is less than a thousand lines long, written with portability in mind, and extensively commented, so it should not be too difficult to address most of these flaws. It should even run on Windows!

Python?

Although tedious, it is possible to use Superlinker to build a fully self-contained Python distribution without source modifications or, in fact, touching source at all. First, link the combination of the Python executable, its dependencies, and essential modules. Using Alpine Linux 3.20 as the base distribution, run:

…

Python has a little known function where it can treat a zip archive as if it was a directory, which will come in handy when packaging the (portable subset of) standard library modules:

# apk add fastjar
$ fastjar 0cvf py.zip -C /usr/lib/python3.12/ .

Note the 0 (that's a zero) option for fastjar; Python loads compressed zip archives using its own zipimport standard library module, which means that it cannot be compressed when it is a part of a zip archive itself.

Even though Python has all of these modules linked into it, it's currently unaware of that, and an attempt to import any of them will fail. This can be solved with a little bit of Python code:

$ cat >sitecustomize.py py.run
$ chmod +x py.run

The final touch this distribution needs is the PYTHONPATH environment variable:

…

Past?

If you like Superlinker, you might also enjoy unfork.

License?

0-clause BSD.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言