1 Static linking 2 ================================================================================ 3 4 While I was working on a new initramfs generator for Carbs, I was once again 5 reminded of the advantages of static linking software. Previously, I was using 6 some really dumb script that was just basically using the package manager as a 7 library for building the whole initramfs system from scratch. This system 8 structure was completely statically linked, and the whole thing weighed around 9 1.3MiB. 10 11 Now, while `rd` (the small script that I had written) was good enough for me, it 12 wouldn't be a fit to distribute with the system. It doesn't deal with dynamic 13 binaries, kernel modules or library installation. So I have written this script 14 that deals with those (kernel modules aren't done yet, though). 15 16 The issue with build systems today are that the binaries are built dynamically 17 unless you build the whole thing static. As long as there are shared libraries, 18 the binaries will be dynamic as well. That's why the core repository of Carbs 19 still contains dynamic binaries for gcc, binutils, util-linux and some other 20 packages. 21 22 The size of the new image with exactly the same binaries is a whopping 1.9MiB. 23 While a size increase of 600KiB might not seem like a huge deal, I just want to 24 tell you that busybox is static in both images, leaving ONLY TWO binaries that 25 I install to my image; fsck and e2fsck. By switching from a static binary to 26 dynamic + lib for only two programs, you require 600 KiB more space, and I have 27 been talking about a gzip compressed cpio archive throughout this whole post.