cvs commit: hints prelink.txt

timothy at timothy at
Sat Dec 28 12:02:59 PST 2002

timothy     02/12/28 15:02:59

  Added:       .        prelink.txt
  Initial commit.
  Revision  Changes    Path
  1.1                  hints/prelink.txt
  Index: prelink.txt
  TITLE:		Prelinking
  LFS VERSION:	glibc-2.3+ based LFS
  AUTHOR:         Tushar Teredesai <Tushar at LinuxFromScratch.Org>
  	Use prelinking - the official way to optimize!
  Primary Location of this hint:

  The latest version of the hint and any relevant patches are available at that
  site. Please refer to the primary location before submitting
  bug-reports/enhancements to this hint.
  You may freely copy this document or create derivate works or distribute the
  document in any format. At your discretion, you may give credit to the original
  Use the hint at your own risk. Neither the author, nor the Linux From Scratch
  project accepts any reponsibility for anything that happens when using these
  documents or associated files.
  An appropriate place to discuss this hint is blfs-support MailingList/NewsGroup
  at LinuxFromScratch.Org.
  Change Log:
          * Changed primary location and e-mail address.
  	* First public version.
  Pre-requisites (post LFS):
  	* libelf - 0.8.2
  Packages to download:
  	* prelink - 20021002
  * I have tested the hint on a glibc-2.3.1 system. Check out the lfs-dev archives
    since October 2002 for how to upgrade to glibc-2.3.1.
  * Prelinking *can* mess up your system. So make appropriate backups.
  * Don't try to prelink during the chroot phase.
  What is prelinking? (From the horse's mouth - the man page)
  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.
  prelink first collects ELF binaries which should be prelinked and all the ELF
  shared libraries they depend on. Then it assigns a unique virtual address space
  slot for each library and relinks the shared library to that base address. When
  the dynamic linker attempts to load such a library, unless that virtual address
  space slot is already occupied, it will  map it into the given slot. After this
  is done, prelink with the help of dynamic linker resolves all relocations in the
  binary or library against its dependant libraries and stores the relocations
  into the ELF object. It also stores a list of all dependant libraries together
  with their checksums into the binary or library. For binaries, it also computes
  a list of conflicts (relocations which resolve differently in the binary's
  symbol search scope than in the smaller search scope in which the dependant
  library was resolved) and stores it into a special ELF section.
  At runtime, the dynamic linker first checks whether all dependant libraries were
  successfully mapped into their designated address space slots and whether they
  have not changed since the prelinking was done. If all checks are successful,
  the dynamic linker just replays the list of conflicts (which is usually
  significantly shorter than total number of relocations) instead of relocating
  each library.
  Installing libelf:
  	./configure --prefix=/usr --enable-shared
  	make all install
  Installing prelink:
  	./configure --prefix=/usr
  	make all install
  Creating /etc/prelink.conf:
  The configuration file used by prelink is /etc/prelink.conf. It is to be
  populated by directories where your binaries and applications are located. In
  the following, replace DIRS by the list of directories you want prelink to
  search automatically.
  	DIRS="/bin /lib /sbin /usr /opt"
  	for i in $DIRS; do echo "-l $i"; done > /etc/prelink.conf
  Prelinking, the real deal:
  Check out the man page for prelink to get familiar with the various options that
  prelink accepts.
  I use the following steps for prelinking.
  First do a dry run to determine what actions prelink will take.
  	cd /var/tmp
  	prelink -avmnR 2>/dev/null > dry-run
  Now backup the files that are going to be prelinked (just in case there are
  problems and we need to go back in time). Note that prelink also has an undo
  option to revert the changes, so the following step are additional insurance.
  	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 -av $f /var/tmp${f}
  Now do the actual prelinking.
  	prelink -avmR 2>&1 > log
  Don't forget to send me bug reports and enhancements so that I can keep the hint
Unsubscribe: send email to listar at
and put 'unsubscribe hints' in the subject header of the message

More information about the hints mailing list