3

Take cat as an example, if I do ldd $(which cat), it shows

linux-vdso.so.1 (0x00007fff8afbb000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb3102dd000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb310524000)

Is there any way to bundle the cat binary and these three so files, so that it become statically linked?

My purpose is to use it inside a container.

doraemon
  • 421

1 Answers1

3

Statifier can do this for you: it will bundle a dynamically-linked binary and its dependencies. The result isn’t at all the same as you’d get by building the binary statically in the first place, but it will give you what you’re after.

You’ll need to disable layout randomisation to create a “statified” binary:

printf 0 | sudo tee /proc/sys/kernel/randomize_va_space

(and restore the original value afterwards).

Depending on the binaries you really want in your container, you may find it simpler to use something like a static Busybox instead.

Note that the first dependency isn’t a dynamic library you need to care about, it’s the vDSO provided by the kernel.

Stephen Kitt
  • 434,908