Typo
[linux_from_scratch_hints.git] / OLD / prelink.txt
blob69dbc21001fd9f69650563c3d86a82ba7725f6e2
1 TITLE:          Prelinking
3 LFS VERSION:    glibc-2.3+ based LFS
5 AUTHOR:         Tushar Teredesai <Tushar@LinuxFromScratch.Org>
7 SYNOPSIS:
8         Use prelinking - the official way to optimize!
10 HINT:
12 Primary Location of this hint:
13         http://www.linuxfromscratch.org/~tushar/
14 The latest version of the hint and any relevant patches are available at that
15 site. Please refer to the primary location before submitting
16 bug-reports/enhancements to this hint.
18 You may freely copy this document or create derivate works or distribute the
19 document in any format. At your discretion, you may give credit to the original
20 author:)
22 Use the hint at your own risk. Neither the author, nor the Linux From Scratch
23 project accept any responsibility for anything that happens when using these
24 documents or associated files.
26 An appropriate place to discuss this hint is blfs-support MailingList/NewsGroup
27 at LinuxFromScratch.Org. I welcome bug reports but for support requests, please
28 use the support list.
30 Change Log:
31 [2003-03-05]
32         * Added explaination for objprelink (which many confuse with prelink).
33         * Added a cron script to run prelink periodically.
34         * Added note that making a backup is optional.
35 [2003-03-02]
36         * Added -f flag to force prelink.
37 [2002-12-25]
38         * Changed primary location and e-mail address.
39 [2002-10-24]
40         * First public version.
42 Pre-requisites (post LFS):
43         * libelf - 0.8.2
44                 <http://freshmeat.net/projects/libelf/>
46 Packages to download:
47         * prelink - 20021002
48                 <http://freshmeat.net/projects/prelink/>
50 WARNING:
51 * I have tested the hint on a glibc-2.3.1 system. Check out the lfs-dev archives
52   since October 2002 for how to upgrade to glibc-2.3.1.
53 * Prelinking *can* mess up your system. So make appropriate backups.
54 * Don't try to prelink during the chroot phase.
56 What is prelinking? (From the horse's mouth - the man page)
58 prelink is a program which modifies ELF shared libraries and ELF dynamically
59 linked binaries, so that the time which dynamic linker needs for their
60 relocation at startup significantly decreases and also due to fewer relocations
61 the run-time memory consumption decreases too (especially number of unshareable
62 pages). Such prelinking information is only used if all its dependant libraries
63 have not changed since prelinking, otherwise programs are relocated normally.
65 prelink first collects ELF binaries which should be prelinked and all the ELF
66 shared libraries they depend on. Then it assigns a unique virtual address space
67 slot for each library and relinks the shared library to that base address. When
68 the dynamic linker attempts to load such a library, unless that virtual address
69 space slot is already occupied, it will  map it into the given slot. After this
70 is done, prelink with the help of dynamic linker resolves all relocations in the
71 binary or library against its dependant libraries and stores the relocations
72 into the ELF object. It also stores a list of all dependant libraries together
73 with their checksums into the binary or library. For binaries, it also computes
74 a list of conflicts (relocations which resolve differently in the binary's
75 symbol search scope than in the smaller search scope in which the dependant
76 library was resolved) and stores it into a special ELF section.
78 At runtime, the dynamic linker first checks whether all dependant libraries were
79 successfully mapped into their designated address space slots and whether they
80 have not changed since the prelinking was done. If all checks are successful,
81 the dynamic linker just replays the list of conflicts (which is usually
82 significantly shorter than total number of relocations) instead of relocating
83 each library.
85 Previous prelinking efforts:
87 Many people confuse prelink with a previous (and now obsolete) technique
88 objprelink <http://freshmeat.net/projects/objprelink/>. Objprelink1 was first
89 used as an optimization technique for KDE, but is now obsolete with the newer
90 version of binutils that use combreloc. combreloc is now enabled by default in
91 binutils. There is a newer version of objprelink (objprelink2) but according to
92 the authors of objprelink, the technique does not provide any significant speed
93 improvements over combreloc. Also objprelink2 does not work with gcc-3.x based
94 compilers.
96 Installing libelf:
98         ./configure --prefix=/usr --enable-shared
99         make all install
101 Installing prelink:
103         ./configure --prefix=/usr
104         make all install
106 Creating /etc/prelink.conf:
108 The configuration file used by prelink is /etc/prelink.conf. It is to be
109 populated by directories where your binaries and applications are located. In
110 the following, replace DIRS by the list of directories you want prelink to
111 search automatically.
112         DIRS="/bin /lib /sbin /usr /opt"
113         for i in $DIRS; do echo "-l $i"; done > /etc/prelink.conf
115 Prelinking, the real deal:
117 Check out the man page for prelink to get familiar with the various options that
118 prelink accepts.
120 I use the following steps for prelinking.
122 Prelink has an undo option to revert the system back to a pre-prelink stage. But
123 if you are paranoid, make a backup of the files that will be modified by prelink
124 by performing a dry run. For the record, I don't:-)
125         cd /var/tmp
126         prelink -vnamRf 2>/dev/null > dry-run
127         cat dry-run | grep "Would prelink" | sed -e "s:Would prelink ::" > bkup
128         for f in `cat bkup`
129         do
130                 d=`dirname ${f}`
131                 install -d /var/tmp${d}
132                 cp -Lv $f /var/tmp${f}
133         done
135 Now do the actual prelinking.
136         prelink -vamRf 2>&1 > log
138 Remember that you need to re-prelink the binaries on every upgrade. I use the
139 following script which is run by cron:
140         if [ -f /var/lib/misc/runPrelink ]
141         then
142                 prelink -au
143                 prelink -vamRf --ld-library-path=/usr/lib/mozilla
144                 rm -f /var/lib/misc/runPrelink
145         fi
146 The /var/lib/misc/runPrelink file is created each time a package is upgraded on
147 my system.
150 Don't forget to send me bug reports and enhancements so that I can keep the hint
151 updated.