Linux Process prelink

Source: Internet
Author: User
Tags configuration settings wrappers
What is prelink? What can it do for me?

Many applications use the shared library. when these programs are executed, the shared function library is read into the memory and linked with the symbol (Symbol) used in the program. for most small programs, such dynamic connections are usually very fast. however, for C ++ programs that depend on a large number of function libraries, Dynamic Linking may take a lot of time.

In most systems, the function library is not often changed, and the linking actions performed every time a program is executed are identical. prelink uses this, link the program to the library and record it in the execution file to achieve the effect of "pre-linking. you need the ld-linux.so in glibc to link, to be able to recognize the "pre-linked" record needs> = glibc-2.3.1-r2.

"Pre-link" can save the application startup time. taking a typical KDE program as an example, the program's read time can be reduced by as much as 50%. the only necessary maintenance is that the prelink must be executed again whenever the function library to which the execution file is linked is updated.

Summary

* We can use a program called prelink to perform "pre-link". It can modify the content of the execution file to shorten the start time.
* If the dependent library of an application that has been "prelinked" changes, you must re-"pre-linked" the application. Otherwise, the increase in speed will continue to become ineffective. that is to say, every time you use portage to update some kits and update some libraries, these libraries must be re-"pre-linked.
* Changes to the execution file are completely reversible. prelink has the restoration function.
* The New portage can cope with changes caused by prelink to the md5sum and mtime of the execution file.
* You Need A glibc-2.3.1-r2 or updated version, as well as the binutils-2.13.90.0.xx or updated version of the compiled execution files.

2. Set prelink

Install the required Program

Note: We assume that your system is a Gentoo-1.4 and is compiled using a gcc-3.2 and a later version of The binutils-2.13.90.0.xx so that the compiled execution file can be "prelinked ".

Warning you must have installed a glibc-2.3.1-r2 or an updated version, or prelink will mess up your executable!

Update your portage tree first, because most of the programs that need to be used are new, and new error fixes are often added.

Code 2.1: update your portage tree

# Emerge sync

Next, confirm that you have installed portage-2.0.46 or the latest version. in this way, the portage can recognize the execution files that have been "pre-linked" and be correctly removed only when the user wants to reinstall them. this is because "pre-linking" will change the md5sum value of the execution file.

Code 2.2: Ensure the portage version

# Emerge "> = portage-2.0.46"

Now you can start to install the "pre-link" tool. The emerge program can automatically test whether your system can perform "pre-link" securely and normally ".

Code 2.3: Install prelink

# Emerge prelink

Many people encounter test failure errors when installing prelink. these tests are put for security reasons. If you close these tests, prelink behavior cannot be guaranteed. most of these errors are caused by these core kits: binutils, GCC, and glibc. try to reinstall these kits in the above Order.

Note: Tips: If you are trying to manually compile and test prelink (. /configure; Make; make check). You can check *. log files, which may give you some useful clues.

If you can develop a set of steps to reproduce the emerge error on multiple systems, please email Stefan Jones.

Configuration Settings

Portage will automatically generate the/etc/prelink. conf file to tell prelink which files need to be "prelinked ".

Unfortunately, you cannot "pre-link" the old version of binutils program. most of these are from pre-compiled and the execution files are installed in/opt. write the following files to inform prelink not to "pre-link" them.

Code 2.4:/etc/env. d/99 prelink

Prelink_path_mask = "/OPT"

Note: You can use colons to separate more directories in this list.

3. Perform "pre-connection"

Prelink usage

We can use the following commands to "pre-link" All execution files listed in the/etc/prelink. conf directory.

Code 3.1: Pre-link the file in the list

# Prelink-afmr

Warning some people find that if you "pre-link" All execution files on the system when the disk space is tight, your execution files may be truncated, which will cause your system to crash. you can use file or readelf to check the status of the execution file. alternatively, DF-H is used to check the remaining space of the hard disk before "pre-linking.
Explanation of each option:
-A "all": "pre-linking" All execution files ".
-F force prelink to re-execute the file "pre-link" has been performed "pre-link. this option is added because prelink suspends the execution when it sees the "pre-link" execution file, even if the dependent library has been changed.
-M saves Virtual Address allocation. this option is required if you have a truck's function library that requires "pre-linking. (Note: The original virtual memory space is incorrect. The virtual address space is correct .)
-R random-Address Allocation with random numbers, which improves security against buffer overflow attacks.

