prelink(8)

๐Ÿ“ฆ version 0.0.20131005, in ubuntu jammy, ubuntu noble

System Manager's Manual โ€” yep, section 8, we're in full sysadmin main-character territory now โœจ


๐ŸŒธ NAME ๐ŸŒธ

prelink โ€” prelink ELF shared libraries and binaries to speed up startup time


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

prelink [OPTION...] [FILES]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

okay so bestie, listen. prelink is a program that goes into your ELF shared libraries and your ELF dynamically linked binaries and โœจmodifiesโœจ them so that the dynamic linker spends way less time doing relocations at startup. It's giving "make the computer wake up faster" and honestly? It ate. ๐Ÿ’…

And because there are fewer relocations to do, the run-time memory consumption goes down too โ€” especially the number of unshareable pages. Iconic. ๐Ÿซถ

the prelinking information is only used at startup if none of the dependent libraries have changed since prelinking. If something did change, the programs just get relocated normally, no drama. ๐ŸŒˆ

So here's the whole vibe of how it works, step by step:

  1. prelink first collects the ELF binaries it's supposed to prelink, plus all the ELF shared libraries they depend on.
  2. Then it assigns a unique virtual address space slot to each library, and relinks the shared library to that base address.
  3. When the dynamic linker tries to load such a library, unless that virtual address space slot is already occupied, it maps the library into the given slot. (slot taken = sorry bestie, you go elsewhere ๐Ÿ’€)
  4. After that's done, prelink โ€” with the help of the dynamic linker โ€” resolves all the relocations in the binary or library against its dependent libraries, and stores those relocations into the ELF object.
  5. It also stores a list of all dependent libraries together with their checksums into the binary or library.
  6. For binaries specifically, it also computes a list of conflicts (these are 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 that list into a special ELF section.

Then at runtime, the dynamic linker first checks whether all the dependent libraries were successfully mapped into their designated address space slots, and whether they have not changed since the prelinking was done. If all the checks pass, the dynamic linker just replays the list of conflicts โ€” which is usually significantly shorter than the total number of relocations โ€” instead of relocating each library. efficiency queen behavior ๐Ÿ‘‘


โœจ OPTIONS โœจ

  • -v, --verbose โ€” Verbose mode, bestie. Prints the virtual address slots assigned to libraries, and tells you what binary or library is currently being prelinked. It's like a little live commentary track. ๐ŸŽ™๏ธ
  • -n, --dry-run โ€” Don't actually prelink anything! Just collect the binaries/libraries, assign them addresses, and with -v print what would be prelinked. Manifesting prelinking without doing prelinking. ๐Ÿ”ฎ
  • -a, --all โ€” Prelink all binaries and dependent libraries found in the directory hierarchies specified in /etc/prelink.conf. Normally (i.e. without this) only the binaries specified on the command line and their dependent libraries get prelinked.
  • -m, --conserve-memory โ€” When assigning addresses to libraries, allow overlap of address space slots, provided that the two libraries are not present together in any of the binaries or libraries. This means a smaller virtual address space range gets used for libraries. BUT โ€” the trade-off is real: if prelink sees a binary during incremental prelinking that puts together two libraries which weren't present together in any other binary and were given the same virtual address space slots, then that binary cannot be prelinked. ๐Ÿ˜ญ Without this option, each library gets its own unique virtual address space slot, no sharing.
  • -R, --random โ€” When assigning addresses to libraries, start with a random address within the architecture-dependent virtual address space range. This can make some buffer overflow attacks slightly harder to exploit, because libraries are not present at the same addresses across different machines. Normally, assigning virtual addresses starts at the bottom of the architecture-dependent range.
  • -r, --reloc-only=ADDRESS โ€” Instead of prelinking, just relink the given shared libraries to the specified base address.
  • -N, --no-update-cache โ€” Don't save the cache file after prelinking. Normally the list of libraries (and, with -m, binaries too) is stored into the /etc/prelink.cache file together with their given address space slots and dependencies, so the cache can be used during incremental prelinking (which is prelinking without the -a option).
  • -c, --config-file=CONFIG โ€” Specify an alternate config file instead of the default /etc/prelink.conf.
  • -C, --cache-file=CACHE โ€” Specify an alternate cache file instead of the default /etc/prelink.cache.
  • -f, --force โ€” Force re-prelinking even for already prelinked objects whose dependencies are unchanged. This option causes new virtual address space slots to be assigned to all libraries. Normally, only binaries or libraries that are either not prelinked yet, or whose dependencies have changed, get prelinked.
  • -q, --quick โ€” Run prelink in quick mode. This mode checks just the mtime and ctime timestamps of libraries and binaries stored in the cache file. If they are unchanged from the last prelink run, it is assumed that the library in question did not change โ€” without parsing or verifying its ELF headers. Speedrun strats. โšก
  • -p, --print-cache โ€” Print the contents of the cache file (normally /etc/prelink.cache) and exit.
  • --dynamic-linker=LDSO โ€” Specify an alternate dynamic linker instead of the default.
  • --ld-library-path=PATH โ€” Specify a special LD_LIBRARY_PATH to be used when prelink queries the dynamic linker about symbol resolution details.
  • --layout-page-size=SIZE โ€” Layout the start of libraries at the given boundary.
  • --libs-only โ€” Only prelink ELF shared libraries, don't prelink any binaries.
  • -h, --dereference โ€” When processing command line directory arguments, follow symbolic links when walking directory hierarchies. ๐Ÿ‡
  • -l, --one-file-system โ€” When processing command line directory arguments, limit the directory tree walk to a single file system.
  • -T, --timestamp-output โ€” Prefix output with timestamps. ๐Ÿ•
  • -u, --undo โ€” Revert binaries and libraries to their original content, from 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 the command line, all their dependencies, all binaries found in directories specified on the command line and in the config file, and all their dependencies are undone. It's the ctrl+Z of prelinking. ๐Ÿ™ˆ
  • -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 the --undo operation on standard output and exits with zero status. Otherwise it exits with error status. So: if the --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 a modified file and the original file having the same digest or checksum. ๐Ÿ‘€
  • -y, --md5 โ€” This is similar to the --verify option, except instead of outputting the content of the binary or library before prelinking to standard output, the MD5 digest is printed. See md5sum(1).
  • -y, --sha โ€” This is similar to the --verify option, except instead of outputting the content of the binary or library before prelinking to standard output, the SHA1 digest is printed. See sha1sum(1).
  • --exec-shield, --no-exec-shield โ€” On IA-32, if the kernel supports Exec-Shield, prelink attempts to lay libraries out similarly to how the kernel places them (i.e. if possible below the binary, most widely used into the ASCII armor zone). These switches allow overriding prelink's detection of whether Exec-Shield is supported or not. ๐Ÿ›ก๏ธ
  • -b, --black-list=PATH โ€” This option allows blacklisting certain paths, libraries or binaries. Prelink will not touch them during prelinking. ๐Ÿšซ
  • -o, --undo-output=FILE โ€” When performing an --undo operation, don't overwrite the prelinked binary or library with its original content (before it was prelinked), but save that into the specified file.
  • -V, --version โ€” Print version and exit.
  • -?, --help โ€” Print short help and exit.
  • --usage โ€” Print short usage message.

๐ŸŒˆ ARGUMENTS ๐ŸŒˆ

Command-line arguments should be either directory hierarchies (in which case the -l and -h options apply), or particular ELF binaries or shared libraries.

Specifying a shared library explicitly on the command line causes it to be prelinked even if no binary is linked against it. Otherwise, binaries are collected together and only the libraries they depend on are prelinked with them.


๐Ÿ’ซ EXAMPLES ๐Ÿ’ซ

# /usr/sbin/prelink -avmR

prelinks all binaries found in directories specified in /etc/prelink.conf and all their dependent libraries, assigning libraries unique virtual address space slots only if they ever appear together, and starts assigning libraries at a random address. ๐ŸŽฒ

# /usr/sbin/prelink -vm ~/bin/progx

prelinks ~/bin/progx program and all its dependent libraries (unless they were prelinked already e.g. during a prelink -a invocation).

# /usr/sbin/prelink -au

reverts all binaries and libraries to their original content.

# /usr/sbin/prelink -y /bin/prelinked_prog > /tmp/original_prog;
echo $?

verifies whether /bin/prelinked_prog is unchanged.

๐Ÿ’พ FILES ๐Ÿ’พ

  • /etc/prelink.cache โ€” okay so this is a binary file bestie, and it contains a list of prelinked libraries and/or binaries together with their assigned virtual address space slots and dependencies. Wanna see what's actually in there? Run /usr/sbin/prelink -p and it will show you. โœจ
  • /etc/prelink.conf โ€” this is the config file with a list of directory hierarchies that contain ELF shared libraries or binaries which should be prelinked. It gets 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. If prelink finds a dependent library of some binary or other library which is not present in any of the directories specified either in /etc/prelink.conf or on the command line, then it cannot be prelinked. No cap, it just can't. ๐Ÿ˜ญ

Each line of the config file should be either:

  • a comment starting with #
  • a directory name
  • or a blacklist specification

Directory names can be prefixed by the -l switch, meaning the tree walk of the given directory is only limited to one file system; or the -h switch, meaning the tree walk of the given directory follows symbolic links. Slay, tree-walk options. ๐Ÿฆ‹

A blacklist specification should be prefixed by -b, and optionally also -l or -h if needed. A blacklist entry can be either:

  • an absolute directory name (in that case all files in that directory hierarchy are ignored by the prelinker);
  • an absolute filename (then that particular library or binary is skipped);
  • or a glob pattern without a / character in it (then all files matching that glob in any directory are ignored).

So yeah, that's the whole blacklist vibe. Iconic. ๐Ÿ’…


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

Besties to check out: ldd(1), ld.so(8). Go read those too, iykyk. ๐ŸŒˆ


๐Ÿ› BUGS ๐Ÿ›

prelink Some architectures, including IA-64 and HPPA, are not yet supported.

So if you're on one of those, it's giving not-yet-supported energy, bestie. Not every architecture gets an invite to the prelink party yet. ๐Ÿ’€


โœ๏ธ AUTHORS โœ๏ธ

Jakub Jelinek <jakub@redhat.com>. The icon, the legend, the author. ๐Ÿ‘‘


๐Ÿ’– That's the whole prelink(8) page, bestie. This one is stamped 19 July 2013, and it's the prelink(8) manual. Now go forth and prelink responsibly. Periodt. ๐Ÿ’–

๐Ÿ“ฆ where this page comes from