2.4.36-stable kernel tree
修订版 | 26082011bfab9e5f2f8200aee41818824b3d20fe (tree) |
---|---|
时间 | 2008-09-07 06:17:02 |
作者 | Willy Tarreau <w@1wt....> |
Commiter | Willy Tarreau |
doc: explain how to build a suitable gcc in Documentation/using-newer-gcc.txt
Since many people are using recent distros which do not ship a compatible
gcc anymore, here's a procedure explaining in details how to build an older
gcc to build kernel 2.4.
Signed-off-by: Willy Tarreau <w@1wt.eu>
@@ -91,7 +91,12 @@ The Red Hat gcc 2.96 compiler subtree can also be used to build this tree. | ||
91 | 91 | You should ensure you use gcc-2.96-74 or later. gcc-2.96-54 will not build |
92 | 92 | the kernel correctly. |
93 | 93 | |
94 | -gcc 4 is not supported. | |
94 | +gcc 3.3 and 3.4 are both known to work well. gcc 4.0 and 4.1 also work on | |
95 | +a several architectures (i386, x86_64, ppc, sparc, sparc64, alpha). Other | |
96 | +archs will not work. Versions 4.2 and onwards are not supported anymore. | |
97 | +Supporting them would require massive in-depth changes which will add a | |
98 | +lot of bugs and might break older compilers. If you don't have any gcc | |
99 | +below 4.2, check Documentation/using-newer-gcc.txt for instructions. | |
95 | 100 | |
96 | 101 | In addition, please pay attention to compiler optimization. Anything |
97 | 102 | greater than -O2 may not be wise. Similarly, if you choose to use gcc-2.95.x |
@@ -0,0 +1,187 @@ | ||
1 | +Building older versions of GCC compatible with Linux Kernel 2.4 | |
2 | +=============================================================== | |
3 | + | |
4 | + | |
5 | +This document explains how to build an older supported version of the GCC | |
6 | +compiler from a distribution which only offers incompatible recent versions. | |
7 | + | |
8 | + | |
9 | +Context | |
10 | +======= | |
11 | + | |
12 | +When Linux 2.4.0 was released in early 2001, GCC 2.95.2 was mainstream and | |
13 | +GCC 2.91.66 was still widely used. The GCC development model was evolving | |
14 | +and still confused. Since then, GCC has evolved a lot and stabilized. New | |
15 | +versions are regularly released, and some old features from the early code | |
16 | +get deprecated then removed. | |
17 | + | |
18 | +The kernel heavily relies on GCC's capabilities and behaviour. Some of the | |
19 | +code in Linux looks strange but is in fact intended to workaround early GCC | |
20 | +bugs. For these reasons, almost every new major GCC release breaks the kernel | |
21 | +build process. GCC 3.4 was a real pain to introduce as it required a lot of | |
22 | +rewriting in sensible areas, and GCC 4 required a lot of work, though this | |
23 | +work was less complicated thanks to the cleanup efforts invested in GCC 3.4. | |
24 | + | |
25 | +Starting with GCC 4.2, the output code randomly fails depending on section | |
26 | +ordering, which itself depends on the declaration order of functions, module | |
27 | +parameters and many other things. The nasty part is that the code builds but | |
28 | +randomly fails at runtime, so it is almost impossible to fix it and ensure | |
29 | +that everything works, especially in the drivers area where most of the | |
30 | +problems lie. | |
31 | + | |
32 | +As of 2008, GCC 4.3.2 is advertised as the current release and 4.2 the previous | |
33 | +release. Most distributions have been shipping with 4.2 and 4.3 for some time, | |
34 | +so building Linux 2.4 on a recent distribution has become a real problem for | |
35 | +users who still have to support kernel 2.4 on servers, firewalls or any other | |
36 | +system. | |
37 | + | |
38 | + | |
39 | +Solution : the two-minutes process | |
40 | +================================== | |
41 | + | |
42 | +If it is not possible to adapt the kernel to GCC, let's adapt GCC to the | |
43 | +kernel. We're lucky, building GCC to build just a kernel is not hard and | |
44 | +is rather fast. I call that a two-minutes process because building an | |
45 | +older GCC takes about 1 minute, and the kernel with that GCC also takes | |
46 | +one minute. | |
47 | + | |
48 | +First, you have to select which version of GCC you want to build your kernel | |
49 | +with. Here are some comments on possible versions : | |
50 | + | |
51 | + - 2.95.3 : very well tested for the kernel, builds kernels very fast, | |
52 | + requires a lot of patches and is rather hard to build.. | |
53 | + | |
54 | + - 3.0 : very buggy, avoid it. | |
55 | + | |
56 | + - 3.1 & 3.2 : apparently less buggy but rarely used so bugs might have | |
57 | + remained unnoticed. | |
58 | + | |
59 | + - 3.3 : used and tested for a long time. A bit slow but easy to build. | |
60 | + | |
61 | + - 3.4 : was recently introduced, received less testing, though seems | |
62 | + OK. Builds kernels faster than 3.3, and is easy to build too. | |
63 | + | |
64 | + - 4.0 & 4.1 : received little testing, particularly slow but may produce | |
65 | + smaller kernels when compiled with -Os. | |
66 | + | |
67 | +Always take the last maintenance version of a compiler (eg: 3.4.6 for 3.4). | |
68 | + | |
69 | +For best reliability and less hassle, I tend to recommend GCC 3.3.6. For | |
70 | +improved build times (about 30% lower) and improved kernel performance, I'd | |
71 | +recommend 3.4.6. It tends to produce more efficient code on i386, but has | |
72 | +had a long history of causing annoyances with inline declarations. It seems | |
73 | +OK though, and I build all my kernels with it. We'll assume 3.4 is used for | |
74 | +the rest of this document, though what is described will work with 3.3 to | |
75 | +4.1 unless stated otherwise. | |
76 | + | |
77 | + | |
78 | +Instructions | |
79 | +============ | |
80 | + | |
81 | +1) Download gcc sources from the nearest mirror | |
82 | +----------------------------------------------- | |
83 | + | |
84 | +Find a mirror address here : [ http://gcc.gnu.org/mirrors.html ] or download | |
85 | +from this directory : | |
86 | + | |
87 | + ftp://ftp.gnu.org/pub/gnu/gcc/gcc-3.4.6/ | |
88 | + | |
89 | +Get gcc-core-3.4.6.tar.bz2. It only contains the C compiler, which is what you | |
90 | +want. | |
91 | + | |
92 | +2) Prepare your build environment | |
93 | +--------------------------------- | |
94 | + | |
95 | +Create a temporary directory where you'll extract the sources. Don't build on | |
96 | +NFS, it may be slow. Use /tmp if you want. You'll need about 150 MB of free | |
97 | +space. You'll have to extract the sources in that new directory, and create a | |
98 | +temporary build directory aside it : | |
99 | + | |
100 | + $ mkdir /tmp/gcc-build | |
101 | + $ cd /tmp/gcc-build | |
102 | + $ tar jxf /tmp/gcc-core-3.4.6.tar.bz2 | |
103 | + $ mkdir build | |
104 | + | |
105 | +3) Configure gcc | |
106 | +---------------- | |
107 | + | |
108 | +You don't want your new gcc to conflict with the one already in place. I | |
109 | +recommend simply prefixing it with "kernel-", and not installing it in | |
110 | +/usr/bin, but rather /opt/kgcc/bin or anywhere else (/usr/local/bin will be | |
111 | +used by default). I recommend choosing a place you already have in your PATH | |
112 | +(such as the default /usr/local/bin), so that you don't have to pass the full | |
113 | +path to the binary when building. | |
114 | + | |
115 | + $ cd /tmp/gcc-build/build | |
116 | + $ ../gcc-3.4.6/configure --disable-locale --disable-shared --disable-nls \ | |
117 | + --enable-languages=c \ | |
118 | + --prefix=/opt/kgcc --program-prefix=kernel- | |
119 | + | |
120 | +If you're using GCC 3.3, you may see strange messages indicating that some | |
121 | +programs were not found (eg: kernel-objdump). Simply ignore them. | |
122 | + | |
123 | +Note that you can set a lot of options, even use it as a cross-compiler. While | |
124 | +very frequent, such a build will not be covered by this document. | |
125 | + | |
126 | +4) Build GCC | |
127 | +------------ | |
128 | + | |
129 | +Both GCC 3.3 and 3.4 support parallel building, which reduces build time on SMP | |
130 | +systems : | |
131 | + | |
132 | + $ make -j 4 | |
133 | + | |
134 | +If the build fails here because of some options you added above, you'll have to | |
135 | +remove the build dir and recreate it. | |
136 | + | |
137 | +5) Install your new GCC | |
138 | +----------------------- | |
139 | + | |
140 | +The binaries may be a bit big, but you can strip them. Both GCC 3.3 and 3.4 | |
141 | +support a trick on the command line during the installation process, which | |
142 | +consists in passing the "-s" flag to "install" : | |
143 | + | |
144 | + $ sudo make install INSTALL_PROGRAM='${INSTALL} -s' | |
145 | + | |
146 | +It will be installed under the directory referred to by the "prefix" option | |
147 | +above, or /usr/local/bin if none was specified : | |
148 | + | |
149 | + $ ls -l /opt/kgcc/bin/kernel-gcc | |
150 | + -rwxr-xr-x 3 root root 73124 Sep 6 22:45 /opt/kgcc/bin/kernel-gcc | |
151 | + | |
152 | + $ /opt/kgcc/bin/kernel-gcc -v | |
153 | + Reading specs from /tmp/gcc-3.4.6-build/tmp-inst/opt/kgcc/bin/... | |
154 | + Configured with: ../gcc-3.4.6/configure --disable-shared --disable-... | |
155 | + Thread model: posix | |
156 | + gcc version 3.4.6 | |
157 | + | |
158 | +6) Using your new compiler | |
159 | +-------------------------- | |
160 | + | |
161 | +The compiler just has to be passed to "make" via the "CC" variable for all | |
162 | +commands : | |
163 | + | |
164 | + $ make CC=/opt/kgcc/bin/kernel-gcc -j 4 dep bzImage modules modules_install | |
165 | + | |
166 | + or more simply, when you have it in your path : | |
167 | + | |
168 | + $ make CC=kernel-gcc -j 4 dep bzImage modules modules_install | |
169 | + | |
170 | + | |
171 | +Conclusion | |
172 | +========== | |
173 | + | |
174 | +Building an older GCC on to build an older kernel on a newer machine is not | |
175 | +really hard. It becomes harder when you have to cross-build (eg: you're | |
176 | +building on a 64-bit machine for a 32-bit one). But for this, I would recommend | |
177 | +that you check the excellent "crosstool" utility from Dan Kegel. It supports a | |
178 | +wide variety of compilers, contains a lot of fixes and will do all the hard | |
179 | +patching and configuration work for any combination you want or need. | |
180 | + | |
181 | + | |
182 | +Suggestions and comments | |
183 | +======================== | |
184 | + | |
185 | +If you find mistakes or want to send comments about this document, please mail | |
186 | +me at <w@1wt.eu>. | |
187 | + |