فهرست منبع

[Bug 195] Add static library explanation to chapter 5

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@1350 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
Mark Hymers 24 سال پیش
والد
کامیت
01669da789
4فایلهای تغییر یافته به همراه71 افزوده شده و 2 حذف شده
  1. 4 0
      chapter01/changelog.xml
  2. 1 0
      chapter05/chapter05.xml
  3. 63 0
      chapter05/whystatic.xml
  4. 3 2
      index.xml

+ 4 - 0
chapter01/changelog.xml

@@ -33,6 +33,10 @@
 
 </para></listitem>
 
+<listitem><para>November 30th, 2001 [markh]: Chapter 5: Added static
+library explanation originally posted on lfs-apps (when it still
+existed) by Plasmatic.</para></listitem>
+
 <listitem><para>November 26th, 2001 [markh]: Chapter 5+6: Updated to
 kernel-2.4.16 and modutils-2.4.12.</para></listitem>
 

+ 1 - 0
chapter05/chapter05.xml

@@ -3,6 +3,7 @@
 <?dbhtml filename="chapter05.html" dir="chapter05"?>
 
 &c5-introduction;
+&c5-whystatic;
 &c5-installasroot;
 &c5-bash;
 &c5-binutils;

+ 63 - 0
chapter05/whystatic.xml

@@ -0,0 +1,63 @@
+<sect1 id="ch05-whystatic">
+<title>Why do we use static linking?</title>
+<?dbhtml filename="whystatic.html" dir="chapter05"?>
+
+<para>Thanks to Plasmatic for posting the text on which this is mainly
+based to one of the LFS mailing lists.</para>
+
+<para>When making (compiling) a program, rather than having to rewrite all the
+functions for dealing with the kernel, hardware, files, etc. everytime you
+write a new program, all these basic functions are instead kept in libraries.
+glibc, which you install later, is one of these major libraries, which contain
+code for all the basic functions programs use, like opening files, printing
+information on the screen, and getting feedback from the user. When the
+program is compiled, these libraries of code are linked together with the new
+program, so that it can use any of the functions that the library
+has.</para>
+
+<para>However, these libraries can be very large (for example, libc.a
+from can often be around 2.5MB), so you may not want a seperate copy of 
+each library attached to the
+program. Just imagine if you had a simple command like ls with an extra 2.5MB
+attached to it! Instead of making the library an actual part of the
+program, or Statically Linked, the library is kept a seperate file,
+which is loaded only when the program needs it. This is what we call Dynamically
+Linked, as the library is loaded and unloaded dynamically, as the program needs
+it.</para>
+
+<para>So now we have a 1kb file and a 2.5MB file, but we still haven't saved any
+space (except maybe RAM until the library is needed). The REAL advantage to
+dynamically linked libraries is that we only need one copy of the library.
+If <filename>ls</filename> and <filename>rm</filename>both use the same 
+library, then we don't need two copies of the
+library, as they can both get the code from the same file.  
+Even when in memory, both programs share the same code, rather than loading
+duplicates into memory. So not only are we saving hard disk space, but also
+precious RAM.</para>
+
+<para>If dynamic linking saves so much room, then why are we making everything
+statically linked?  Well, that's because when you chroot into your brand new
+(but very incomplete) LFS environment, these dynamic libraries won't be
+available because they are somewhere else in your old directory tree
+(<filename>/usr/lib</filename> for example) which won't be accessible 
+from within your LFS root (<filename>$LFS</filename>).</para>
+
+<para>So in order for your new programs to run inside the chroot environment you
+need to make sure that the libraries are statically linked when you build
+them, hence the <userinput>--enable-static-link</userinput>, 
+<userinput>--disable-shared</userinput>, and
+<userinput>-static</userinput> flags used
+through Chapter 5. Once in Chapter 6, the first thing we do is build the
+main set of system libraries, glibc. Once this is made we start rebuilding 
+all the programs we just did in Chapter 5, but this time dynamically linked, 
+so that we can take advantage of the space saving opportunites.</para>
+
+<para>And there you have it, that's why you need to use those weird
+<userinput>-static</userinput> flags.  If you try building everything 
+without them, you'll see very quickly what
+happens when you chroot into your newly crippled LFS system.</para>
+
+<para>If you want to know more about Dynamically Linked Libraries, consult a 
+book or website on programming, especially a Linux-related site.</para>
+
+</sect1>

+ 3 - 2
index.xml

@@ -4,8 +4,8 @@
 
 <!ENTITY book SYSTEM "book/book.xml">
 
-<!ENTITY version "20011126">
-<!ENTITY releasedate "November 26th, 2001">
+<!ENTITY version "20011130">
+<!ENTITY releasedate "November 30th, 2001">
 
 <!ENTITY ftp-root "ftp://ftp.linuxfromscratch.org">
 <!ENTITY http-root "http://ftp.linuxfromscratch.org">
@@ -139,6 +139,7 @@
 
 <!ENTITY chapter5 SYSTEM "chapter5/chapter5.xml">
 <!ENTITY c5-introduction SYSTEM "chapter5/introduction.xml">
+<!ENTITY c5-whystatic SYSTEM "chapter5/whystatic.xml">
 <!ENTITY c5-installasroot SYSTEM "chapter5/installasroot.xml">
 <!ENTITY c5-bash SYSTEM "chapter5/bash.xml">
 <!ENTITY c5-bash-inst SYSTEM "chapter5/bash-inst.xml">