prelink hint

Robert Connolly robert at
Wed Mar 23 20:51:41 PST 2005

Hello. I made a prelink hint for using the glibc prelink stuff, to make stuff 
load faster. Please add it so people can use it if they want :)

-------------- next part --------------
AUTHOR: Robert Connolly <robert at>

DATE: 2005-03-23

LICENSE: Public Domain

SYNOPSIS: ELF shared library prelinking.

Prelinking is when libraries are linked to programs in advance, so they go faster. Some
people say it goes fifty percent faster, but it depends. It helps a lot if you run lots
of programs, like when you configure and make stuff, or when you start big window
managers like gnome or kde. You need a kindof new version of Glibc and Binutils, but the
ones in LFS-6 are good. If you ever upgrade Glibc the prelinking won't do anything, and
you need to run it again to set everything back up. You can also use the prelink program
to set up random load addresses so that if something has a buffer overflow the addresses
won't be guessable.

This should be alright with HLFS Glibc too.



- Problems with X11 (you should read this quick even if you don't use X11):
Prelink only works with shared objects that are compiled with position independent
code (pic). Shared objects are supposed to be pic anyway. The X11 people think that should not be pic. This means isn't really a shared object, it can't
use shared memory, and can't be prelinked. So everything linked to, like all
the X11 stuff, can't be prelinked. This sucks, so it's best to hack X11 so it will work
Read more here (follow the links at the bottom):
and search google for "libGL fpic" if you want.

One of the problems with is that it has non-pic assembly code. This patch fixes

Do all the normal stuff for X11 from the BLFS book. Before making the shadow tree do

patch -Np1 -i ../xorg-6.8.2-libGL_PIC-1.patch also needs to get -fpic when it gets made. This gets done on everything
except i386 usually, so it's not too hard to fix. We could use -fpic on everything,
but redefining stuff is better.

echo "#undef BuildLibGlxWithoutPIC" >> config/cf/ &&
echo "#define BuildLibGlxWithoutPIC NO" >> config/cf/ is not pic in LFS, it is pic in HLFS (with uClibc). I have no idea what the
problem is, but I couldn't find anything that links to, so it doesn't

If you use a binary copy of libGL, like from ATI for their 3D driver, they you're
screwed. You can use prelink for everything else though.

- Then prelink:
Do this after you install everything you think you are going to install.

or else get the newest one in that directory.

Prelink depends on libelf:


Unsquish libelf and install it like this:

./configure --prefix=/usr --sysconfdir=/etc &&
make &&
make install

Then unsquish prelink and install it like this (you can do 'make check' if you want):

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

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

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/

All done :-)

Run 'prelink -am' if you install more stuff later. You should read 'man 8 prelink' too.

If you want to read the Gentoo stuff go here:

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

More information about the hints mailing list