最後更新: 2017-03-21

prelink ELF shared libraries and binaries to speed up startup time

prelink first collects ELF binaries to be prelinked and all the ELF shared libraries they depend on. Then it assigns a unique virtual address space slot to 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 maps the library 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 dependent libraries and stores the relocations into the ELF object. It also stores a list of all dependent libraries together with their checksums into the binary or library. For binaries, it also computes a list of conflicts (relocations that resolve differently in the binary's symbol search scope than in the smaller search scope in which the dependent library was resolved) and stores it into a special ELF section.

At runtime, the dynamic linker first checks whether all dependent 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.


Cron jobs


prelink is run once a day via the system crontab and its control file
/etc/cron.daily/prelink.  The cache will change if system libraries are
updated via yum/rpm or you build something that adds libraries to the
normal system directories.

Cron jobs 會 load 以下 file


# Set this to no to disable prelinking altogether
# (if you change this from yes to no prelink -ua
# will be run next night to undo prelinking)





Binary file containing a list of prelinked libraries and/or binaries together with their assigned virtual address space slots and dependencies. You can run /usr/sbin/prelink -p to see what is stored in there.


Configuration file containing a list of directory hierarchies that contain ELF shared libraries or binaries which should be prelinked.

This configuration file is used in -a mode to find binaries which should be prelinked and also, no matter whether -a is given or not, to limit which dependent shared libraries should be prelinked.


-l meaning the tree walk of the given directory is only limited to one file system
-h meaning the tree walk of the given directory follows symbolic links.
-b A blacklist specification


prelink Options

-v --verbose

-n --dry-run

-u --undo

Revert binaries and libraries to their original content before they were prelinked. Without the -a option, this causes only the binaries and libraries specified on the command line to be reverted to their original state (and e.g. not their dependencies). If used together with the -a option, all binaries and libraries from command line, all their dependencies, all binaries found in directories specified on command line and in the config file, and all their dependencies are undone.

-y --verify

Verifies a prelinked binary or library. This option can be used only on a single binary or library. It first applies an --undo operation on the file, then prelinks just that file again and compares this with the original file. If both are identical, it prints the file after --undo operation on standard output and exits with zero status. Otherwise it exits with error status. Thus if --verify operation returns zero exit status and its standard output is equal to the content of the binary or library before prelinking, you can be sure that nobody modified the binaries or libraries after prelinking. Similarly with message digests and checksums (unless you trigger the improbable case of modified file and original file having the same digest or checksum).