Statically Compiling Binaries

Creating statically compiled binaries is more of an art than a science (and is not always possible), and the act of trying to build a large number of statically compiled binaries can be inexact and difficult. You can use several different methods to compile static binaries, but despite using the apparently correct argument to build a statically compiled binary, you have no assurance of actually getting one.

However, in most cases, the process goes smoothly and generally proves to simplify the chrooting process, as statically compiled binaries can simply be copied to each chrooted directory without having to consider their underlying dependencies. Furthermore, updates are also simplified.

The flags for creating statically compiled binaries are given in one of two locations: either from the ./configure portion of the build or the make portion of the build, depending on the design of the application. Following are several common, simplified examples.

From the ./configure command:

./configure —static

From the make command: make CC="gcc -static" or make -e LDFLAGS=-all-static

As stated earlier, specifying the documented correct flag does not guarantee a statically compiled binary. You must verify that the binary was successfully compiled using ldd or a similar utility:

mail:/opt/static # ldd bash not a dynamic executable

The above output indicates that the bash binary was statically compiled successfully. But, all too often, you discover that the binary still has dynamic links:

mail:/opt/static # ldd /bin/bash linux-gate.so.1 => (0xffffe000)

libreadline.so.4 => /lib/libreadline.so.4 (0x4002d000) libhistory.so.4 => /lib/libhistory.so.4 (0x40059000) libncurses.so.5 => /lib/libncurses.so.5 (0x40060000) libdl.so.2 => /lib/libdl.so.2 (0x400a5000) libc.so.6 => /lib/tls/libc.so.6 (0x400a9000) /lib/ld-linux.so.2 (0x40000000)

Was this article helpful?

0 0
The Ultimate Computer Repair Guide

The Ultimate Computer Repair Guide

Read how to maintain and repair any desktop and laptop computer. This Ebook has articles with photos and videos that show detailed step by step pc repair and maintenance procedures. There are many links to online videos that explain how you can build, maintain, speed up, clean, and repair your computer yourself. Put the money that you were going to pay the PC Tech in your own pocket.

Get My Free Ebook


Post a comment