1 AUTHOR: Robert Connolly <robert@linuxfromscratch.org>
2 Tushar Teredesai <Tushar@LinuxFromScratch.Org>
6 LICENSE: GNU Free Documentation License version 1.2
8 SYNOPSIS: ELF shared library prelinking.
11 >From 'man 8 prelink':
12 Prelink is a program which modifies ELF shared libraries and ELF dynamically
13 linked binaries, so that the time which dynamic linker needs for their
14 relocation at startup significantly decreases and also due to fewer relocations
15 the run-time memory consumption decreases too (especially number of unshareable
16 pages). Such prelinking information is only used if all its dependant libraries
17 have not changed since prelinking, otherwise programs are relocated normally.
19 PREREQUISITES: Glibc-2.3.2 and newer
23 Homepage: http://freshmeat.net/projects/prelink/
25 - First of all, never strip (or otherwise modify) programs or libraries after
26 they are prelinked. If you strip a prelinked program, the prelink application
27 will not undo it because it has been modified. Even if a program is already
28 stripped and you strip it again this will change the timestamp on the ELF header
29 sections. If you want to strip all your programs after they are prelinked, first
30 undo the prelinking with 'prelink -amu'.
32 - Secondly you need at least 50 megabytes of free space to prelink the whole
33 system; up to 200 megabytes of free space is needed if you have a lot installed.
34 If you do not have that much free space then only prelink a few programs at a
37 - Thirdly, if you plan to use the X11 windowing system with prelinking you
38 should install a position independent version of libGL.so. By default the
39 libGL.so library that is included with X11 is not a true shared object, it does
40 not use shared memory, and can not be prelinked (so nothing linked to it can be
41 be prelinked). It is suggested that you install a patch to make libGL.so use
42 use position independent assembly code:
44 http://www.linuxfromscratch.org/patches/downloads/xorg/\
45 xorg-6.8.2-libGL_PIC-1.patch
47 And use these command in the xc/ directory to use -fPIC on libGL.so:
49 echo "#undef BuildLibGlxWithoutPIC" >> config/cf/linux.cf &&
50 echo "#define BuildLibGlxWithoutPIC NO" >> config/cf/linux.cf
52 libOSMesa.so is also not position independent, but there is no strait forward
53 way to remedy this. Nothing I know of links to this library, so it should not
56 If you use a binary version of libGL.so, like the ones shipped by ATI for their
57 3D drivers, then you are screwed. You can however still use prelink for
60 - Finally install the software. Prelink depends on libelf, so fetch:
62 http://dev.gentoo.org/~azarah/prelink/prelink-20050314.tar.bz2
63 http://mirror.hamakor.org.il/pub/mirrors/gentoo-portage/sys-devel/prelink/files/\
64 prelink-20040707-init.patch
65 prelink-20050314-amd64-gcc4.patch
67 http://www.mr511.de/software/libelf-0.8.5.tar.gz
69 Install libelf like this:
71 ./configure --prefix=/usr --enable-shared &&
75 Install prelink like this:
77 patch -Np1 -i ../prelink-20040707-init.patch &&
78 patch -Np1 -i ../prelink-20050314-amd64-gcc4.patch &&
79 ./configure --prefix=/usr --sysconfdir=/etc &&
82 install -m644 doc/prelink.conf /etc/prelink.conf
84 If you use /opt you should add it to the config file like this:
86 echo "-l /opt/bin" >> /etc/prelink.conf
88 You might want to edit the /etc/prelink.conf file.
90 Prelink has an undo option to revert the system back to a pre-prelink stage. But
91 if you are paranoid, make a backup of the files that will be modified by prelink
92 by performing a dry run. For the record, I don't :-)
94 prelink -vnamRf 2>/dev/null > dry-run
95 cat dry-run | grep "Would prelink" | sed -e "s:Would prelink ::" > bkup
99 install -d /var/tmp${d}
100 cp -Lv $f /var/tmp${f}
103 Then actually prelink everything. The -R switch randomizes load addresses,
104 making the system slightly more secure:
108 With Mozilla installed use:
110 prelink -amR --ld-library-path=/usr/lib/mozilla
112 If you get errors about libz.so make sure to use -fPIC in your CFLAGS and
113 install zlib again (just like the LFS book says). Then rerun 'prelink -amR'.
115 KDE knows about prelinking and it will start faster if you tell it you have it.
116 It is best to stick this in where all the users can use it. X.sh is a good place
117 if you use the BLFS shell scripts, or else use /etc/profile or something:
119 echo "export KDE_IS_PRELINKED=1" >> /etc/profile.d/X.sh
121 You should read 'man 8 prelink' too.
123 If you want to read the Gentoo stuff go here:
125 http://www.gentoo.org/doc/en/prelink-howto.xml
127 - Previous prelinking efforts:
128 http://objprelink.sourceforge.net/
130 Many people confuse prelink with a previous (and now obsolete) technique
131 objprelink. Objprelink1 was first used as an optimization technique for KDE, but
132 is now obsolete with the newer version of Binutils that use combreloc. Combreloc
133 is now enabled by default in the newer Binutils. There is a newer version of
134 objprelink (objprelink2) but according to the authors of objprelink, the
135 technique does not provide any significant speed improvements over combreloc.
136 Also objprelink2 does not work with gcc-3.x based compilers.
139 * Thanks to Tushar Teredesai for the original prelink hint.
140 * Thanks to Jakub Jelinek for making the prelink(8) program.
141 * Thanks to Google and Debian for helping me figure out how to fix X11.
142 * Thanks to Gentoo for pointers on setting up prelink.
148 * Adopted prelink.txt from Tushar, merged the two.
150 * Added --ld-library-path=/usr/lib/mozilla and raised the suggested
151 free space. Fixed doccument width. Added -R to suggested prelink command.
153 * Updated for gcc4 (patch).
154 * Using newest version possible (20050314).