prelink hint

Robert Connolly robert at linuxfromscratch.org
Sat Mar 26 01:34:49 PST 2005


Okay. I put the two hints together. I left out the cron script because I don't 
think many people will use it. Everything else should be okay. This one can 
come off the orphan list. Let me know if something is not right :)

robert
-------------- next part --------------
AUTHOR:	Robert Connolly <robert at linuxfromscratch.org>
	Tushar Teredesai <Tushar at LinuxFromScratch.Org>

DATE: 2005-03-26

LICENSE: GNU Free Documentation License version 1.2

SYNOPSIS: ELF shared library prelinking.

DESCRIPTION:
>From 'man 8 prelink':
Prelink is a program which modifies ELF shared libraries and ELF dynamically linked
binaries, so that the time which dynamic linker needs for their relocation at startup
significantly decreases and also due to fewer relocations the run-time memory
consumption decreases too (especially number of unshareable pages). Such prelinking
information is only used if all its dependant libraries have not changed since
prelinking, otherwise programs are relocated normally.

PREREQUISITES: LFS-6.0
This should be alright with HLFS Glibc too.

HINT:

Homepage: http://freshmeat.net/projects/prelink/

- First of all, never strip (or otherwise modify) programs or libraries after they are
prelinked. If you strip a prelinked program, the prelink application will not undo it
because it has been modified. Even if a program is already stripped and you strip it
again this will change the timestamp on the ELF header sections. If you want to strip
all your programs after they are prelinked, first undo the prelinking with 'prelink -au'.

- Secondly you need at least 50 megabytes of freespace to prelink the whole system. If
you do not have that much free space then only do a few programs at a time.

- Thirdly, if you plan to use the X11 windowing system with prelinking you should install
a position independent version of libGL.so. By default the libGL.so library that is
included with X11 is not a true shared object, it does not use shared memory, and can
not be prelinked (so nothing linked to it can be prelinked either). It is suggested
that you install a patch to make libGL.so use position independent assembly code:

http://www.linuxfromscratch.org/patches/downloads/xorg/xorg-6.8.2-libGL_PIC-1.patch

And use these command in the xc/ directory to use -fPIC on libGL.so:

echo "#undef BuildLibGlxWithoutPIC" >> config/cf/linux.cf &&
echo "#define BuildLibGlxWithoutPIC NO" >> config/cf/linux.cf

libOSMesa.so is also not position independent, but there is no strait forward way to
remedy this. Nothing I know of links to this library, so it shouldn't cause a problem.

If you use a binary version of libGL.so, like the ones shipped by ATI for their 3D
driver, then you are screwed. You can however still use prelink for everything else.

- Finally install the software. Prelink depends on libelf, so fetch:

ftp://people.redhat.com/jakub/prelink/prelink-20041123.tar.bz2
and
http://www.mr511.de/software/libelf-0.8.5.tar.gz

Install libelf like this:

./configure --prefix=/usr --enable-shared &&
make &&
make install

Install prelink like this:

./configure --prefix=/usr --sysconfdir=/etc &&
make &&
make install &&
install -m644 doc/prelink.conf /etc/prelink.conf

If you use /opt you should add it to the config file like this:

echo "-l /opt/bin" >> /etc/prelink.conf

You might want to edit the /etc/prelink.conf file.

Prelink has an undo option to revert the system back to a pre-prelink stage. But
if you are paranoid, make a backup of the files that will be modified by prelink
by performing a dry run. For the record, I don't:-)
	cd /var/tmp
	prelink -vnamRf 2>/dev/null > dry-run
	cat dry-run | grep "Would prelink" | sed -e "s:Would prelink ::" > bkup
	for f in `cat bkup`
	do
		d=`dirname ${f}`
		install -d /var/tmp${d}
		cp -Lv $f /var/tmp${f}
	done

Then actually prelink everything. If you want random addresses use -R too:

prelink -am

If you get errors about libz.so make sure to use -fPIC in your CFLAGS and install
zlib again (like the LFS book says). Then rerun 'prelink -am'.

KDE knows about prelinking and it'll start faster if you tell it you have it. It's best
to stick this in where all the users can use it. X.sh is a good place if you use the
BLFS shell scripts, or else use /etc/profile or something:

echo "export KDE_IS_PRELINKED=1" >> /etc/profile.d/X.sh

You should read 'man 8 prelink' too.

If you want to read the Gentoo stuff go here:

http://www.gentoo.org/doc/en/prelink-howto.xml

- Previous prelinking efforts:
http://objprelink.sourceforge.net/

Many people confuse prelink with a previous (and now obsolete) technique objprelink.
Objprelink1 was first used as an optimization technique for KDE, but is now obsolete
with the newer version of binutils that use combreloc. combreloc is now enabled by
default in binutils. There is a newer version of objprelink (objprelink2) but according
to the authors of objprelink, the technique does not provide any significant speed
improvements over combreloc. Also objprelink2 does not work with gcc-3.x based compilers.

ACKNOWLEDGMENTS:
  * Thanks to Jakub Jelinek for making the prelink(8) program.
  * Thanks to Google and Debian for helping me figure out how to fix X11.
  * Thanks to Gentoo for pointers on setting up prelink.

CHANGELOG:
[2005-03-23]
  * Initial hint.
[2005-03-26]
  * Adopted prelink.txt from Tushar, merged the two.


More information about the hints mailing list