VirtualBox

source: vbox/trunk/tools/linux.x86/kmodbuild/build-kernel.sh@ 92273

Last change on this file since 92273 was 78141, checked in by vboxsync, 6 years ago

tools/linux.x86/kmodbuild: Some clues. bugref:9172

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 16.2 KB
Line 
1#!/bin/bash
2# $Id: build-kernel.sh 78141 2019-04-16 02:32:16Z vboxsync $
3## @file
4# Script for build a linux kernel with a default configuration.
5#
6# This script assumes gcc-6, gcc-4.9 and gcc-3.3 are available on the system.
7#
8# For really old kernels make 3.80 and 3.76 will need to be built and put in
9# a specific place relative to the kernel sources.
10#
11# This script may patch the kernel source a little to work around issues with
12# newere binutils, perl, glibc and maybe compilers.
13#
14# It is recommended to use a overlayfs setup and kDeDup the kernel sources to
15# save disk space.
16#
17
18#
19# Copyright (C) 2019 Oracle Corporation
20#
21# This file is part of VirtualBox Open Source Edition (OSE), as
22# available from http://www.virtualbox.org. This file is free software;
23# you can redistribute it and/or modify it under the terms of the GNU
24# General Public License (GPL) as published by the Free Software
25# Foundation, in version 2 as it comes in the "COPYING" file of the
26# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
27# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
28#
29
30#
31# /etc/apt/sources.list clues:
32#
33# # for gcc-4.8
34# deb http://deb.debian.org/debian/ oldstable main contrib non-free
35# deb-src http://deb.debian.org/debian/ oldstable main contrib non-free
36#
37# # for gcc-6
38# deb http://deb.debian.org/debian/ stable main contrib non-free
39# deb-src http://deb.debian.org/debian/ stable main contrib non-free
40#
41# # for gcc 3.4.x
42# deb [ allow-insecure=yes ] http://archive.debian.org/debian/ lenny main contrib non-free
43# deb-src [ allow-insecure=yes ] http://archive.debian.org/debian/ lenny main contrib non-free
44#
45# # for gcc 3.3.x
46# deb [ allow-insecure=yes ] http://archive.debian.org/debian/ etch main contrib non-free
47# deb-src [ allow-insecure=yes ] http://archive.debian.org/debian/ etch main contrib non-free
48#
49# # for gcc 3.2.x
50# deb [ allow-insecure=yes arch=i386] http://archive.debian.org/debian/ woody main contrib non-free
51# deb-src [ allow-insecure=yes arch=i386 ] http://archive.debian.org/debian/ woody main contrib non-free
52#
53#
54# Clue for /etc/fstab:
55# overlay /mnt/bldlnx/amd64 overlay lowerdir=/mnt/big/virgin-lnx/,upperdir=/mnt/big/bldlnx/amd64,workdir=/mnt/big/workdir/bldlnx-amd64,noauto 0 0
56#
57
58if [ -z "${JOBS}" ]; then JOBS=42; fi
59
60#
61# The path argument.
62#
63if [ "$#" -lt "1" ]; then
64 echo "usage: build.sh <dir> [clean]"
65 exit 2
66fi
67
68set -e
69echo "********************************************************************************"
70echo "* $1"
71echo "********************************************************************************"
72set -x
73shopt -s extglob
74
75# Enter it.
76cd "$1"
77
78# Change the terminal title (ASSUMES xterm-like TERM).
79KERN_SUBDIR=`basename $1`
80export PS1="\$ ";
81echo -ne "\033]0;build.sh - ${KERN_SUBDIR}\007"
82
83# Derive the version from it.
84KERN_VER=`echo $1 | sed -e 's/^.*linux-\([0-9][0-9.]*\).*$/\1/'`
85case "${KERN_VER}" in
86 [0-9].[0-9]|[0-9].[0-9][0-9]|[0-9][0-9].[0-9]|[0-9][0-9].[0-9][0-9])
87 KERN_VER_3PLUS_DOTS="${KERN_VER}.0";;
88 *)
89 KERN_VER_3PLUS_DOTS=${KERN_VER};;
90esac
91echo "debug: KERN_VER=${KERN_VER} --> KERN_VER_3PLUS_DOTS=${KERN_VER_3PLUS_DOTS}"
92
93# Determin tool overrides.
94OVERRIDES=
95MAKE=/usr/bin/make
96case "${KERN_VER_3PLUS_DOTS}" in
97 4.9.*|4.1[0-7].*)
98 OVERRIDES="CC=gcc-6 CXX=g++-6"
99 ;;
100 2.6.3[789]*|3.*|4.[0-8].*)
101 OVERRIDES="CC=gcc-4.9 CXX=g++-4.9"
102 ;;
103 2.6.29*|2.6.3[0-9]*)
104 OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
105 ;;
106 2.6.[89]*|2.6.12[0-9]*|2.6.2[0-8]*)
107 OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
108 MAKE=../../make-3.80/installed/bin/make
109 ;;
110 2.6.*)
111 OVERRIDES="CC=gcc-3.3 CXX=g++-3.3"
112 MAKE=../../make-3.80/installed/bin/make
113 ;;
114esac
115echo "debug: OVERRIDES=${OVERRIDES} MAKE=${MAKE}"
116
117echo "${OVERRIDES}" > .bird-overrides
118ln -sf "${MAKE}" .bird-make
119
120# Done with arg #1.
121shift
122
123
124#
125# Apply patches for newer tools and stuff.
126#
127
128# perl --annoying
129if [ -f kernel/timeconst.pl ]; then
130 if patch --output /tmp/build.$$ -Np1 <<EOF
131--- a/kernel/timeconst.pl 2019-04-15 13:44:55.434946090 +0200
132+++ b/kernel/timeconst.pl 2019-04-15 13:57:29.330140587 +0200
133@@ -372,5 +372,5 @@
134 @val = @{\$canned_values{\$hz}};
135- if (!defined(@val)) {
136+ if (!@val) {
137 @val = compute_values(\$hz);
138 }
139 output(\$hz, @val);
140EOF
141 then
142 cp /tmp/build.$$ kernel/timeconst.pl
143 fi
144fi
145
146# binutils PLT32
147case "${KERN_VER_3PLUS_DOTS}" in
148 4.10.*|4.11.*|4.12.*|4.13.*|4.14.*|4.15.*|4.16.*)
149 if patch --output /tmp/build.$$ -Np1 <<EOF
150diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
151index 1f790cf9d38f..3b7427aa7d85 100644
152--- a/arch/x86/kernel/machine_kexec_64.c
153+++ b/arch/x86/kernel/machine_kexec_64.c
154@@ -542,6 +542,7 @@ int arch_kexec_apply_relocations_add(const Elf64_Ehdr *ehdr,
155 goto overflow;
156 break;
157 case R_X86_64_PC32:
158+ case R_X86_64_PLT32:
159 value -= (u64)address;
160 *(u32 *)location = value;
161 break;
162EOF
163then
164 cp /tmp/build.$$ arch/x86/kernel/machine_kexec_64.c
165 fi
166 case "${KERN_VER}" in
167 4.10.*|4.11.*|4.12.*|4.13.*)
168 if patch --output /tmp/build.$$ -Np1 <<EOF
169diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
170index da0c160e5589..f58336af095c 100644
171--- a/arch/x86/kernel/module.c
172+++ b/arch/x86/kernel/module.c
173@@ -191,6 +191,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
174 goto overflow;
175 break;
176 case R_X86_64_PC32:
177+ case R_X86_64_PLT32:
178 val -= (u64)loc;
179 *(u32 *)loc = val;
180 #if 0
181EOF
182 then
183 cp /tmp/build.$$ arch/x86/kernel/module.c
184 fi;;
185 **)
186 if patch --output /tmp/build.$$ -Np1 <<EOF
187diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
188index da0c160e5589..f58336af095c 100644
189--- a/arch/x86/kernel/module.c
190+++ b/arch/x86/kernel/module.c
191@@ -191,6 +191,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
192 goto overflow;
193 break;
194 case R_X86_64_PC32:
195+ case R_X86_64_PLT32:
196 if (*(u32 *)loc != 0)
197 goto invalid_relocation;
198 val -= (u64)loc;
199EOF
200 then
201 cp /tmp/build.$$ arch/x86/kernel/module.c
202 fi;;
203 esac
204 if patch --output /tmp/build.$$ -Np1 <<EOF
205diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
206index 5d73c443e778..220e97841e49 100644
207--- a/arch/x86/tools/relocs.c
208+++ b/arch/x86/tools/relocs.c
209@@ -770,9 +770,12 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym,
210 break;
211
212 case R_X86_64_PC32:
213+ case R_X86_64_PLT32:
214 /*
215 * PC relative relocations don't need to be adjusted unless
216 * referencing a percpu symbol.
217+ *
218+ * NB: R_X86_64_PLT32 can be treated as R_X86_64_PC32.
219 */
220 if (is_percpu_sym(sym, symname))
221 add_reloc(&relocs32neg, offset);
222EOF
223 then
224 cp /tmp/build.$$ arch/x86/tools/relocs.c
225 fi
226 if patch --output /tmp/build.$$ -Np1 <<EOF
227--- linux-4.15/tools/lib/subcmd/pager.c 2017-11-12 19:46:13.000000000 +0100
228+++ linux-4.17/tools/lib/subcmd/pager.c 2018-06-03 23:15:21.000000000 +0200
229@@ -30,10 +30,13 @@
230 * have real input
231 */
232 fd_set in;
233+ fd_set exception;
234
235 FD_ZERO(&in);
236+ FD_ZERO(&exception);
237 FD_SET(0, &in);
238- select(1, &in, NULL, &in, NULL);
239+ FD_SET(0, &exception);
240+ select(1, &in, NULL, &exception, NULL);
241
242 setenv("LESS", "FRSX", 0);
243 }
244EOF
245 then
246 cp /tmp/build.$$ tools/lib/subcmd/pager.c
247 fi
248 if patch --output /tmp/build.$$ -Np1 <<EOF
249--- linux-4.16/tools/lib/str_error_r.c 2019-04-15 06:04:50.978464217 +0200
250+++ linux-4.17/tools/lib/str_error_r.c 2018-06-03 23:15:21.000000000 +0200
251@@ -22,6 +22,6 @@
252 {
253 int err = strerror_r(errnum, buf, buflen);
254 if (err)
255- snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, %p, %zd)=%d", errnum, buf, buflen, err);
256+ snprintf(buf, buflen, "INTERNAL ERROR: strerror_r(%d, [buf], %zd)=%d", errnum, buflen, err);
257 return buf;
258 }
259EOF
260 then
261 cp /tmp/build.$$ tools/lib/str_error_r.c
262 fi
263 ;;
264esac
265
266# Undefined ____ilog2_NaN symbol:
267if [ -f include/linux/log2.h ]; then
268 case "${KERN_VER_3PLUS_DOTS}" in
269 4.10.*|4.[9].*)
270 if patch --output /tmp/build.$$ -Np1 <<EOF
271--- linux-4.10/include/linux/log2.h 2017-02-19 23:34:00.000000000 +0100
272+++ linux-4.11/include/linux/log2.h 2017-11-12 19:46:13.000000000 +0100
273@@ -15,14 +15,8 @@
274 #include <linux/types.h>
275 #include <linux/bitops.h>
276
277 /*
278- * deal with unrepresentable constant logarithms
279- */
280-extern __attribute__((const, noreturn))
281-int ____ilog2_NaN(void);
282-
283-/*
284 * non-constant log of base 2 calculators
285 * - the arch may override these in asm/bitops.h if they can be implemented
286 * more efficiently than using fls() and fls64()
287 * - the arch is not required to handle n==0 if implementing the fallback
288@@ -84,9 +78,9 @@
289 */
290 #define ilog2(n) \\
291 ( \\
292 __builtin_constant_p(n) ? ( \\
293- (n) < 1 ? ____ilog2_NaN() : \\
294+ (n) < 2 ? 0 : \\
295 (n) & (1ULL << 63) ? 63 : \\
296 (n) & (1ULL << 62) ? 62 : \\
297 (n) & (1ULL << 61) ? 61 : \\
298 (n) & (1ULL << 60) ? 60 : \\
299@@ -147,12 +141,9 @@
300 (n) & (1ULL << 5) ? 5 : \\
301 (n) & (1ULL << 4) ? 4 : \\
302 (n) & (1ULL << 3) ? 3 : \\
303 (n) & (1ULL << 2) ? 2 : \\
304- (n) & (1ULL << 1) ? 1 : \\
305- (n) & (1ULL << 0) ? 0 : \\
306- ____ilog2_NaN() \\
307- ) : \\
308+ 1 ) : \\
309 (sizeof(n) <= 4) ? \\
310 __ilog2_u32(n) : \\
311 __ilog2_u64(n) \\
312 )
313EOF
314 then
315 cp /tmp/build.$$ include/linux/log2.h
316 fi
317 ;;
318 esac
319fi
320
321# extern then static current_menu.
322if [ -f scripts/kconfig/lkc.h -a -f scripts/kconfig/mconf.c ]; then
323 case "${KERN_VER_3PLUS_DOTS}" in
324 2.6.1[0-9]*|2.6.2[0-9]*|2.6.3[0-9]*|2.6.4[0-9]*)
325 ;;
326 2.5.*|2.6.[012345678])
327 if patch --output /tmp/build.$$ -Np1 <<EOF
328--- linux-2.6.8/scripts/kconfig/mconf.c 2004-08-14 07:36:32.000000000 +0200
329+++ linux-2.6.8/scripts/kconfig/mconf.c 2019-04-15 15:52:42.143587966 +0200
330@@ -88,5 +88,5 @@
331 static struct termios ios_org;
332 static int rows = 0, cols = 0;
333-static struct menu *current_menu;
334+struct menu *current_menu;
335 static int child_count;
336 static int do_resize;
337EOF
338 then
339 cp /tmp/build.$$ scripts/kconfig/mconf.c
340 fi
341 ;;
342 esac
343fi
344
345# Incorrect END label in arch/x86/lib/copy_user_64.S
346case "${KERN_VER_3PLUS_DOTS}" in
347 2.6.2[456]*)
348 if patch --output /tmp/build.$$ -Np1 <<EOF
349--- linux-2.6.26/arch/x86/lib/copy_user_64.S 2019-04-15 16:21:49.475846822 +0200
350+++ linux-2.6.26/arch/x86/lib/copy_user_64.S 2019-04-15 16:21:50.883863141 +0200
351@@ -341,7 +341,7 @@
352 11: pop %rax
353 7: ret
354 CFI_ENDPROC
355-END(copy_user_generic_c)
356+END(copy_user_generic_string)
357
358 .section __ex_table,"a"
359 .quad 1b,3b
360EOF
361 then
362 cp /tmp/build.$$ arch/x86/lib/copy_user_64.S
363 fi
364 ;;
365 2.6.2[0123]*|2.6.19*)
366 if patch --output /tmp/build.$$ -Np1 <<EOF
367--- linux-2.6.23/arch/x86_64/lib/copy_user.S 2019-04-15 16:42:16.898006203 +0200
368+++ linux-2.6.23/arch/x86_64/lib/copy_user.S 2019-04-15 16:42:25.906109885 +0200
369@@ -344,7 +344,7 @@
370 11: pop %rax
371 7: ret
372 CFI_ENDPROC
373-END(copy_user_generic_c)
374+END(copy_user_generic_string)
375
376 .section __ex_table,"a"
377 .quad 1b,3b
378EOF
379 then
380 cp /tmp/build.$$ arch/x86_64/lib/copy_user.S
381 fi
382 ;;
383esac
384
385# Increase vdso text segment limit as newer tools/whatever causes it to be too large.
386if [ -f arch/x86_64/vdso/vdso.lds.S ]; then
387 if patch --output /tmp/build.$$ -Np1 <<EOF
388--- linux-2.6.23/arch/x86_64/vdso/vdso.lds.S 2019-04-15 17:20:27.567440594 +0200
389+++ linux-2.6.23/arch/x86_64/vdso/vdso.lds.S 2019-04-15 17:20:29.635463886 +0200
390@@ -28,5 +28,5 @@
391 .text : { *(.text) } :text
392 .text.ptr : { *(.text.ptr) } :text
393- . = VDSO_PRELINK + 0x900;
394+ . = VDSO_PRELINK + 0xa00;
395 .data : { *(.data) } :text
396 .bss : { *(.bss) } :text
397EOF
398 then
399 cp /tmp/build.$$ arch/x86_64/vdso/vdso.lds.S
400 fi
401fi
402
403# glibc PATH_MAX cleanup affect 2.6.21 and earlier:
404if [ -f scripts/mod/sumversion.c ]; then
405 case "${KERN_VER_3PLUS_DOTS}" in
406 2.6.[0-9]!([0-9])*|2.6.1[0-9]*|2.6.2[01]*)
407 if patch --output /tmp/build.$$ -Np1 <<EOF
408--- linux-2.6.21/scripts/mod/sumversion.c 2007-02-04 19:44:54.000000000 +0100
409+++ linux-2.6.21/scripts/mod/sumversion.c 2019-02-15 16:10:12.956678862 +0100
410@@ -7,4 +7,5 @@
411 #include <ctype.h>
412 #include <errno.h>
413 #include <string.h>
414+#include <linux/limits.h>
415 #include "modpost.h"
416EOF
417 then
418 cp /tmp/build.$$ scripts/mod/sumversion.c
419 fi
420 esac
421fi
422
423# Problem with "System too big" messages in 2.6.17 and earlier:
424if [ -f arch/x86_64/boot/tools/build.c ]; then
425 case "${KERN_VER_3PLUS_DOTS}" in
426 2.6.[0-9]!([0-9])*|2.6.1[0-7]*)
427 if patch --output /tmp/build.$$ -Np1 <<EOF
428--- linux-2.6.17/arch/x86_64/boot/tools/build.c 2006-01-03 04:21:10.000000000 +0100
429+++ linux-2.6.18/arch/x86_64/boot/tools/build.c 2007-02-04 19:44:54.000000000 +0100
430@@ -149,9 +149,7 @@
431 sz = sb.st_size;
432 fprintf (stderr, "System is %d kB\n", sz/1024);
433 sys_size = (sz + 15) / 16;
434- /* 0x40000*16 = 4.0 MB, reasonable estimate for the current maximum */
435- if (sys_size > (is_big_kernel ? 0x40000 : DEF_SYSSIZE))
436- die("System is too big. Try using %smodules.",
437- is_big_kernel ? "" : "bzImage or ");
438+ if (!is_big_kernel && sys_size > DEF_SYSSIZE)
439+ die("System is too big. Try using bzImage or modules.");
440 while (sz > 0) {
441 int l, n;
442EOF
443 then
444 cp /tmp/build.$$ arch/x86_64/boot/tools/build.c
445 fi
446 esac
447fi
448
449# Problem with incorrect mov sizes for segments in 2.6.11 and earlier:
450if [ -f arch/x86_64/kernel/process.c ]; then
451 case "${KERN_VER_3PLUS_DOTS}" in
452 2.6.[0-9]!([0-9])*|2.6.1[01]*)
453 if patch --output /tmp/build.$$ -lNp1 <<EOF
454--- linux-2.6.11/arch/x86_64/kernel/process.c 2005-03-02 08:38:10.000000000 +0100
455+++ linux-2.6.11/arch/x86_64/kernel/process.c 2019-02-15 16:57:47.653585327 +0100
456@@ -390,10 +390,10 @@
457 p->thread.fs = me->thread.fs;
458 p->thread.gs = me->thread.gs;
459
460- asm("movl %%gs,%0" : "=m" (p->thread.gsindex));
461- asm("movl %%fs,%0" : "=m" (p->thread.fsindex));
462- asm("movl %%es,%0" : "=m" (p->thread.es));
463- asm("movl %%ds,%0" : "=m" (p->thread.ds));
464+ asm("movw %%gs,%0" : "=m" (p->thread.gsindex));
465+ asm("movw %%fs,%0" : "=m" (p->thread.fsindex));
466+ asm("movw %%es,%0" : "=m" (p->thread.es));
467+ asm("movw %%ds,%0" : "=m" (p->thread.ds));
468
469 if (unlikely(me->thread.io_bitmap_ptr != NULL)) {
470 p->thread.io_bitmap_ptr = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
471@@ -456,11 +456,11 @@
472 * Switch DS and ES.
473 * This won't pick up thread selector changes, but I guess that is ok.
474 */
475- asm volatile("movl %%es,%0" : "=m" (prev->es));
476+ asm volatile("movw %%es,%0" : "=m" (prev->es));
477 if (unlikely(next->es | prev->es))
478 loadsegment(es, next->es);
479
480- asm volatile ("movl %%ds,%0" : "=m" (prev->ds));
481+ asm volatile ("movw %%ds,%0" : "=m" (prev->ds));
482 if (unlikely(next->ds | prev->ds))
483 loadsegment(ds, next->ds);
484EOF
485 then
486 cp /tmp/build.$$ arch/x86_64/kernel/process.c
487 fi
488 esac
489fi
490
491
492#
493# Other arguments.
494#
495while [ "$#" -gt 0 ];
496do
497 case "$1" in
498 clean)
499 time ./.bird-make ${OVERRIDES} -j ${JOBS} clean
500 ;;
501
502 *)
503 echo "syntax error: $1" 1>&2
504 ;;
505 esac
506 shift
507done
508
509#
510# Configure.
511#
512if [ -f .config ]; then
513 mv -f .config .bird-previous-config
514fi
515nice ./.bird-make ${OVERRIDES} -j ${JOBS} defconfig
516case "${KERN_VER_3PLUS_DOTS}" in
517 2.[012345].*|2.6.[0-9]!([0-9])*|2.6.[12][0-9]*)
518 ;;
519 *)
520 echo CONFIG_DRM_TTM=m >> .config;
521 echo CONFIG_DRM_RADEON=m >> .config
522 echo CONFIG_DRM_RADEON_UMS=y >> .config
523 echo CONFIG_DRM_RADEON_USERPTR=y >> .config
524 echo CONFIG_DRM_RADEON_KMS=y >> .config
525 ;;
526esac
527case "${KERN_VER_3PLUS_DOTS}" in
528 2.4.*) ;;
529 4.2[0-9].*|4.1[789].*|[5-9].*)
530 nice ./.bird-make ${OVERRIDES} syncconfig;;
531 *) nice ./.bird-make ${OVERRIDES} silentoldconfig;;
532esac
533if [ -f .bird-previous-config ]; then
534 if cmp -s .config .bird-previous-config; then
535 mv -f .bird-previous-config .config
536 fi
537fi
538
539#
540# Build all.
541#
542if time nice ./.bird-make ${OVERRIDES} -j ${JOBS} all -k; then
543 rm -f .bird-failed
544 echo -ne "\033]0;build.sh - ${KERN_SUBDIR} - done\007"
545else
546 touch .bird-failed
547 echo -ne "\033]0;build.sh - ${KERN_SUBDIR} - failed\007"
548 exit 1
549fi
550
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette