prelink hint

Robert Connolly robert at
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 :)

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

DATE: 2005-03-26

LICENSE: GNU Free Documentation License version 1.2

SYNOPSIS: ELF shared library prelinking.

>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.

This should be alright with HLFS Glibc too.



- 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 By default the 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 use position independent assembly code:

And use these command in the xc/ directory to use -fPIC on

echo "#undef BuildLibGlxWithoutPIC" >> config/cf/ &&
echo "#define BuildLibGlxWithoutPIC NO" >> config/cf/ 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, 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:

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`
		d=`dirname ${f}`
		install -d /var/tmp${d}
		cp -Lv $f /var/tmp${f}

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

prelink -am

If you get errors about 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. 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/

You should read 'man 8 prelink' too.

If you want to read the Gentoo stuff go here:

- Previous prelinking efforts:

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.

  * 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.

  * Initial hint.
  * Adopted prelink.txt from Tushar, merged the two.

More information about the hints mailing list