Prelink/ko

이 안내서에서는 Portage 2.0.46 이상의 버전에서 지원하는 prelink를 어떻게 사용할 수 있는지 알려줍니다.

Prelink가 무엇이고, 어떻게 도움을 받을 수 있나요?
대부분의 일반 프로그램은 공유 라이브러리를 활용합니다. 이들 공유 라이브러리는 실행 시간에 메모리로 불러와야 하며 다양한 심볼 참조를 해석해야 합니다. 대부분의 작은 프로그램은 동적 연결을 매우 빠르게 처리합니다. 그러나 C++로 작성한 프로그램이고 수많은 라이브러리 의존성을 지녔다면, 동적 연결에 상당한 시간이 필요할 수 있습니다.

대부분의 시스템에서는, 라이브러리가 자주 바뀌지 않으며 프로그램을 실행할 때, 프로그램과의 연결 처리가 동시에 일어납니다. Prelink는 실행 파일에 미리 연결하는 것과 같이 실행시 연결 및 라이브러리 저장을 처리하는 장점을 취합니다.

선 링크는 프로그램의 시작 시간을 줄일 수 있습니다. 예컨대, 보통의 KDE 프로그램을 불러오는 시간은 최대 50% 가량 줄일 수 있습니다. 이 과정의 관리상 실행 파일에 미리 연결하기 위해 업그레이드한 라이브러리를 매번 선연결 처리를 위해 prelink를 다시 실행하기만 하면 됩니다.

요약

 * Prelinking is done via a program called, surprisingly,  . It changes the binary to make it start faster.
 * If an application's dependent libraries change after you have prelinked it, you need to re-prelink the application, otherwise you lose the speed advantage. This is to say, everytime you update a package via portage that updates libraries, they need to be re-prelinked.
 * The change to the binary is fully reversible.  has an undo function.
 * Current versions of Portage can handle, via , the changing MD5sums and mtimes of the binaries.
 * You do not need to set  in your  file; Portage will automatically support prelink if it can find the prelink binary.

Installing the Programs
First you need to install the  tool. The emerge process automatically verifies that your system can prelink safely.

A number of people get errors in emerging prelink because of the failed tests. The tests were put in for safety reasons, prelink's behavior is undefined if you disable them. The emerge errors are usually only dependent on the core packages; binutils, gcc, and glibc. Try re-emerging those packages in that order.

If you have a set of steps that reproduces the emerge error on another system please check Bugzilla and create a bug report if it has not already been reported.

Preparing your System
Also make sure that you do not have -fPIC set in your CFLAGS/CXXFLAGS. If you do, you will need to rebuild your entire system without.

설정
Running  will generate the  file that tells  which files to prelink.

Unfortunately you cannot prelink files that were compiled by old versions of binutils. Most of these applications come from pre-compiled, binary only packages which are installed in. Making the following file will tell prelink not to attempt to prelink them.

/etc/env.d/60prelink

prelink 사용법
I use the following command to prelink all the binaries in the directories given by.

Prelink Cron Job
and later install a cron job in. To enable it, edit the configuration file. This will run prelink daily in the background, as needed, saving you running the command manually.

Speeding Up KDE After Prelinking
KDE's loading time can be greatly reduced after prelinking. If you inform KDE that it has been prelinked it will disable the loading of  (as it isn't required anymore) which speeds up KDE even more.

Set  in  to inform KDE about the prelinking.

Removing prelink
If you ever change your mind about prelinking, before you unmerge prelink, you'll first need to remove the prelink cronjob from and. Next, you'll have to remove prelinking from all binaries:

Finally, unmerge the  package itself:

"Cannot prelink against non-PIC shared library"
The cause of this problem is from badly compiled shared libraries that were compiled without the -fPIC gcc option for all their object files.

Here are the libraries that haven't been fixed or cannot be fixed:


 * The libraries in the wine package, including winex. Prelinking wouldn't speed up MS Windows executables anyway.
 * The library in media-video/mjpegtools,.
 * Nvidia OpenGl libraries, . Due to performance reasons they were compiled without PIC support.

If your problem library was not listed please report it with, preferably, a patch to add  to the relevant CFLAGS.

When I prelink my system some static binaries don't work anymore
Where glibc is concerned, there is no such thing as a 100% static binary. If you statically compile a binary with glibc, it may still depend on other system files. Below is an explanation by Dick Howell,

"I suppose the idea is that everything will be in the downloaded file, so nothing depends on the local libraries on the target system. Unfortunately with Linux, and I think anything else using GLIBC, this still isn't quite true. There's this "libnss" (name service switch, some people seem to call it network security system) which provides functions for accessing various databases for authentication, network information, and other things. It's supposed to make application programs independent of the separately configured actual network environment of the machine. A nice idea, but changes to GLIBC can lead to problems loading it. And you can't statically link "libnss", since it is configured for each machine individually. The problem comes, I think, mainly from statically linking other GLIBC libraries, notably "libpthread", "libm", and "libc", from which come incompatible calls to "libnss" functions."

Prelink aborts with "prelink: dso.c:306: fdopen_dso: Assertion `j
k' failed." ===

This a known problem, kindly diagnosed here. Prelink cannot cope with UPX-compressed executables. As of prelink-20021213 there is no fix except to hide the executables while you are prelinking. See the section above for an easy way to do this.

I use grsecurity and it seems that prelinking doesn't work.
In order to prelink on a system with grsecurity using a randomized mmap base, it is necessary to turn "randomized mmap base" OFF for. This can be done with the  utility, but it must be done when the file is not in use (f.i. boot from a rescue CD).

Prelink fails with error "prelink: Can't walk directory tree XXXX: Too many levels of symbolic links"
Your symlinks are nested too deeply. This happens when a symlink points to itself. For example, is the most common. To fix this, you can find the symlink manually or use the utility provided by the  package:

More details can be found at Bugzilla and this forum post.

Conclusion
Prelinking can drastically speed up the start up times for a number of large applications. Support is built into Portage. Prelinking is also safe as you can always undo the prelinking for any binary if you come across any problems. Just remember that when you update glibc or other libraries that you prelinked with, you need to rerun ! In short good luck!

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Stefan Jones
 * John P. Davis
 * Jorge Paulo
 * Sven Vermeulen
 * Erwin
 * nightmorph