prelink hint

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

robert
-------------- next part --------------
AUTHOR: Robert Connolly <robert at linuxfromscratch.org>

DATE: 2005-03-23

LICENSE: Public Domain

SYNOPSIS: ELF shared library prelinking.

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

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

HINT:

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

- 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
libGL.so should not be pic. This means libGL.so isn't really a shared object, it can't
use shared memory, and can't be prelinked. So everything linked to libGL.so, like all
the X11 stuff, can't be prelinked. This sucks, so it's best to hack X11 so it will work
better.
Read more here (follow the links at the bottom):
http://lists.debian.org/debian-x/2002/12/msg00022.html
especially:
http://marc.theaimsgroup.com/?l=xfree-xpert&m=103913722104609&w=2
and search google for "libGL fpic" if you want.

One of the problems with libGL.so is that it has non-pic assembly code. This patch fixes
it:
http://www.linuxfromscratch.org/patches/downloads/xorg/xorg-6.8.2-libGL_PIC-1.patch

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

patch -Np1 -i ../xorg-6.8.2-libGL_PIC-1.patch

libGL.so 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/linux.cf &&
echo "#define BuildLibGlxWithoutPIC NO" >> config/cf/linux.cf

libOSMesa.so 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 libOSMesa.so, so it doesn't
matter.

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.

Get: ftp://people.redhat.com/jakub/prelink/prelink-20041123.tar.bz2
or else get the newest one in that directory.

Prelink depends on libelf:
http://directory.fsf.org/libs/misc/libelf.html

Get: http://www.mr511.de/software/libelf-0.8.5.tar.gz

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

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:

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

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.


More information about the hints mailing list