3 # Copyright (C) 2016-2019 Michael Jeanson <mjeanson@efficios.com>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 platforms
=${platforms:-}
22 # Derive arch from label if it isn't set
23 if [ -z "${arch:-}" ] ; then
24 # Labels may be platform specific, eg. jammy-amd64, deb12-armhf
25 regex
='[[:alnum:]]+-([[:alnum:]]+)'
26 if [[ "${platforms}" =~
${regex} ]] ; then
27 arch
="${BASH_REMATCH[1]}"
33 cross_arch
=${cross_arch:-}
35 kgitrepo
=${kgitrepo:-}
36 mversion
=${mversion:-}
37 mgitrepo
=${mgitrepo:-}
44 # Kernel version compare functions
46 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ]
50 # shellcheck disable=SC2015
51 [ "$1" = "$2" ] && return 1 || verlte
"$1" "$2"
55 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ]
59 # shellcheck disable=SC2015
60 [ "$1" = "$2" ] && return 1 || vergte
"$1" "$2"
63 git_clone_modules_sources
() {
64 mkdir
-p "$MODULES_GIT_DIR"
66 # If the version starts with "refs/", checkout the specific git ref, otherwise treat it
68 if [ "${mversion:0:5}" = "refs/" ]; then
69 git clone
--no-tags --depth=1 "${mgitrepo}" "$MODULES_GIT_DIR"
70 (cd "$MODULES_GIT_DIR" && git fetch origin
"${mversion}" && git checkout FETCH_HEAD
)
72 git clone
--no-tags --depth=1 -b "${mversion}" "${mgitrepo}" "$MODULES_GIT_DIR"
76 # Checkout a shallow kernel tree of the specified tag
77 git_clone_linux_sources
() {
78 mkdir
-p "$LINUX_GIT_DIR"
79 git clone
--depth=1 -b "${ktag}" --reference "$LINUX_GIT_REF_REPO_DIR" "${kgitrepo}" "$LINUX_GIT_DIR"
83 # Export the kernel sources from the git repo
84 git_export_linux_sources
() {
86 git archive
"${ktag}" |
tar -x -C "$LINUX_SRCOBJ_DIR"
90 # Upload the tar archive to the object store
91 upload_archive_obj
() {
92 s3cmd
-c "$WORKSPACE/.s3cfg" put
"$WORKSPACE/$obj_name" "$obj_url_prefix/"
93 rm -f "$WORKSPACE/$obj_name"
97 extract_archive_obj
() {
98 tar -xf "$WORKSPACE/$obj_name" -C "$LINUX_OBJ_DIR" -I pbzip2
99 rm -f "$WORKSPACE/$obj_name"
105 tar -cf "$WORKSPACE/$obj_name" -I pbzip2 .
112 IFS
=: read -r -a path_array
<<< "$PATH"
113 while read -r gcc
; do
115 done < <(find "${path_array[@]}" -maxdepth 1 -regex '.*/gcc-[0-9\.]+$' -printf '%f\n' |
sort -t- -k2 -V -r)
119 # Find the most recent GCC version supported by the kernel sources
123 cd "$LINUX_SRCOBJ_DIR"
125 kversion
=$
(make -s kernelversion
)
129 for cc
in $
(list_gccs
) ; do
130 if "${CROSS_COMPILE:-}${cc}" -I include
/ -D__LINUX_COMPILER_H -D__LINUX_COMPILER_TYPES_H -E include
/linux
/compiler-gcc.h
; then
131 cc_version
=$
(echo "${cc}" | cut
-d'-' -f2)
132 if { verlt
"${kversion}" "5.17"; } && { vergt "${cc_version}" "11"; } ; then
133 # Using gcc-12+ with '-Wuse-after-free' breaks the build of older
134 # kernels (in particular, objtool). Some releases on LTS
135 # branches between 4.x and 5.15 can be built with gcc-12.
136 # @see https://lore.kernel.org/lkml/20494.1643237814@turing-police/
137 # @see https://gitlab.com/linux-kernel/stable/-/commit/52a9dab6d892763b2a8334a568bd4e2c1a6fde66
147 # Force gcc-4.8 for kernels before 4.4
148 if { verlt "$kversion" "4.4"; }; then
149 selected_cc='gcc-4.8'
152 if [ -z "$selected_cc" ]; then
153 echo "Found no suitable compiler.
"
161 if [ "$selected_cc" != "gcc-4.8
" ]; then
162 # Older kernel Makefiles do not expect the compiler to default to PIE
169 _KCPPFLAGS+=(-fno-pie)
172 selected_cc_version="$
(echo "${selected_cc}" | cut
-d'-' -f2)"
173 if { vergte "${selected_cc_version}" "10"; } && { verlt "${kversion}" "5.10"; } ; then
174 # gcc-10 changed the default from '-fcommon' to '-fno-common', which
175 # causes a linker failure. '-fcommon' can be set on the HOSTCFLAGS
176 # to avoid the issue.
177 # @see https://gitlab.com/linux-kernel/stable/-/commit/e33a814e772cdc36436c8c188d8c42d019fda639
178 _HOSTCFLAGS
+=(-fcommon)
181 if [ "${cross_arch:-}" == "armhf" ] ; then
182 if { verlt
"${kversion}" "5.14"; } ; then
183 # Work-around for producing instructions that aren't valid for the
184 # default architectures.
185 # Eg. Error: selected processor does not support `cpsid i' in ARM mode
186 _KCFLAGS
+=(-march=armv7-a
-mfpu=vfpv3-d16
)
187 _KCPPFLAGS
+=(-march=armv7-a
-mfpu=vfpv3-d16
)
191 if { vergt
"${selected_cc_version}" "8"; } && { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.17"; } ; then
192 # This was added to -Wall in gcc 9 but some kernels do not include the fixes
193 # @see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88583
194 _KCFLAGS+=(-Wno-error=packed-not-aligned)
197 export KAFLAGS="${_KAFLAGS[*]}"
198 export KCFLAGS="${_KCFLAGS[*]}"
199 export KCPPFLAGS="${_KCPPFLAGS[*]}"
200 export HOSTCFLAGS="${_HOSTCFLAGS[*]}"
201 export CC="${CROSS_COMPILE:-}${selected_cc}"
202 export HOSTCC="${selected_cc}"
207 HOSTCFLAGS="${HOSTCFLAGS:-}"
209 if [ -n "${DEBUG}" ] ; then
217 patch_linux_kernel() {
221 git -C "${LINUX_GIT_REF_REPO_DIR}" format-patch -n1 --stdout "${commit_hash}" | patch -p1
223 if [ "$?
" -gt 1 ] ; then
224 echo "Serious issue patching
"
229 build_linux_kernel() {
230 cd "$LINUX_SRCOBJ_DIR"
232 kversion=$(make -s kernelversion "${make_args[@]}")
233 pahole_version="$
(pahole
--version |
tr -d 'v')"
235 if { verlt "${kversion}" "3.3"; } && [ "${vanilla_config}" = "imx_v6_v7_defconfig
" ] ; then
236 # imx_v6_v7 didn't exist before 06965c39b4c63933fa0a1cde2237ef85477c5655
237 if { verlt "${kversion}" "3.2"; } ; then
238 vanilla_config='mx5_defconfig'
240 vanilla_config='mx51_defconfig'
244 if { verlt "${kversion}" "3.13"; } && [ "${vanilla_config}" = "pseries_le_defconfig
" ] ; then
245 # pseries_le_deconfig was introduced in f53e462e907cbaed29c49c0f10f5b8f614e1bf1d
246 vanilla_config='pseries_defconfig'
249 # Generate kernel configuration
252 if [ "${cross_arch}" = "powerpc
" ]; then
253 if vergte "${kversion}" "4.10"; then
254 echo "Ubuntu removed big endian powerpc configuration from kernel
>= 4.10. Don
't try to build it."
259 # Disable riscv64 config generation, we don't have a toolchain on bionic
260 sed -i 's/riscv64 //' debian.master
/etc
/kernelconfig
262 fakeroot debian
/rules clean KW_DEFCONFIG_DIR
=.
264 # Hack for kernel Ubuntu-hwe-5.8
265 # The debian/control file is produced by the clean target above, so this
266 # check needs to happen afterwards.
267 if [ ! -f "debian/compat" ] && ! grep -q debhelper-compat debian
/control
; then
268 echo "10" > "debian/compat"
271 # genconfigs check can fail in certain cases, eg. when a more recent
272 # compiler exposes kernel configuration flags which aren't set in the
273 # Ubuntu annotations.
274 # In any case, the configuration will be updated with any missing values
275 # later in our build script.
276 fakeroot debian
/rules genconfigs KW_DEFCONFIG_DIR
=. do_skip_checks
=true
277 cp CONFIGS
/"${ubuntu_config}" .config
281 # Force 32bit build on i386, default is 64bit
282 if [ "$arch" = "i386" ]; then
286 make "${vanilla_config}" "${make_args[@]}"
290 if [ "${vanilla_config}" = "pseries_defconfig" ] && [ "${cross_arch}" = "ppc64el" ] ; then
291 # @see diff <(git show v3.13:arch/powerpc/configs/pseries_defconfig) <(git show v3.13:arch/powerpc/configs/pseries_le_defconfig)
292 scripts
/config
--enable CONFIG_CPU_LITTLE_ENDIAN
293 scripts
/config
--enable CONFIG_CMA
294 scripts
/config
--disable CONFIG_XMON_DEFAULT
295 # scripts/config --disable CONFIG_VIRTUALIZATION
296 # scripts/config --disable CONFIG_KVM_BOOK3S_64
297 scripts
/config
--disable CONFIG_KVM_BOOK3S_64_HV
300 # oldnoconfig was renamed in 4.19
301 if vergte
"$kversion" "4.19"; then
302 update_conf_target
="olddefconfig"
304 update_conf_target
="oldnoconfig"
307 # Fix 'defined(@array)' was removed from recent perl
308 if [ -f "kernel/timeconst.pl" ]; then
309 sed -i 's/defined(\@\(.*\))/@\1/' kernel
/timeconst.pl
312 # Fix syntax of inline assembly which is confused with C++11 raw strings on gcc >= 5
313 if [ "$HOSTCC" != "gcc-4.8" ]; then
314 if [ -f "arch/x86/kvm/svm.c" ]; then
315 sed -i 's/ R"/ R "/g; s/"R"/" R "/g' arch
/x86
/kvm
/svm.c
318 if [ -f "arch/x86/kvm/vmx.c" ]; then
319 sed -i 's/ R"/ R "/g; s/"R"/" R "/g' arch
/x86
/kvm
/vmx.c
323 if { verlt
"${kversion}" "5.11"; } && { vergte "${kversion}" "4.10"; } ; then
324 # Binutils > 2.35 strips empty symbol tables, causing obltool to fail
325 # in certain cases when files are empty.
326 # @see https://gitlab.com/linux-kernel/stable/-/commit/1d489151e9f9d1647110277ff77282fe4d96d09b
328 # There doesn't seem to be any LD/AS/AR flags to control this behaviour,
329 # therefore patching tools/objtool/elf.c is attempted.
330 patch_linux_kernel 1d489151e9f9d1647110277ff77282fe4d96d09b
331 if { verlt "${kversion}" "4.18"; } ; then
332 patch_linux_kernel e81e0724432542af8d8c702c31e9d82f57b1ff31
336 if { vergt "${selected_cc_version}" "7"; } && { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.17"; } ; then
337 # Builds fail due to -Werror=restrict in pager.o and str_error_r.o
338 if { verlt
"${kversion}" "4.16"; } ; then
339 # This is patched since objtool's Makefile doesn't respect HOSTCFLAGS
340 # @see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ad343a98e74e85aa91d844310e797f96fee6983b
341 patch_linux_kernel ad343a98e74e85aa91d844310e797f96fee6983b
343 if { verlt
"${kversion}" "4.17"; } ; then
344 # This is patched since objtool's Makefile doesn't respect HOSTCFLAGS
345 # @see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=854e55ad289ef8888e7991f0ada85d5846f5afb9
346 patch_linux_kernel
854e55ad289ef8888e7991f0ada85d5846f5afb9
351 if { vergt
"${selected_cc_version}" "9"; } && { verlt "${kversion}" "5.6"; } ; then
352 # Duplicate decalarations of __force_order
353 # @see https://gitlab.com/linux-kernel/stable/-/commit/df6d4f9db79c1a5d6f48b59db35ccd1e9ff9adfc
354 patch_linux_kernel df6d4f9db79c1a5d6f48b59db35ccd1e9ff9adfc
355 # However, kaslr_64.c doesn't exit in 4.15, 4.16, it's named pagetable.c
356 if [ -f arch/x86/boot/compressed/pagetable.c ] ; then
357 sed -i '/^unsigned long __force_order;$/d' arch/x86/boot/compressed/pagetable.c
361 if { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.18"; } ; then
362 # Some old kernels fail to build when make is too new
363 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
364 patch_linux_kernel
9564a8cf422d7b58f6e857e3546d346fa970191e
365 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
366 patch_linux_kernel
9feeb638cde083c737e295c0547f1b4f28e99583
369 if { vergte
"${kversion}" "4.12"; } && { verlt "${kversion}" "4.19"; } ; then
370 # Old kernels can fail to build while on newer host kernels with errors
372 # In file included from scripts/selinux/genheaders/genheaders.c:19:
373 # ./security/selinux/include/classmap.h:249:2: error: #error New address family defined, please update secclass_map.
374 # @see https://gitlab.com/linux-kernel/stable/-/commit/dfbd199a7cfe3e3cd8531e1353cdbd7175bfbc5e
376 patch_linux_kernel dfbd199a7cfe3e3cd8531e1353cdbd7175bfbc5e
379 if { vergte "${kversion}" "3.18"; } && { verlt "${kversion}" "4.4"; } ; then
380 # Compatibility with binutils >= ~ 2.31
381 patch_linux_kernel b21ebf2fb4cde1618915a97cc773e287ff49173e
384 # The above patch only partially applies linux 3.17, and has been, so a
385 # rebased version is used instead.
386 if { vergte
"${kversion}" "3.17"; } && { verlt "${kversion}" "3.18"; } ; then
387 cat <<'EOF' | patch -p1
388 diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_kexec_64.c
389 index 48598105..0652c5b6 100644
390 --- a/arch/x86/kernel/machine_kexec_64.c
391 +++ b/arch/x86/kernel/machine_kexec_64.c
392 @@ -516,6 +516,7 @@ int arch_kexec_apply_relocations_add(const Elf64_Ehdr *ehdr,
396 + case R_X86_64_PLT32:
397 value -= (u64)address;
398 *(u32 *)location = value;
400 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
401 index e69f9882..7c6bc9fe 100644
402 --- a/arch/x86/kernel/module.c
403 +++ b/arch/x86/kernel/module.c
404 @@ -180,6 +180,7 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
408 + case R_X86_64_PLT32:
412 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
413 index bbb1d225..8deeacbc 100644
414 --- a/arch/x86/tools/relocs.c
415 +++ b/arch/x86/tools/relocs.c
416 @@ -763,6 +763,7 @@ static int do_reloc64(struct section *sec, Elf_Rel *rel, ElfW(Sym) *sym,
420 + case R_X86_64_PLT32:
422 * NONE can be ignored and PC relative relocations don't
423 * need to be adjusted.
427 if ( { vergte "${kversion}" "3.14"; } && { verlt "${kversion}" "4.4"; } ) ||
428 ( { vergte
"${kversion}" "4.15"; } && { verlt "${kversion}" "4.17"; } ); then
429 # While the original motivation of this patch is for fixing builds using
430 # clang, the same error occurs between linux >= 3.14 and < 4.4, and in
433 # This patch only partially applies due to changes in kernel/Makefile,
434 # so a supplementary patch is needed
436 # Without this patch, builds fail with
437 # Cannot find symbol for section 2: .text.
438 # kernel/elfcore.o: failed
440 # @see https://github.com/linuxppc/issues/issues/388
441 # @see https://lore.kernel.org/lkml/20201204165742.3815221-2-arnd@kernel.org/
443 patch_linux_kernel 6e7b64b9dd6d96537d816ea07ec26b7dedd397b9
444 if grep -q elfcore.o kernel/Makefile ; then
445 sed -i '/^.* += elfcore.o$/d' kernel/Makefile
448 # Same as above for the v4.4 branch
449 if ( { vergte "${kversion}" "4.4"; } && { verlt "${kversion}" "4.4.257"; } ); then
450 patch_linux_kernel
3140b0740b31cc63cf2ee08bc3f746b423eb068d
451 if grep -q elfcore.o kernel
/Makefile
; then
452 sed -i '/^.* += elfcore.o$/d' kernel
/Makefile
456 # Newer binutils don't accept 3 operand 'cmp' instructions on ppc64
457 # Convert them to 'cmpw' which was previously done silently
458 if verlt
"$kversion" "4.9"; then
459 find arch
/powerpc
/ -name "*.S" -print0 |
xargs -0 sed -i "s/\(cmp\)\(\s\+[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+\)/cmpw\2/"
460 find arch
/powerpc
/ -name "*.S" -print0 |
xargs -0 sed -i "s/\(cmpli\)\(\s\+[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+,\s*[a-zA-Z0-9]\+\)/cmplwi\2/"
461 sed -i "s/\$pie \-o \"\$ofile\"/\$pie --no-dynamic-linker -o \"\$ofile\"/" arch
/powerpc
/boot
/wrapper
464 # Fix a typo in v2.6.36.x
465 if [ -f "arch/x86/kernel/entry_64.S" ]; then
466 sed -i 's/END(do_hypervisor_callback)/END(xen_do_hypervisor_callback)/' arch
/x86
/kernel
/entry_64.S
469 # Fix compiler switch in vdso Makefile for 2.6.36 to 2.6.36.2
470 if { vergte
"$kversion" "2.6.36" && verlte
"$kversion" "2.6.36.3"; }; then
471 sed -i 's/-m elf_x86_64/-m64/' arch
/x86
/vdso
/Makefile
472 sed -i 's/-m elf_i386/-m32/' arch
/x86
/vdso
/Makefile
475 # Fix kernel < 3.0 with gcc >= 4.7
476 if verlt
"$kversion" "3.0"; then
477 sed -i '/linux\/compiler.h/a #include <linux\/linkage.h> \/* For asmregparm *\/' arch
/x86
/include
/asm
/ptrace.h
478 sed -i 's/extern long syscall_trace_enter/extern asmregparm long syscall_trace_enter/' arch
/x86
/include
/asm
/ptrace.h
479 sed -i 's/extern void syscall_trace_leave/extern asmregparm void syscall_trace_leave/' arch
/x86
/include
/asm
/ptrace.h
480 echo "header-y += linkage.h" >> include
/linux
/Kbuild
483 if [ "${cross_arch}" = "powerpc" ] ; then
484 if { vergte
"${kversion}" "4.15"; } && { verlt "${kversion}" "4.16"; } ; then
485 # Avoid register errors such as
486 # aes_generic.c:(.text+0x4e0): undefined reference to `_restgpr_31_x'
487 # @see https://gitlab.com/linux-kernel/stable/-/commit/148b974deea927f5dbb6c468af2707b488bfa2de
489 CFLAGS_aes_generic.o=''
494 if [ "$
(scripts
/config
--state CONFIG_DEBUG_INFO_BTF
)" == "y
" ] &&
495 { vergte "${pahole_version}" "1.24"; } &&
496 { vergte "${kversion}" "5.10"; } && { verlt "${kversion}" "6.0"; } ;then
497 # Some kernels Eg. Ubuntu-hwe-5.13-5.13.0-52.59_20.04.1
498 # fail with the following error:
500 # FAILED: load BTF from vmlinux: Invalid argument
502 # When CONFIG_DEBUG_INFO_BTF is set, certain versions of pahole require
503 # `--skip_encoding_btf_enum64` to be passed as the kernel doesn't define
506 # Introduced in 341dfcf8d78eaa3a2dc96dea06f0392eb2978364 (~v5.10)
507 # @see https://lore.kernel.org/bpf/20220825171620.cioobudss6ovyrkc@altlinux.org/t/
509 if [ -f "scripts/pahole-flags.sh" ] ; then
510 sed -i 's/ -J ${PAHOLE_FLAGS} / -J ${PAHOLE_FLAGS} --skip_encoding_btf_enum64 /' scripts
/link-vmlinux.sh
512 sed -i 's/ -J ${extra_paholeopt} / -J ${extra_paholeopt} --skip_encoding_btf_enum64 /' scripts
/link-vmlinux.sh
517 if [ "$HOSTCC" == "gcc-4.8" ]; then
518 scripts
/config
--disable CONFIG_CC_STACKPROTECTOR_STRONG
519 scripts
/config
--disable CONFIG_PPC_OF_BOOT_TRAMPOLINE
522 # Don't try to sign modules
523 scripts
/config
--disable CONFIG_MODULE_SIG
525 # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails
526 scripts
/config
--disable CONFIG_STACK_VALIDATION
528 # Cause problems with inline assembly on i386
529 scripts
/config
--disable CONFIG_DEBUG_SECTION_MISMATCH
531 # Don't build samples, they are broken on some kernel releases
532 scripts
/config
--disable CONFIG_SAMPLES
533 scripts
/config
--disable CONFIG_BUILD_DOCSRC
536 scripts
/config
--disable CONFIG_KCOV
538 # Broken on some RT kernels
539 scripts
/config
--disable CONFIG_HYPERV
542 scripts
/config
--disable CONFIG_RAPIDIO_TSI721
543 scripts
/config
--disable CONFIG_SGI_XP
544 scripts
/config
--disable CONFIG_MFD_WM8994
545 scripts
/config
--disable CONFIG_DRM_RADEON
546 scripts
/config
--disable CONFIG_SND_SOC_WM5100
547 # More recent compiler optimizations (from gcc 8 onwards )expose build errors
548 # with netronome on older kernels.
549 # Observed in 4.11-rt, 4.15-4.17, 5.0-rt - 5.16-rt
550 # It seems easier to disable the driver than to attempt patching.
552 # In function ‘ur_load_imm_any’,
553 # inlined from ‘jeq_imm’ at drivers/net/ethernet/netronome/nfp/bpf/jit.c:3146:13:
554 # ./include/linux/compiler.h:350:45: error: call to ‘__compiletime_assert_1062’ declared with attribute error: FIELD_FIT: value too large for the field
555 # 350 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
557 scripts
/config
--disable CONFIG_NET_VENDOR_NETRONOME
559 # In function ‘memcpy’,
560 # inlined from ‘kszphy_get_strings’ at drivers/net/phy/micrel.c:664:3:
561 # ./include/linux/string.h:305:25: error: call to ‘__read_overflow2’ declared with attribute error: detected read beyond size of object passed as 2nd parameter
562 # 305 | __read_overflow2();
563 # | ^~~~~~~~~~~~~~~~~~
564 # make[3]: *** [scripts/Makefile.build:308: drivers/net/phy/micrel.o] Error 1
566 scripts
/config
--disable CONFIG_MICREL_PHY
569 # IGBVF won't build with recent gcc on 2.6.38.x
570 if { vergte
"$kversion" "2.6.37" && verlt
"$kversion" "2.6.38"; }; then
571 scripts
/config
--disable CONFIG_IGBVF
574 # Don't fail the build on warnings
575 scripts
/config
--disable CONFIG_WERROR
576 scripts
/config
--enable CONFIG_PPC_DISABLE_WERROR
578 # Set required options
579 scripts
/config
--enable CONFIG_TRACEPOINTS
580 scripts
/config
--enable CONFIG_KALLSYMS
581 scripts
/config
--enable CONFIG_HIGH_RES_TIMERS
582 scripts
/config
--enable CONFIG_KPROBES
583 scripts
/config
--enable CONFIG_FTRACE
584 scripts
/config
--enable CONFIG_BLK_DEV_IO_TRACE
585 scripts
/config
--enable CONFIG_KALLSYMS_ALL
586 scripts
/config
--enable CONFIG_HAVE_SYSCALL_TRACEPOINTS
587 scripts
/config
--enable CONFIG_PERF_EVENTS
588 scripts
/config
--enable CONFIG_EVENT_TRACING
589 scripts
/config
--enable CONFIG_KRETPROBES
591 if [ -n "${DEBUG}" ] ; then
595 make "$update_conf_target" "${make_args[@]}"
596 make -j"$NPROC" "${make_args[@]}"
598 krelease
=$
(make -s kernelrelease
"${make_args[@]}")
600 # Save the kernel and modules
601 mkdir
-p "$LINUX_INSTOBJ_DIR/boot"
602 make INSTALL_MOD_PATH
="$LINUX_INSTOBJ_DIR" INSTALL_MOD_STRIP
=1 modules_install
"${make_args[@]}"
603 make INSTALL_MOD_PATH
="$LINUX_INSTOBJ_DIR" INSTALL_PATH
="$LINUX_INSTOBJ_DIR/boot" install "${make_args[@]}"
604 rm -f "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source" "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/build"
605 ln -s ..
/..
/..
/..
/sources
"$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source"
606 ln -s ..
/..
/..
/..
/sources
"$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source"
610 extract_distro_headers
() {
612 # Enter linux source dir
613 cd "${LINUX_SRCOBJ_DIR}"
616 # For RT kernels, copy version file
617 if [ -s localversion-rt
]; then
618 cp -a localversion-rt
"${LINUX_HDROBJ_DIR}"
621 # Copy all Makefile related stuff
622 find .
-path './include/*' -prune \
623 -o -path './scripts/*' -prune -o -type f \
624 \
( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
625 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \
) \
626 -print |
cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
628 # Copy base scripts and include dirs
629 cp -a scripts include
"${LINUX_HDROBJ_DIR}"
632 (find arch
-name include
-type d
-print0 | \
633 xargs -0 -n1 -I '{}' find '{}' -type f
) | \
634 cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
637 (find arch
-name scripts
-type d
-print0 | \
638 xargs -0 -n1 -I '{}' find '{}' -type f
) | \
639 cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
642 rm -f "${LINUX_HDROBJ_DIR}/scripts/*.o"
643 rm -f "${LINUX_HDROBJ_DIR}/scripts/*/*.o"
645 # On powerpc 32bits this object is required to link modules
646 if [ "${karch}" = "powerpc" ]; then
647 if [ "$(scripts/config -s CONFIG_PPC64)" = "y" ] && vergte
"${kversion}" "5.4"; then
650 cp -a --parents arch
/powerpc
/lib
/crtsavres.
[So
] "${LINUX_HDROBJ_DIR}/"
654 # On arm64 between 4.13 and 1.15 this object is required to build with ftrace support
655 if [ "${karch}" = "arm64" ]; then
656 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
657 cp -a --parents arch
/arm64
/kernel
/ftrace-mod.
[So
] "${LINUX_HDROBJ_DIR}/"
661 # Newer kernels need objtool to build modules when CONFIG_STACK_VALIDATION=y
662 if [ -f tools
/objtool
/objtool
]; then
663 cp -a --parents tools
/objtool
/objtool
"${LINUX_HDROBJ_DIR}/"
666 if [ -f "arch/x86/kernel/macros.s" ]; then
667 cp -a --parents arch
/x86
/kernel
/macros.s
"${LINUX_HDROBJ_DIR}/"
670 # Copy modules related stuff, if available
671 if [ -s Module.symvers
]; then
672 cp Module.symvers
"${LINUX_HDROBJ_DIR}"
675 if [ -s System.map
]; then
676 cp System.map
"${LINUX_HDROBJ_DIR}"
679 if [ -s Module.markers
]; then
680 cp Module.markers
"${LINUX_HDROBJ_DIR}"
684 cp .config
"${LINUX_HDROBJ_DIR}"
686 # Make sure the Makefile and version.h have a matching timestamp so that
687 # external modules can be built
688 if [ -s "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h" ]; then
689 touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h"
690 elif [ -s "${LINUX_HDROBJ_DIR}/include/linux/version.h" ]; then
691 touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/linux/version.h"
693 echo "Missing version.h"
696 touch -r "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/generated/autoconf.h"
698 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
699 if [ ! -f "${LINUX_HDROBJ_DIR}/include/config/auto.conf" ]; then
700 cp "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/config/auto.conf"
703 # Finally clean the object files from the full source tree
706 # And regen the modules support files
707 make modules_prepare
"${make_args[@]}"
709 # On powerpc 32bits this object is required to link modules
710 if [ "${karch}" = "powerpc" ]; then
711 if [ "$(scripts/config -s CONFIG_PPC64)" = "y" ] && vergte
"${kversion}" "5.4"; then
714 make arch
/powerpc
/lib
/crtsavres.o
"${make_args[@]}"
718 # On arm64 between 4.13 and 4.15 this object is required to build with ftrace support
719 if [ "${karch}" = "arm64" ]; then
720 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
721 make arch
/arm64
/kernel
/ftrace-mod.o
"${make_args[@]}"
725 # Version specific tasks
728 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
729 ABINUM
="$(echo "$ktag" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')"
730 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> include
/generated
/utsrelease.h
731 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${LINUX_HDROBJ_DIR}/include/generated/utsrelease.h"
743 kversion
=$
(make -C "$LINUX_HDROBJ_DIR" -s kernelversion
)
745 # Try to catch some compatibility problems by turning some
746 # warnings into errors.
747 #export KCFLAGS="$KCFLAGS -Wall -Werror"
749 # Enter lttng-modules source dir
750 cd "${MODULES_GIT_DIR}"
752 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
753 # timekeeping subsystem. We want those build to fail.
754 if { vergte
"$kversion" "3.10" && verlte
"$kversion" "3.10.13"; } || \
755 { vergte
"$kversion" "3.11" && verlte
"$kversion" "3.11.2"; }; then
760 KERNELDIR
="${kdir}" make -j"${NPROC}" V=1 "${make_args[@]}"
765 # We expect this build to fail, if it doesn't, fail the job.
766 if [ "$ret" -eq 0 ]; then
767 echo "This build should have failed."
771 # We have to publish at least one file or the build will fail
772 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${outdir}/BROKEN.txt.ko"
774 KERNELDIR
="${kdir}" make clean
778 # Build modules against full kernel sources
779 KERNELDIR
="${kdir}" make -j"${NPROC}" V=1 "${make_args[@]}"
781 # Install modules to build dir
782 KERNELDIR
="${kdir}" make INSTALL_MOD_PATH
="${outdir}" modules_install
785 KERNELDIR
="${kdir}" make clean
795 MODULES_GIT_DIR
="${WORKSPACE}/src/lttng-modules"
796 LINUX_GIT_DIR
="${WORKSPACE}/src/linux"
798 LINUX_OBJ_DIR
="${WORKSPACE}/linux"
799 LINUX_SRCOBJ_DIR
="${LINUX_OBJ_DIR}/sources"
800 LINUX_HDROBJ_DIR
="${LINUX_OBJ_DIR}/headers"
801 LINUX_INSTOBJ_DIR
="${LINUX_OBJ_DIR}/install"
803 MODULES_OUTPUT_KSRC_DIR
="${WORKSPACE}/build/lttng-modules-ksrc"
804 MODULES_OUTPUT_KHDR_DIR
="${WORKSPACE}/build/lttng-modules-khdr"
806 LINUX_GIT_REF_REPO_DIR
="$HOME/gitcache/linux-stable.git/"
808 OBJ_STORE_URL
="s3://jenkins"
812 # Create build directories
813 mkdir
-p "${LINUX_SRCOBJ_DIR}" "${LINUX_HDROBJ_DIR}" "${LINUX_INSTOBJ_DIR}" "${MODULES_OUTPUT_KSRC_DIR}" "${MODULES_OUTPUT_KHDR_DIR}"
815 git_clone_modules_sources
817 # Setup cross compile env if available
818 if [ "x${cross_arch}" != "x" ]; then
820 case "$cross_arch" in
823 cross_compile
="arm-linux-gnueabihf-"
824 vanilla_config
="imx_v6_v7_defconfig"
825 ubuntu_config
="armhf-config.flavour.generic"
830 cross_compile
="aarch64-linux-gnu-"
831 vanilla_config
="defconfig"
832 ubuntu_config
="arm64-config.flavour.generic"
837 cross_compile
="powerpc-linux-gnu-"
838 vanilla_config
="ppc44x_defconfig"
839 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
844 cross_compile
="powerpc64le-linux-gnu-"
845 vanilla_config
="pseries_le_defconfig"
846 ubuntu_config
="ppc64el-config.flavour.generic"
850 echo "Unsupported cross arch $cross_arch"
855 # Export variables used by Kbuild for cross compilation
856 export ARCH
="${karch}"
857 export CROSS_COMPILE
="${cross_compile}"
859 # Set arch specific values if we are not cross compiling
860 elif [ "x${arch}" != "x" ]; then
865 vanilla_config
="allmodconfig"
866 ubuntu_config
="i386-config.flavour.generic"
871 vanilla_config
="allmodconfig"
872 ubuntu_config
="amd64-config.flavour.generic"
877 vanilla_config
="allmodconfig"
878 ubuntu_config
="armhf-config.flavour.generic"
883 vanilla_config
="allmodconfig"
884 ubuntu_config
="arm64-config.flavour.generic"
889 vanilla_config
="allmodconfig"
890 ubuntu_config
="powerpc-config.flavour.powerpc-smp"
895 vanilla_config
="allmodconfig"
896 ubuntu_config
="ppc64el-config.flavour.generic"
900 echo "Unsupported arch $arch"
905 echo "No arch or cross_arch specified"
911 # First get the kernel build from the object store, or build it, if it's
914 echo "# Setup endpoint
915 host_base = obj.internal.efficios.com
916 host_bucket = obj.internal.efficios.com
917 bucket_location = us-east-1
922 secret_key = echo123456
924 # Enable S3 v4 signature APIs
925 signature_v2 = False" > "$WORKSPACE/.s3cfg"
927 url_hash
="$(echo -n "$kgitrepo" | md5sum | awk '{ print $1 }')"
928 obj_name
="linux.tar.bz2"
930 if [ -z "${cross_arch}" ]; then
931 obj_url_prefix
="$OBJ_STORE_URL/linux-build/$url_hash/$ktag/platform-${platforms}/$arch/native"
933 obj_url_prefix
="$OBJ_STORE_URL/linux-build/$url_hash/$ktag/platform-${platforms}/${cross_arch}"
936 obj_url
="$obj_url_prefix/$obj_name"
939 # In s3cmd 2.3, the return code of get when an object does not exist (64)
940 # is different than in 2.2 (12). The return codes of 's3cmd info' are
941 # consistent between 2.2 and 2.3.
942 s3cmd
-c "$WORKSPACE/.s3cfg" info
"$obj_url"
948 s3cmd
-c "$WORKSPACE/.s3cfg" get
"$obj_url"
953 echo "File not found"
955 # Build all the things and upload
956 # then finish the module build...
958 git_clone_linux_sources
959 git_export_linux_sources
963 ## PREPARE FULL LINUX SOURCE TREE
966 ## EXTRACT DISTRO STYLE KERNEL HEADERS / DEVEL
967 extract_distro_headers
976 echo "Unknown error? Abort"
983 selected_cc_version
="$(echo "${selected_cc}" | cut -d'-' -f2)"
984 # lttng-modules requires gcc >= 5.1 for aarch64
985 # @see https://github.com/lttng/lttng-modules/commit/be06402dbdbea2f3394e60ec15c5d3356e2be416
986 if { verlt
"${selected_cc_version}" "5.1"; } && [ "${cross_arch}" = "arm64" ] ; then
987 echo "Building lltng-modules on aarch64 requires gcc >= 5.1"
992 # Either we downloaded a pre-build kernel or we built it and uploaded
993 # the archive for future builds.
997 # Build modules against full kernel sources
998 build_modules
"${LINUX_SRCOBJ_DIR}" "${MODULES_OUTPUT_KSRC_DIR}"
1000 # Build modules against kernel headers
1001 build_modules
"${LINUX_HDROBJ_DIR}" "${MODULES_OUTPUT_KHDR_DIR}"
1003 # Make sure some modules were actually built
1004 tree
"${MODULES_OUTPUT_KSRC_DIR}"
1005 if [ "x$(find "${MODULES_OUTPUT_KSRC_DIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
1006 echo "No modules built!"
1010 tree
"${MODULES_OUTPUT_KHDR_DIR}"
1011 if [ "x$(find "${MODULES_OUTPUT_KHDR_DIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
1012 echo "No modules built!"