website

My personal website
git clone git://git.ckyln.com/website
Log | Files | Refs

20200828-static-linking.html (3033B)


      1 <!DOCTYPE HTML>
      2 <html lan=en>
      3   <head>
      4     <title>Static linking | Cem's Website</title>
      5     <meta charset="utf-8">
      6     <meta name="Description" content="Cem Keylan's Website">
      7     <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      8     <style>
      9       html {font-family:monospace;font-size:16px;color:#282a36;}
     10       body {
     11 	  width: 90%;
     12 	  max-width: 1050px;
     13 	  margin-left: auto;
     14 	  margin-right: auto;
     15 	  margin-top: 20px;
     16 	  overflow: none;
     17           overflow-y: scroll;
     18 	  padding-right: 10px;
     19 	  padding-left: 10px;
     20       }
     21       a{text-decoration:none;font-weight:bold;color:#282a36;}
     22       a:hover{text-decoration:underline;}
     23       @media (prefers-color-scheme: dark) {
     24           html {color: white;background:#282a36;}
     25           a{color:white;}
     26       }
     27     </style>
     28     <link rel="stylesheet" href="/static/syntax.css">
     29     <script src="/static/highlight.pack.js"></script>
     30     <script>hljs.initHighlightingOnLoad();</script>
     31   </head>
     32   <body>
     33     <div class="header">
     34       <nav>
     35         <a href='/'>index</a> |
     36         <a href="/software.html">software</a> |
     37         <a href="/blog.html">blog</a> |
     38         <a href="/contact.html">contact</a> |
     39         <a href="/sysmgr">sysmgr</a> |
     40       </nav>
     41     </div>
     42     <hr>
     43     <p>
     44 <h1>Static linking</h1>
     45 
     46 <p>While I was working on a new initramfs generator for Carbs, I was once again
     47 reminded of the advantages of static linking software. Previously, I was using
     48 some really dumb script that was just basically using the package manager as a
     49 library for building the whole initramfs system from scratch. This system
     50 structure was completely statically linked, and the whole thing weighed around
     51 1.3MiB.</p>
     52 
     53 <p>Now, while <code>rd</code> (the small script that I had written) was good enough for me, it
     54 wouldn&rsquo;t be a fit to distribute with the system. It doesn&rsquo;t deal with dynamic
     55 binaries, kernel modules or library installation. So I have written this script
     56 that deals with those (kernel modules aren&rsquo;t done yet, though).</p>
     57 
     58 <p>The issue with build systems today are that the binaries are built dynamically
     59 unless you build the whole thing static. As long as there are shared libraries,
     60 the binaries will be dynamic as well. That&rsquo;s why the core repository of Carbs
     61 still contains dynamic binaries for gcc, binutils, util-linux and some other
     62 packages.</p>
     63 
     64 <p>The size of the new image with exactly the same binaries is a whopping 1.9MiB.
     65 While a size increase of 600KiB might not seem like a huge deal, I just want to
     66 tell you that busybox is static in both images, leaving ONLY TWO binaries that
     67 I install to my image; fsck and e2fsck. By switching from a static binary to
     68 dynamic + lib for only two programs, you require 600 KiB more space, and I have
     69 been talking about a gzip compressed cpio archive throughout this whole post.</p>
     70     </p>
     71     <a href="/blog/20200828-static-linking.txt">This page in plain-text</a>
     72     <hr>
     73     <p class=footer>Copyright &copy; 2019-2021 Cem Keylan</p>
     74   </body>
     75 </html>