Note: For more details about options, see man prelink.

4. Known Problems and Solutions

"Cannot prelink against non-pic shared library"

This problem is caused by the function library that does not use the-fpic gcc option to compile all object files.

The following is a problem library and the corresponding suite that needs to be re-installed when you encounter the above problems.

Code 4.1: corrected

// To the orbit library,/usr/lib/libiiop. so.0.5.17
# Emerge "> = sys-apps/tcp-wrappers-7.6-r4" orbit // For zlib library,/usr/lib/libz. so.1.1.4
# Emerge "> = sys-libs/zlib-1.1.4" // For svgalib,/usr/lib/libsvga. So. xx
# Emerge "> = media-libs/svgalib-1.9.16" // For the xfree OpenGL library, libglu. so.1
# Emerge "> = x11-base/xfree-4.2.1-r2" // For Libpcap. so.0.6
# Emerge "> = net-libs/libpcap-0.7.1-r2" // The LCMS library,/usr/lib/liblcms. so.1
# Emerge "> = media-libs/lcms-1.09"

Note: Many function libraries are statically linked to zlib and/or TCP-wrappers, so install them first and reinstall the problem library.

If you encounter problems in "pre-linking" QT/Kde, first try updating to> = x11-base/xfree-4.2.1-r2 with> = x11-libs/qt-3.1.0-r1 suite. if QT still does not work, you can try adding myconf = "-no-xinerama $ {myconf}" to the ebuild file of QT to compile QT that does not support xinerama.

Here are some function libraries that have not been corrected or cannot be corrected:

* Winex is no exception to the function library in wine kit, but "pre-linking" would not be able to accelerate the MS Windows Executable.
* Media-Video/m1_tools Library/usr/lib/liblavfile-1.6.so.0.

If your problem library is not in the list, please pay off. It is best to attach a patch file that matches cflags with the-FPIC option.

A file is aborted when it is pre-linked, such as "1631 aborted ...."

You need to add the-F parameter to prelink. That is to say, if you want to re-"pre-link" the entire system, use prelink-AF.

"<File Name>: Error while loading shared libraries: Unexpected reloc type ..."

This error was fixed in sys-libs/glibc-2.3.1-r2 at. If you are still using the old version, reinstall glibc.

It is known that prelink-u-a-m; prelink-a-m may also be useful. If all these methods fail, prelink-u <File>.

My NVIDIA OpenGL library has a problem.

The accelerated OpenGL library in the NVIDIA-Glx kit is compiled in a non-standard way, So prelink will issue a warning. there is nothing to worry about, and no one except NVIDIA can fix it. if you do not need 3D acceleration, you can switch back to the libgl built in xfree at any time. so. the xfree NVIDIA driver works properly.

After I "pre-link" the entire system, some static link execution files will not change.

For glibc, there is no 100% static link execution file. if you use glibc to statically compile an execution file, the execution file may depend on other system files. the following is the explanation of Dick Howell.

"I think your idea is that all dependent libraries will be in the downloaded file ), therefore, it does not depend on any local library. however, unfortunately, this idea is incorrect for Linux or even for any system that uses glibc. there is something called "libnss" (name service is selected as name service switch, or someone calls it network security system, network security system), which provides some processing and authentication databases, network Information and some other functions. it is designed to allow applications to adapt directly to different network environments. this is a clever design, but using glibc of different systems may cause problems with its loading. however, it varies according to different system settings, so you cannot perform static connections on it. I think the problem is that the program statically links the glibc library of different systems, mainly "libpthread", "libm", "libc ", these libraries call incompatible functions for "libnss."

Prelink sends "prelink: DSO. C: 306: fdopen_dso: assertion 'J = K' failed." And stops

This is a known issue. Here is a friendly explanation. prelink cannot process execution files compressed by UPX. until the prelink-20021213 has not been corrected, you can only "pre-link" these compressed execution files hidden. you can refer to the Configuration Settings section above to simply complete this task.

I use grsecurity and "pre-linking" does not seem to work.

If you want to use "pre-linking" on a system that uses grsecurity to make MMAP () base addresses out of number (randomized MMAP () base), you have to put/lib/ld-2.3. *. so's "randomized MMAP () base" setting is disabled. you can use the chpax utility to complete this action, but this must be performed only when this file is not in use. (For example, use a rescue CD to start the system)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.