Typo
[linux_from_scratch_hints.git] / OLD / combreloc.txt
blob17f9c3e1b7b9f4066a39c27086b4260229f565b9
1 TITLE:          Setting up combreloc on recent binutils
2 LFS VERSION:    3.3+ (maybe earlier)
3 AUTHOR:         Zack Winkles <sativa93@bellsouth.net>
5 SYNOPSIS:
6         Configuring/tricking binutils to use the -z combreloc option
8 HINT:
9 Contents
11         * Introduction
12         * Methods
13         * Problems
15 Introduction
17    Recent versions of binutils (actually its ld) include a new option that
18    reaps the same loading inprovements as objprelink of KDE fame, but for
19    all programs compiled by it. As a general rule you can expect around 20%
20    to 30% faster loading times. I personally have had no problems compiling
21    *EVERYTHING* on my system with it (including gcc, glibc, etc).
23 Methods
25    Here's the real meat of it all. Even though all you really need to do is
26    to link the program with this option, it can be quite hard getting all of
27    your options passed down to ld. One particular example is gcc. To get it
28    to use the option on its libgcc_s.so binary you have to set about eight
29    environmental variables and edit a few Makefiles. But if you want to do it
30    that way the proper was is to set the LDFLAGS variable:
32         export LDFLAGS='-z combreloc'
34    should work. I'd estimate about 50% of packages actually recognize and use
35    that variable though. We don't want to stop there do we? Let's take it a
36    step further and set the CFLAGS variable too:
38         export CFLAGS='**YOUR_CFLAGS** -z combreloc'
39         export CXXFLAGS='**YOUR_CFLAGS** -z combreloc'
41    If you don't understand why I set CXXFLAGS too you have worse things to
42    worry about than loading times on a computer... Onward. Even then programs
43    like bzip2 won't be optimized. Let's take it further:
45         export CC='gcc -z combreloc'
46         export CXX='g++ -z combreloc'
48    Think that's good enough of a job? I sure don't. When compiling gcc it
49    doesn't care about any of your flags: it ignores them all and uses its
50    own tags and compilers. Here's the easiest/most aggressive method to do
51    this for your entire system. WARNING: All programs you compile with have
52    -z combreloc run on ld. There is no longer a way to use ld without the
53    option outside of calling ld.orig or removing the script and moving
54    ld.orig to ld (the reverse of the following instructions).
56         mv /usr/bin/ld /usr/bin/ld.orig &&
57         cat > /usr/bin/ld << "EOF"
58         #!/bin/sh
59         # Begin /usr/bin/ld
60         # Wrapper script to use -z combreloc option on all executables
61         # By: Zack Winkles
63         exec /usr/bin/ld.orig -z combreloc "$@"
65         # End /usr/bin/ld
66         EOF
67         chmod 755 /usr/bin/ld
69    Now you can unset CC, CFLAGS, and all the other stuff we did before in
70    the hint. Aren't you glad you read the whole hint ;). There's just one
71    last issue to address. When initially compiling the system and you're in
72    the static chroot'd environment, how do you get your stuff optimized then?
73    its pretty easy actually. Take the above instructions and modify every
74    instance of /usr/bin to /static/bin. Then even the static binutils will
75    optimize. Pretty easy ay?
77 Problems
79    So far I have never had a single problem with anything I compiled using
80    even the most aggressive method listed. The only thing I've noticed is
81    better performance. If you have any problems let me know and I'll try to
82    help you out.