静态 link 动态加载二进制文件到二进制文件

statically link dynamic loaded binaries into binary

我有一个已编译的二进制文件 file.bin,它是动态链接到其他文件的。

$ ldd file.bin
    linux-vdso.so.1 (0x00007ffc017c6000)
    so.6 => /usr/lib/libm.so.6 (0x00007f3af51d7000)
    so.2 => /usr/lib/libdl.so.2 (0x00007f3af51d1000)
    so.6 => /usr/lib/libc.so.6 (0x00007f3af5008000)
    ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f3af61a7000)

我需要独立于库,因为我的目标系统使用这些库的不同版本。 (在目标上执行 file.bin 会产生错误:/lib64/libm.so.6: version 'GLIBC_2.27' not found)。我没有file.bin的源代码。 我的尝试是将那些动态链接的文件添加到该二进制文件中,但我找不到任何工具来执行此操作。有可能吗?

如果这有帮助:我可以 运行 内核 5.10.6-arch1-1 上的 file.bin 并且目标是内核 3.10.0-1062.9.1.el7.x86_64

没有 file.bin 的源代码,您无法构建静态二进制文件。

但是,有许多工具可以帮助您将现有的动态二进制文件及其依赖项打包到一个二进制文件中,例如 Statifier and Ermine

引自 Ermine 网站:

What can Ermine do for you?

Ermine packs a GNU/Linux application together with any needed shared libraries and data files into a single executable. This file can be copied to any GNU/Linux host and run without further modifications.

Basic functionality:

  • Only one file is installed
  • Escape from “dependency hell”
  • Independence from package management (RPM, DEB, TGZ, ...)
  • No version mismatch between the executable and its auxiliary files
  • No host-dependent side-effects: the application and the target host's software environment do not interfere with each other