Skip to content

fossable/solder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

solder

Don't rebuild it, solder it!

Actually, you should probably try rebuilding it first, but if that doesn't work out, then you can solder it.

solder is a post-link static merger for ELF executables. It extracts symbols from shared libraries and fuses them directly into executables, removing runtime dependencies altogether.

Partial static linking

The primary use case for solder is partial static linking.

Depending on what build tool you're using, you can have vastly different experiences. Sometimes you can simply add -l:libexample.a to your LDFLAGS and it works first try. Sometimes it's not that easy. If you find yourself hacking configure scripts or generated Makefiles to accomplish this, consider just post-processing your binary with solder instead.

You don't have to recompile anything. Just give it your executable and the shared objects you want statically linked. Just note the following libraries are excluded because static linking them can cause unpleasant problems (even when you properly static link them at build time).

  • ld-linux
  • ld-musl
  • linux-vdso
  • linux-gate
  • libc
  • libm
  • librt
  • libpthread
  • libdl
  • libresolv
  • libnss_
  • libgcc_s

Nixpkgs

For binaries built from nixpkgs, you can make them fully portable to other systems by first solder-ing in the libraries, then patchelf-ing the library path back to normal. I've used this to take advantage of the vast quantity of software available in nixpkgs on embedded systems where I can't install nix, etc.

Usage

# Merge all possible libraries into the executable (in-place)
solder ./myapp

# Merge only specific libraries
solder ./myapp -m libfoo.so.1 -m libbar.so.2

# Add additional library search paths
solder ./myapp -L /opt/mylibs -L ./libs

# Preview what would happen without writing output
solder ./myapp --dry-run

How It Works

  • Parses the executable's dynamic section to identify imported symbols
  • Resolves which shared libraries provide those symbols (using regular library search paths)
  • Extracts the minimal set of code/data needed
    • Uses symbolic execution to identify jump tables in .rodata
  • Applies relocations and creates trampolines for any remaining external calls
  • Appends a new PT_LOAD segment containing the merged code
  • Patches GOT entries to point directly to the merged symbols
  • Removes the merged libraries from DT_NEEDED

Limitations

  • x86_64 only
  • We can't merge dlopen libraries

About

Fuse shared libraries into ELFs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors