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 => (0xffffe000) => /lib/ (0x4002d000) => /lib/ (0x40059000) => /lib/ (0x40060000) => /lib/ (0x400a5000) => /lib/tls/ (0x400a9000) /lib/ (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