jjb: lttng-modules: update coverity for deb12
[lttng-ci.git] / scripts / lttng-modules / param-build.sh
CommitLineData
51c9c62d 1#!/bin/bash
f3d8604b 2#
53300bf0 3# Copyright (C) 2016-2023 Michael Jeanson <mjeanson@efficios.com>
f3d8604b
MJ
4#
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.
9#
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.
14#
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/>.
17
51c9c62d
MJ
18set -exu
19
39961776 20# Parameters
53300bf0
MJ
21platform=${platforms:-}
22cross_arch=${cross_arch:-}
23ktag=${ktag:-}
24kgitrepo=${kgitrepo:-}
25mversion=${mversion:-}
26mgitrepo=${mgitrepo:-}
27make_args=()
28
29DEBUG=${DEBUG:-}
30
447eaf93
KS
31# Derive arch from label if it isn't set
32if [ -z "${arch:-}" ] ; then
33 # Labels may be platform specific, eg. jammy-amd64, deb12-armhf
34 regex='[[:alnum:]]+-([[:alnum:]]+)'
53300bf0 35 if [[ "${platform}" =~ ${regex} ]] ; then
447eaf93
KS
36 arch="${BASH_REMATCH[1]}"
37 else
53300bf0 38 arch="${platform:-}"
447eaf93
KS
39 fi
40fi
a86b55bc 41
39961776 42
339db64d
MJ
43## FUNCTIONS ##
44
f3d8604b
MJ
45# Kernel version compare functions
46verlte() {
51fa2ab3 47 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ]
f3d8604b
MJ
48}
49
50verlt() {
28b10e79 51 # shellcheck disable=SC2015
51fa2ab3 52 [ "$1" = "$2" ] && return 1 || verlte "$1" "$2"
f3d8604b
MJ
53}
54
55vergte() {
51fa2ab3 56 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ]
f3d8604b
MJ
57}
58
59vergt() {
28b10e79 60 # shellcheck disable=SC2015
51fa2ab3 61 [ "$1" = "$2" ] && return 1 || vergte "$1" "$2"
f3d8604b
MJ
62}
63
53300bf0
MJ
64print_header() {
65 set +x
66
67 local message=" $1 "
68 local message_len
69 local padding_len
70
71 message_len="${#message}"
72 padding_len=$(( (80 - (message_len)) / 2 ))
73
74 printf '\n'; printf -- '#%.0s' {1..80}; printf '\n'
75 printf -- '-%.0s' {1..80}; printf '\n'
76 printf -- '#%.0s' $(seq 1 $padding_len); printf '%s' "$message"; printf -- '#%.0s' $(seq 1 $padding_len); printf '\n'
77 printf -- '-%.0s' {1..80}; printf '\n'
78 printf -- '#%.0s' {1..80}; printf '\n\n'
79
80 set -x
81}
82
5a196804
MJ
83git_clone_modules_sources() {
84 mkdir -p "$MODULES_GIT_DIR"
28b10e79
MJ
85
86 # If the version starts with "refs/", checkout the specific git ref, otherwise treat it
87 # as a branch name.
88 if [ "${mversion:0:5}" = "refs/" ]; then
89 git clone --no-tags --depth=1 "${mgitrepo}" "$MODULES_GIT_DIR"
90 (cd "$MODULES_GIT_DIR" && git fetch origin "${mversion}" && git checkout FETCH_HEAD)
91 else
92 git clone --no-tags --depth=1 -b "${mversion}" "${mgitrepo}" "$MODULES_GIT_DIR"
93 fi
5a196804
MJ
94}
95
96# Checkout a shallow kernel tree of the specified tag
97git_clone_linux_sources() {
98 mkdir -p "$LINUX_GIT_DIR"
99 git clone --depth=1 -b "${ktag}" --reference "$LINUX_GIT_REF_REPO_DIR" "${kgitrepo}" "$LINUX_GIT_DIR"
100}
7e02032c 101
7e02032c 102
5a196804
MJ
103# Export the kernel sources from the git repo
104git_export_linux_sources() {
105 cd "$LINUX_GIT_DIR"
106 git archive "${ktag}" | tar -x -C "$LINUX_SRCOBJ_DIR"
107}
108
109
110# Upload the tar archive to the object store
111upload_archive_obj() {
112 s3cmd -c "$WORKSPACE/.s3cfg" put "$WORKSPACE/$obj_name" "$obj_url_prefix/"
113 rm -f "$WORKSPACE/$obj_name"
114}
115
116
117extract_archive_obj() {
02c6a56a 118 tar -xf "$WORKSPACE/$obj_name" -C "$LINUX_OBJ_DIR" -I pbzip2
5a196804
MJ
119 rm -f "$WORKSPACE/$obj_name"
120}
121
122
123tar_archive_obj() {
124 cd "$LINUX_OBJ_DIR"
125 tar -cf "$WORKSPACE/$obj_name" -I pbzip2 .
126 cd -
127}
128
53300bf0 129# List all GCC versions present in the PATH
6c0b2710
KS
130list_gccs() {
131 local gccs
132 gccs=()
133 IFS=: read -r -a path_array <<< "$PATH"
134 while read -r gcc ; do
135 gccs+=("$gcc")
136 done < <(find "${path_array[@]}" -maxdepth 1 -regex '.*/gcc-[0-9\.]+$' -printf '%f\n' | sort -t- -k2 -V -r)
137 echo "${gccs[@]}"
138}
139
5a196804
MJ
140# Find the most recent GCC version supported by the kernel sources
141select_compiler() {
5a196804 142
53300bf0 143 # Enter linux source dir
5a196804
MJ
144 cd "$LINUX_SRCOBJ_DIR"
145
146 kversion=$(make -s kernelversion)
147
a86b55bc 148 if { verlt "$kversion" "4.4"; }; then
53300bf0 149 # Force gcc-4.8 for kernels before 4.4
a86b55bc 150 selected_cc='gcc-4.8'
53300bf0
MJ
151 selected_cc_version=$(echo "${selected_cc}" | cut -d'-' -f2)
152 else
153 for cc in $(list_gccs) ; do
154 if "${CROSS_COMPILE:-}${cc}" -I include/ -D__LINUX_COMPILER_H -D__LINUX_COMPILER_TYPES_H -E include/linux/compiler-gcc.h; then
155 cc_version=$(echo "${cc}" | cut -d'-' -f2)
156 if { verlt "${kversion}" "5.17"; } && { vergt "${cc_version}" "11"; } ; then
157 # Using gcc-12+ with '-Wuse-after-free' breaks the build of older
158 # kernels (in particular, objtool). Some releases on LTS
159 # branches between 4.x and 5.15 can be built with gcc-12.
160 # @see https://lore.kernel.org/lkml/20494.1643237814@turing-police/
161 # @see https://gitlab.com/linux-kernel/stable/-/commit/52a9dab6d892763b2a8334a568bd4e2c1a6fde66
162 continue
163 fi
164 selected_cc="$cc"
165 selected_cc_version="$cc_version"
166 break
167 fi
168 done
a86b55bc
KS
169 fi
170
efdab1b7 171 if [ -z "$selected_cc" ]; then
5a196804
MJ
172 echo "Found no suitable compiler."
173 exit 1
174 fi
175
53300bf0
MJ
176 # lttng-modules requires gcc >= 5.1 for aarch64
177 # @see https://github.com/lttng/lttng-modules/commit/be06402dbdbea2f3394e60ec15c5d3356e2be416
178 if { verlt "${selected_cc_version}" "5.1"; } && [ "${cross_arch}" = "arm64" ] ; then
179 echo "Building lttng-modules on aarch64 requires gcc >= 5.1"
180 exit 1
181 fi
182
183 cd -
184}
185
186export_kbuild_flags() {
187 local _KAFLAGS
188 local _KCFLAGS
189 local _KCPPFLAGS
190 local _HOSTCFLAGS
191
a86b55bc
KS
192 _KAFLAGS=()
193 _KCFLAGS=()
194 _KCPPFLAGS=()
195 _HOSTCFLAGS=()
53300bf0 196
425e4992
MJ
197 if [ "$selected_cc" != "gcc-4.8" ]; then
198 # Older kernel Makefiles do not expect the compiler to default to PIE
a86b55bc
KS
199 _KAFLAGS+=(-fno-pie)
200 _KCFLAGS+=(
201 -fno-pie
202 -no-pie
203 -fno-stack-protector
204 )
205 _KCPPFLAGS+=(-fno-pie)
206 fi
207
a86b55bc
KS
208 if { vergte "${selected_cc_version}" "10"; } && { verlt "${kversion}" "5.10"; } ; then
209 # gcc-10 changed the default from '-fcommon' to '-fno-common', which
210 # causes a linker failure. '-fcommon' can be set on the HOSTCFLAGS
211 # to avoid the issue.
212 # @see https://gitlab.com/linux-kernel/stable/-/commit/e33a814e772cdc36436c8c188d8c42d019fda639
213 _HOSTCFLAGS+=(-fcommon)
214 fi
215
53300bf0
MJ
216 if { verlt "${kversion}" "5.14"; } && [ "${cross_arch:-}" == "armhf" ] ; then
217 # Work-around for producing instructions that aren't valid for the
218 # default architectures.
219 # Eg. Error: selected processor does not support `cpsid i' in ARM mode
220 _KCFLAGS+=(-march=armv7-a -mfpu=vfpv3-d16)
221 _KCPPFLAGS+=(-march=armv7-a -mfpu=vfpv3-d16)
a86b55bc
KS
222 fi
223
224 if { vergt "${selected_cc_version}" "8"; } && { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.17"; } ; then
225 # This was added to -Wall in gcc 9 but some kernels do not include the fixes
226 # @see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88583
227 _KCFLAGS+=(-Wno-error=packed-not-aligned)
425e4992
MJ
228 fi
229
a86b55bc
KS
230 export KAFLAGS="${_KAFLAGS[*]}"
231 export KCFLAGS="${_KCFLAGS[*]}"
232 export KCPPFLAGS="${_KCPPFLAGS[*]}"
233 export HOSTCFLAGS="${_HOSTCFLAGS[*]}"
5a196804 234 export CC="${CROSS_COMPILE:-}${selected_cc}"
1d5a0a3c 235 export HOSTCC="${selected_cc}"
5a196804 236
a86b55bc
KS
237 make_args=(
238 CC="${CC}"
239 HOSTCC="${HOSTCC}"
240 HOSTCFLAGS="${HOSTCFLAGS:-}"
241 )
53300bf0 242
a86b55bc
KS
243 if [ -n "${DEBUG}" ] ; then
244 make_args+=(
245 V=1
246 )
247 fi
5a196804
MJ
248}
249
a86b55bc
KS
250patch_linux_kernel() {
251 local commit_hash
252 commit_hash="$1"
53300bf0
MJ
253
254 # Show the title of the patch in the build log
255 git -C "${LINUX_GIT_REF_REPO_DIR}" show --oneline -s "${commit_hash}"
256
257 # Apply patch, don't fail if it doesn't apply cleanly
a86b55bc
KS
258 set +e
259 git -C "${LINUX_GIT_REF_REPO_DIR}" format-patch -n1 --stdout "${commit_hash}" | patch -p1
260 set -e
53300bf0 261
a86b55bc
KS
262 if [ "$?" -gt 1 ] ; then
263 echo "Serious issue patching"
264 exit 1
265 fi
266}
5a196804
MJ
267
268build_linux_kernel() {
269 cd "$LINUX_SRCOBJ_DIR"
270
a86b55bc 271 kversion=$(make -s kernelversion "${make_args[@]}")
23ebcd4b 272 pahole_version="$(pahole --version | tr -d 'v')"
a86b55bc
KS
273
274 if { verlt "${kversion}" "3.3"; } && [ "${vanilla_config}" = "imx_v6_v7_defconfig" ] ; then
275 # imx_v6_v7 didn't exist before 06965c39b4c63933fa0a1cde2237ef85477c5655
276 if { verlt "${kversion}" "3.2"; } ; then
277 vanilla_config='mx5_defconfig'
278 else
279 vanilla_config='mx51_defconfig'
280 fi
281 fi
282
283 if { verlt "${kversion}" "3.13"; } && [ "${vanilla_config}" = "pseries_le_defconfig" ] ; then
284 # pseries_le_deconfig was introduced in f53e462e907cbaed29c49c0f10f5b8f614e1bf1d
285 vanilla_config='pseries_defconfig'
286 fi
5a196804 287
7e02032c 288 # Generate kernel configuration
a1ae361e 289 case "$ktag" in
7e02032c 290 Ubuntu*)
39961776 291 if [ "${cross_arch}" = "powerpc" ]; then
5a196804 292 if vergte "${kversion}" "4.10"; then
39961776
MJ
293 echo "Ubuntu removed big endian powerpc configuration from kernel >= 4.10. Don't try to build it."
294 exit 0
295 fi
296 fi
af101606 297
0c1bde3d
KS
298 fakeroot debian/rules clean KW_DEFCONFIG_DIR=.
299
073dc82c 300 # Hack for kernel Ubuntu-hwe-5.8
0c1bde3d
KS
301 # The debian/control file is produced by the clean target above, so this
302 # check needs to happen afterwards.
303 if [ ! -f "debian/compat" ] && ! grep -q debhelper-compat debian/control; then
073dc82c
MJ
304 echo "10" > "debian/compat"
305 fi
306
0c1bde3d
KS
307 # genconfigs check can fail in certain cases, eg. when a more recent
308 # compiler exposes kernel configuration flags which aren't set in the
309 # Ubuntu annotations.
310 # In any case, the configuration will be updated with any missing values
311 # later in our build script.
312 fakeroot debian/rules genconfigs KW_DEFCONFIG_DIR=. do_skip_checks=true
5a196804 313 cp CONFIGS/"${ubuntu_config}" .config
7e02032c 314 ;;
c45b04df 315
7e02032c 316 *)
16844a6d
MJ
317 # Force 32bit build on i386, default is 64bit
318 if [ "$arch" = "i386" ]; then
5a196804
MJ
319 export ARCH="i386"
320 fi
321
a86b55bc 322 make "${vanilla_config}" "${make_args[@]}"
7e02032c
MJ
323 ;;
324 esac
325
a86b55bc
KS
326 if [ "${vanilla_config}" = "pseries_defconfig" ] && [ "${cross_arch}" = "ppc64el" ] ; then
327 # @see diff <(git show v3.13:arch/powerpc/configs/pseries_defconfig) <(git show v3.13:arch/powerpc/configs/pseries_le_defconfig)
328 scripts/config --enable CONFIG_CPU_LITTLE_ENDIAN
329 scripts/config --enable CONFIG_CMA
330 scripts/config --disable CONFIG_XMON_DEFAULT
331 # scripts/config --disable CONFIG_VIRTUALIZATION
332 # scripts/config --disable CONFIG_KVM_BOOK3S_64
333 scripts/config --disable CONFIG_KVM_BOOK3S_64_HV
334 fi
335
53b51a15 336 # oldnoconfig was renamed in 4.19
5a196804 337 if vergte "$kversion" "4.19"; then
53b51a15 338 update_conf_target="olddefconfig"
5a196804 339 else
53b51a15 340 update_conf_target="oldnoconfig"
5a196804
MJ
341 fi
342
343 # Fix 'defined(@array)' was removed from recent perl
344 if [ -f "kernel/timeconst.pl" ]; then
345 sed -i 's/defined(\@\(.*\))/@\1/' kernel/timeconst.pl
346 fi
347
348 # Fix syntax of inline assembly which is confused with C++11 raw strings on gcc >= 5
53b51a15 349 if [ "$HOSTCC" != "gcc-4.8" ]; then
5a196804
MJ
350 if [ -f "arch/x86/kvm/svm.c" ]; then
351 sed -i 's/ R"/ R "/g; s/"R"/" R "/g' arch/x86/kvm/svm.c
352 fi
353
354 if [ -f "arch/x86/kvm/vmx.c" ]; then
355 sed -i 's/ R"/ R "/g; s/"R"/" R "/g' arch/x86/kvm/vmx.c
356 fi
357 fi
358
a86b55bc
KS
359 if { verlt "${kversion}" "5.11"; } && { vergte "${kversion}" "4.10"; } ; then
360 # Binutils > 2.35 strips empty symbol tables, causing obltool to fail
361 # in certain cases when files are empty.
362 # @see https://gitlab.com/linux-kernel/stable/-/commit/1d489151e9f9d1647110277ff77282fe4d96d09b
363 #
364 # There doesn't seem to be any LD/AS/AR flags to control this behaviour,
365 # therefore patching tools/objtool/elf.c is attempted.
366 patch_linux_kernel 1d489151e9f9d1647110277ff77282fe4d96d09b
367 if { verlt "${kversion}" "4.18"; } ; then
368 patch_linux_kernel e81e0724432542af8d8c702c31e9d82f57b1ff31
369 fi
370 fi
371
9383502e 372 if { vergt "${selected_cc_version}" "7"; } && { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.17"; } ; then
a86b55bc
KS
373 # Builds fail due to -Werror=restrict in pager.o and str_error_r.o
374 if { verlt "${kversion}" "4.16"; } ; then
375 # This is patched since objtool's Makefile doesn't respect HOSTCFLAGS
376 # @see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ad343a98e74e85aa91d844310e797f96fee6983b
377 patch_linux_kernel ad343a98e74e85aa91d844310e797f96fee6983b
378 fi
379 if { verlt "${kversion}" "4.17"; } ; then
380 # This is patched since objtool's Makefile doesn't respect HOSTCFLAGS
381 # @see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=854e55ad289ef8888e7991f0ada85d5846f5afb9
382 patch_linux_kernel 854e55ad289ef8888e7991f0ada85d5846f5afb9
383 fi
384
ad23f63b
KS
385 fi
386
387 if { vergt "${selected_cc_version}" "9"; } && { verlt "${kversion}" "5.6"; } ; then
a86b55bc
KS
388 # Duplicate decalarations of __force_order
389 # @see https://gitlab.com/linux-kernel/stable/-/commit/df6d4f9db79c1a5d6f48b59db35ccd1e9ff9adfc
390 # However, kaslr_64.c doesn't exit in 4.15, 4.16, it's named pagetable.c
391 if [ -f arch/x86/boot/compressed/pagetable.c ] ; then
392 sed -i '/^unsigned long __force_order;$/d' arch/x86/boot/compressed/pagetable.c
393 fi
9ae537d7
KS
394 if [ -f arch/x86/boot/compressed/kaslr_64.c ] ; then
395 patch_linux_kernel df6d4f9db79c1a5d6f48b59db35ccd1e9ff9adfc
396 fi
397 fi
398
399 if { vergte "${kversion}" "4.18"; } && { verlt "${kversion}" "4.19"; } ; then
400 # In some cases, compiling net/bpfilter can fail with the following error:
401 # net/bpfilter/main.c:9:10: fatal error: include/uapi/linux/bpf.h: No such file or directory
402 # make[2]: *** [scripts/Makefile.host:107: net/bpfilter/main.o] Error 1
403 #
404 # While the issue is potentially in a number of old versions, it has only
405 # been observed in v4.18-rt
406 #
407 patch_linux_kernel 303a339f30a9441c4695d3d2cc78f1b33cd959ff
408 fi
409
410 if { vergte "${kversion}" "4.18"; } && { verlt "${kversion}" "4.19"; } ; then
411 # In some cases, compiling net/bpfilter can fail with the following error:
412 # net/bpfilter/main.c:9:10: fatal error: include/uapi/linux/bpf.h: No such file or directory
413 # make[2]: *** [scripts/Makefile.host:107: net/bpfilter/main.o] Error 1
414 #
415 # While the issue is potentially in a number of old versions, it has only
416 # been observed in v4.18-rt
417 #
418 patch_linux_kernel 303a339f30a9441c4695d3d2cc78f1b33cd959ff
a86b55bc
KS
419 fi
420
421 if { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.18"; } ; then
422 # Some old kernels fail to build when make is too new
423 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
424 patch_linux_kernel 9564a8cf422d7b58f6e857e3546d346fa970191e
9383502e
MJ
425 fi
426
427 if { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.55"; } ; then
428 # Some old kernels fail to build when make is too new
429 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
430 patch_linux_kernel e82885490a611f2b75a6c27cd7bb09665c1740be
431 fi
432
433 if ( { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.18"; } ) || \
434 ( { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.56"; } ) ; then
435 # Some old kernels fail to build when make is too new
a86b55bc
KS
436 # @see https://gitlab.com/linux-kernel/stable/-/commit/9feeb638cde083c737e295c0547f1b4f28e99583
437 patch_linux_kernel 9feeb638cde083c737e295c0547f1b4f28e99583
438 fi
439
c0849ee1
MJ
440 if ( { vergte "${kversion}" "4.12"; } && { verlt "${kversion}" "4.20.17"; } ) || \
441 ( { vergte "${kversion}" "5.0"; } && { verlt "${kversion}" "5.0.12"; } ) ; then
7b15f9fa
KS
442 # Old kernels can fail to build while on newer host kernels with errors
443 # such as:
444 # In file included from scripts/selinux/genheaders/genheaders.c:19:
445 # ./security/selinux/include/classmap.h:249:2: error: #error New address family defined, please update secclass_map.
a86b55bc
KS
446 # @see https://gitlab.com/linux-kernel/stable/-/commit/dfbd199a7cfe3e3cd8531e1353cdbd7175bfbc5e
447 #
448 patch_linux_kernel dfbd199a7cfe3e3cd8531e1353cdbd7175bfbc5e
449 fi
450
c05bf06f
MJ
451 # Compatibility with binutils >= ~ 2.31
452 if { vergte "${kversion}" "3.19"; } && { verlt "${kversion}" "4.16"; } ; then
a86b55bc
KS
453 patch_linux_kernel b21ebf2fb4cde1618915a97cc773e287ff49173e
454 fi
c05bf06f
MJ
455 if { vergte "${kversion}" "3.17"; } && { verlt "${kversion}" "3.18.69"; } ; then
456 patch_linux_kernel edb9d2d5e647e7a8521b0d35f8452deb02dfd138
457 fi
458 if { vergte "${kversion}" "3.17"; } && { verlt "${kversion}" "3.18.100"; } ; then
459 patch_linux_kernel 3be6583f0b6f1bf1ee650ebf473d9dee36836527
460 patch_linux_kernel 12d839211d080f6a9c370398c41a260365d34c62
461 fi
462 if { vergte "${kversion}" "3.16"; } && { verlt "${kversion}" "3.16.82"; } ; then
463 patch_linux_kernel ad10e6d464796f2a481de4039a43b9cfca034e1c
a86b55bc
KS
464 fi
465
4d7942d1 466 if ( { vergte "${kversion}" "3.14"; } && { verlt "${kversion}" "4.4"; } ) ||
9ae537d7 467 ( { vergte "${kversion}" "4.8"; } && { verlt "${kversion}" "4.18"; } ); then
a86b55bc 468 # While the original motivation of this patch is for fixing builds using
4d7942d1 469 # clang, the same error occurs between linux >= 3.14 and < 4.4, and in
a86b55bc 470 # 4.15, 4.16.
9ae537d7 471 # For rt-linux, the error has been observed in 4.8, 4.11, and 4.13.
a86b55bc
KS
472 #
473 # This patch only partially applies due to changes in kernel/Makefile,
474 # so a supplementary patch is needed
475 #
476 # Without this patch, builds fail with
477 # Cannot find symbol for section 2: .text.
478 # kernel/elfcore.o: failed
479 #
480 # @see https://github.com/linuxppc/issues/issues/388
481 # @see https://lore.kernel.org/lkml/20201204165742.3815221-2-arnd@kernel.org/
482 #
483 patch_linux_kernel 6e7b64b9dd6d96537d816ea07ec26b7dedd397b9
484 if grep -q elfcore.o kernel/Makefile ; then
485 sed -i '/^.* += elfcore.o$/d' kernel/Makefile
486 fi
487 fi
9bbfa9db
MJ
488 # Same as above for the v4.4 branch
489 if ( { vergte "${kversion}" "4.4"; } && { verlt "${kversion}" "4.4.257"; } ); then
490 patch_linux_kernel 3140b0740b31cc63cf2ee08bc3f746b423eb068d
491 if grep -q elfcore.o kernel/Makefile ; then
492 sed -i '/^.* += elfcore.o$/d' kernel/Makefile
493 fi
494 fi
a86b55bc 495
15ef760e 496 if { vergte "${kversion}" "4.5"; } && { verlt "${kversion}" "4.8"; } ; then
53300bf0
MJ
497 # Kernels between v4.5 and v4.8 built with gcc >= 8 on arm will hit an
498 # assembler error :
15ef760e
MJ
499 #
500 # kernel/.tmp_fork.s: Assembler messages:
501 # kernel/.tmp_fork.s:1790: Error: .err encountered
53300bf0
MJ
502 #
503 # @see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85745
15ef760e
MJ
504 #
505 patch_linux_kernel 9f73bd8bb445e0cbe4bcef6d4cfc788f1e184007
506 fi
507
c0849ee1
MJ
508 if ( { vergte "${kversion}" "4.4"; } && { verlt "${kversion}" "4.4.136"; } ) ||
509 ( { vergte "${kversion}" "4.5"; } && { verlt "${kversion}" "4.8"; } ); then
9ae537d7
KS
510 # Hacky patch to deal with the following build error:
511 # Cannot find symbol for section 7: .text.unlikely.
512 # kernel/kexec_file.o: failed
513 # make[1]: *** [scripts/Makefile.build:291: kernel/kexec_file.o] Error 1
514 #
515 # This error happens with binutils 2.36 and 2.37, but should probably not
516 # be an issue with binutils 2.38.
517 # @see https://github.com/linuxppc/issues/issues/388
518 # @see https://github.com/bminor/binutils-gdb/commit/c09c8b42021180eee9495bd50d8b35e683d3901b
519 #
520 # There is some sort of config (unspecified in past discussions) which
521 # provokes the error, and there was never a potential fix merged in
522 # this discussion, in part because the build systems of the kernel
523 # switched to objtool instead.
524 #
525 # @see https://lore.kernel.org/all/20210215162209.5e2a475b@gandalf.local.home/
526 #
527 sed -i 's/return txtname;/return shdr0->sh_size ? txtname : NULL;/' scripts/recordmcount.h
528
529 # After applying the above patch, the build continues but fails with
530 # head64.c:(.text.exit+0x5): undefined reference to `__gcov_exit'
531 #
532 scripts/config --disable CONFIG_GCOV_KERNEL
533 fi
534
c0849ee1
MJ
535 if { vergte "${kversion}" "4.5"; } && { verlt "${kversion}" "4.5.5"; } ; then
536 # drivers/staging/wilc1000/wilc_spi.c:123:34: error: storage size of ‘wilc1000_spi_ops’ isn’t known
537 patch_linux_kernel ce7b516f3f9e11fe4ee06fad0d7e853bb6e8f160
538 fi
539
53b51a15
MJ
540 # Newer binutils don't accept 3 operand 'cmp' instructions on ppc64
541 # Convert them to 'cmpw' which was previously done silently
542 if verlt "$kversion" "4.9"; then
53300bf0
MJ
543 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/"
544 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/"
545 sed -i "s/\$pie \-o \"\$ofile\"/\$pie --no-dynamic-linker -o \"\$ofile\"/" arch/powerpc/boot/wrapper
53b51a15
MJ
546 fi
547
9ae537d7
KS
548 if [ "$(scripts/config --state CONFIG_EXTCON_ADC_JACK)" != "n" ] &&
549 ( { vergte "${kversion}" "4.2"; } && { verlt "${kversion}" "4.12"; } ); then
550 # 73b6ecdb93e8e77752cae9077c424fcdc6f23c39 introduced a change where
551 # extcon-adc-jack.h has an incompatible pointer type.
552 # In GCC >= 5 this will provoke a warning and build failure.
553 # Eg.
554 # drivers/extcon/extcon-adc-jack.c: In function ‘adc_jack_probe’:
555 # drivers/extcon/extcon-adc-jack.c:111:64: error: passing argument 2 of ‘devm_extcon_dev_allocate’ from incompatible pointer type [-Werror=incompatible-pointer-types]
556 # make[2]: *** [scripts/Makefile.build:295: drivers/extcon/extcon-adc-jack.o] Error 1
557 #
558 # 8a522bf2d4f788306443d36b26b54f0aedcdfdbe (in 4.11) has a fix for this warning
559 #
560 patch_linux_kernel 8a522bf2d4f788306443d36b26b54f0aedcdfdbe
561 fi
562
9383502e
MJ
563 if ( { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.15.2"; } ) || \
564 ( { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.18"; } ) ; then
565 # Fix an objtool Segmentation fault
566 patch_linux_kernel dd12561854824fd1f05baf2a1b794faa046e2425
567 fi
568
569 if { vergte "${kversion}" "4.14"; } && { verlt "${kversion}" "4.14.268"; } ; then
570 # Builds fail due to -Werror=use-after-free in sigchain.o and help.o
571 patch_linux_kernel e89bb266b710ce056f141f29f091fd468a4a8185
572 fi
573
5a196804
MJ
574 # Fix a typo in v2.6.36.x
575 if [ -f "arch/x86/kernel/entry_64.S" ]; then
576 sed -i 's/END(do_hypervisor_callback)/END(xen_do_hypervisor_callback)/' arch/x86/kernel/entry_64.S
577 fi
578
53b51a15
MJ
579 # Fix compiler switch in vdso Makefile for 2.6.36 to 2.6.36.2
580 if { vergte "$kversion" "2.6.36" && verlte "$kversion" "2.6.36.3"; }; then
581 sed -i 's/-m elf_x86_64/-m64/' arch/x86/vdso/Makefile
582 sed -i 's/-m elf_i386/-m32/' arch/x86/vdso/Makefile
583 fi
584
5a196804
MJ
585 # Fix kernel < 3.0 with gcc >= 4.7
586 if verlt "$kversion" "3.0"; then
587 sed -i '/linux\/compiler.h/a #include <linux\/linkage.h> \/* For asmregparm *\/' arch/x86/include/asm/ptrace.h
588 sed -i 's/extern long syscall_trace_enter/extern asmregparm long syscall_trace_enter/' arch/x86/include/asm/ptrace.h
589 sed -i 's/extern void syscall_trace_leave/extern asmregparm void syscall_trace_leave/' arch/x86/include/asm/ptrace.h
590 echo "header-y += linkage.h" >> include/linux/Kbuild
591 fi
592
a86b55bc
KS
593 if [ "${cross_arch}" = "powerpc" ] ; then
594 if { vergte "${kversion}" "4.15"; } && { verlt "${kversion}" "4.16"; } ; then
595 # Avoid register errors such as
596 # aes_generic.c:(.text+0x4e0): undefined reference to `_restgpr_31_x'
597 # @see https://gitlab.com/linux-kernel/stable/-/commit/148b974deea927f5dbb6c468af2707b488bfa2de
598 make_args+=(
599 CFLAGS_aes_generic.o=''
600 )
601 fi
602 fi
603
23ebcd4b
KS
604 if [ "$(scripts/config --state CONFIG_DEBUG_INFO_BTF)" == "y" ] &&
605 { vergte "${pahole_version}" "1.24"; } &&
606 { vergte "${kversion}" "5.10"; } && { verlt "${kversion}" "6.0"; } ;then
607 # Some kernels Eg. Ubuntu-hwe-5.13-5.13.0-52.59_20.04.1
608 # fail with the following error:
609 # BTFIDS vmlinux
610 # FAILED: load BTF from vmlinux: Invalid argument
611 #
612 # When CONFIG_DEBUG_INFO_BTF is set, certain versions of pahole require
613 # `--skip_encoding_btf_enum64` to be passed as the kernel doesn't define
614 # BTF_KIND_ENUM64.
615 #
616 # Introduced in 341dfcf8d78eaa3a2dc96dea06f0392eb2978364 (~v5.10)
617 # @see https://lore.kernel.org/bpf/20220825171620.cioobudss6ovyrkc@altlinux.org/t/
618 #
619 if [ -f "scripts/pahole-flags.sh" ] ; then
53300bf0 620 # shellcheck disable=SC2016
23ebcd4b
KS
621 sed -i 's/ -J ${PAHOLE_FLAGS} / -J ${PAHOLE_FLAGS} --skip_encoding_btf_enum64 /' scripts/link-vmlinux.sh
622 else
53300bf0 623 # shellcheck disable=SC2016
23ebcd4b
KS
624 sed -i 's/ -J ${extra_paholeopt} / -J ${extra_paholeopt} --skip_encoding_btf_enum64 /' scripts/link-vmlinux.sh
625 fi
626 fi
627
7e02032c 628 # GCC 4.8
53b51a15 629 if [ "$HOSTCC" == "gcc-4.8" ]; then
a86b55bc
KS
630 scripts/config --disable CONFIG_CC_STACKPROTECTOR_STRONG
631 scripts/config --disable CONFIG_PPC_OF_BOOT_TRAMPOLINE
53b51a15 632 fi
7e02032c
MJ
633
634 # Don't try to sign modules
53b51a15 635 scripts/config --disable CONFIG_MODULE_SIG
7e02032c 636
9ef18fa2 637 # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails
53b51a15 638 scripts/config --disable CONFIG_STACK_VALIDATION
5a196804
MJ
639
640 # Cause problems with inline assembly on i386
53b51a15 641 scripts/config --disable CONFIG_DEBUG_SECTION_MISMATCH
5a196804 642
1d5a0a3c 643 # Don't build samples, they are broken on some kernel releases
53b51a15
MJ
644 scripts/config --disable CONFIG_SAMPLES
645 scripts/config --disable CONFIG_BUILD_DOCSRC
c45b04df
MJ
646
647 # Disable kcov
53b51a15 648 scripts/config --disable CONFIG_KCOV
c45b04df
MJ
649
650 # Broken on some RT kernels
53b51a15 651 scripts/config --disable CONFIG_HYPERV
1d5a0a3c 652
1e300ea9 653 # Broken drivers
53b51a15
MJ
654 scripts/config --disable CONFIG_RAPIDIO_TSI721
655 scripts/config --disable CONFIG_SGI_XP
656 scripts/config --disable CONFIG_MFD_WM8994
657 scripts/config --disable CONFIG_DRM_RADEON
658 scripts/config --disable CONFIG_SND_SOC_WM5100
a9aea01c
KS
659 # More recent compiler optimizations (from gcc 8 onwards )expose build errors
660 # with netronome on older kernels.
661 # Observed in 4.11-rt, 4.15-4.17, 5.0-rt - 5.16-rt
662 # It seems easier to disable the driver than to attempt patching.
663 # Eg.
664 # In function ‘ur_load_imm_any’,
665 # inlined from ‘jeq_imm’ at drivers/net/ethernet/netronome/nfp/bpf/jit.c:3146:13:
666 # ./include/linux/compiler.h:350:45: error: call to ‘__compiletime_assert_1062’ declared with attribute error: FIELD_FIT: value too large for the field
667 # 350 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
668 #
669 scripts/config --disable CONFIG_NET_VENDOR_NETRONOME
670 # Eg.
671 # In function ‘memcpy’,
672 # inlined from ‘kszphy_get_strings’ at drivers/net/phy/micrel.c:664:3:
673 # ./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
674 # 305 | __read_overflow2();
675 # | ^~~~~~~~~~~~~~~~~~
676 # make[3]: *** [scripts/Makefile.build:308: drivers/net/phy/micrel.o] Error 1
677 #
678 scripts/config --disable CONFIG_MICREL_PHY
679
1e300ea9 680
5a196804
MJ
681 # IGBVF won't build with recent gcc on 2.6.38.x
682 if { vergte "$kversion" "2.6.37" && verlt "$kversion" "2.6.38"; }; then
53b51a15 683 scripts/config --disable CONFIG_IGBVF
5a196804 684 fi
9ef18fa2 685
c72041eb
MJ
686 # Don't fail the build on warnings
687 scripts/config --disable CONFIG_WERROR
a86b55bc 688 scripts/config --enable CONFIG_PPC_DISABLE_WERROR
c72041eb 689
51fa2ab3 690 # Set required options
53b51a15
MJ
691 scripts/config --enable CONFIG_TRACEPOINTS
692 scripts/config --enable CONFIG_KALLSYMS
693 scripts/config --enable CONFIG_HIGH_RES_TIMERS
694 scripts/config --enable CONFIG_KPROBES
695 scripts/config --enable CONFIG_FTRACE
696 scripts/config --enable CONFIG_BLK_DEV_IO_TRACE
697 scripts/config --enable CONFIG_KALLSYMS_ALL
698 scripts/config --enable CONFIG_HAVE_SYSCALL_TRACEPOINTS
699 scripts/config --enable CONFIG_PERF_EVENTS
700 scripts/config --enable CONFIG_EVENT_TRACING
701 scripts/config --enable CONFIG_KRETPROBES
7e02032c 702
a86b55bc
KS
703 if [ -n "${DEBUG}" ] ; then
704 cat .config
705 fi
5a196804 706
a86b55bc
KS
707 make "$update_conf_target" "${make_args[@]}"
708 make -j"$NPROC" "${make_args[@]}"
5a196804 709
80eda7bb 710 krelease=$(make -s kernelrelease "${make_args[@]}")
5a196804
MJ
711
712 # Save the kernel and modules
713 mkdir -p "$LINUX_INSTOBJ_DIR/boot"
a86b55bc
KS
714 make INSTALL_MOD_PATH="$LINUX_INSTOBJ_DIR" INSTALL_MOD_STRIP=1 modules_install "${make_args[@]}"
715 make INSTALL_MOD_PATH="$LINUX_INSTOBJ_DIR" INSTALL_PATH="$LINUX_INSTOBJ_DIR/boot" install "${make_args[@]}"
5a196804
MJ
716 rm -f "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source" "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/build"
717 ln -s ../../../../sources "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source"
718 ln -s ../../../../sources "$LINUX_INSTOBJ_DIR/lib/modules/${krelease}/source"
719}
720
721
722extract_distro_headers() {
723
724 # Enter linux source dir
725 cd "${LINUX_SRCOBJ_DIR}"
726
727
728 # For RT kernels, copy version file
729 if [ -s localversion-rt ]; then
730 cp -a localversion-rt "${LINUX_HDROBJ_DIR}"
731 fi
732
733 # Copy all Makefile related stuff
734 find . -path './include/*' -prune \
735 -o -path './scripts/*' -prune -o -type f \
736 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
737 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
738 -print | cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
739
740 # Copy base scripts and include dirs
741 cp -a scripts include "${LINUX_HDROBJ_DIR}"
7e02032c 742
5a196804
MJ
743 # Copy arch includes
744 (find arch -name include -type d -print0 | \
efdab1b7 745 xargs -0 -n1 -I '{}' find '{}' -type f) | \
5a196804
MJ
746 cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
747
748 # Copy arch scripts
749 (find arch -name scripts -type d -print0 | \
efdab1b7 750 xargs -0 -n1 -I '{}' find '{}' -type f) | \
5a196804
MJ
751 cpio -pd --preserve-modification-time "${LINUX_HDROBJ_DIR}"
752
753 # Cleanup scripts
754 rm -f "${LINUX_HDROBJ_DIR}/scripts/*.o"
755 rm -f "${LINUX_HDROBJ_DIR}/scripts/*/*.o"
756
04873cc3 757 # On powerpc 32bits this object is required to link modules
5a196804 758 if [ "${karch}" = "powerpc" ]; then
efdab1b7 759 if [ "$(scripts/config -s CONFIG_PPC64)" = "y" ] && vergte "${kversion}" "5.4"; then
10528202
MJ
760 :
761 else
04873cc3
MJ
762 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LINUX_HDROBJ_DIR}/"
763 fi
5a196804
MJ
764 fi
765
766 # On arm64 between 4.13 and 1.15 this object is required to build with ftrace support
767 if [ "${karch}" = "arm64" ]; then
768 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
769 cp -a --parents arch/arm64/kernel/ftrace-mod.[So] "${LINUX_HDROBJ_DIR}/"
770 fi
771 fi
772
773 # Newer kernels need objtool to build modules when CONFIG_STACK_VALIDATION=y
774 if [ -f tools/objtool/objtool ]; then
775 cp -a --parents tools/objtool/objtool "${LINUX_HDROBJ_DIR}/"
776 fi
777
778 if [ -f "arch/x86/kernel/macros.s" ]; then
779 cp -a --parents arch/x86/kernel/macros.s "${LINUX_HDROBJ_DIR}/"
780 fi
781
782 # Copy modules related stuff, if available
783 if [ -s Module.symvers ]; then
784 cp Module.symvers "${LINUX_HDROBJ_DIR}"
785 fi
786
787 if [ -s System.map ]; then
788 cp System.map "${LINUX_HDROBJ_DIR}"
789 fi
790
791 if [ -s Module.markers ]; then
792 cp Module.markers "${LINUX_HDROBJ_DIR}"
793 fi
794
795 # Copy config file
796 cp .config "${LINUX_HDROBJ_DIR}"
797
798 # Make sure the Makefile and version.h have a matching timestamp so that
799 # external modules can be built
800 if [ -s "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h" ]; then
801 touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/generated/uapi/linux/version.h"
802 elif [ -s "${LINUX_HDROBJ_DIR}/include/linux/version.h" ]; then
803 touch -r "${LINUX_HDROBJ_DIR}/Makefile" "${LINUX_HDROBJ_DIR}/include/linux/version.h"
804 else
805 echo "Missing version.h"
806 exit 1
807 fi
808 touch -r "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/generated/autoconf.h"
809
810 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
780f6285
MJ
811 if [ ! -f "${LINUX_HDROBJ_DIR}/include/config/auto.conf" ]; then
812 cp "${LINUX_HDROBJ_DIR}/.config" "${LINUX_HDROBJ_DIR}/include/config/auto.conf"
813 fi
5a196804
MJ
814
815 # Finally clean the object files from the full source tree
816 make clean
817
818 # And regen the modules support files
a86b55bc 819 make modules_prepare "${make_args[@]}"
51fa2ab3 820
04873cc3 821 # On powerpc 32bits this object is required to link modules
d815b018 822 if [ "${karch}" = "powerpc" ]; then
efdab1b7 823 if [ "$(scripts/config -s CONFIG_PPC64)" = "y" ] && vergte "${kversion}" "5.4"; then
10528202
MJ
824 :
825 else
a86b55bc 826 make arch/powerpc/lib/crtsavres.o "${make_args[@]}"
04873cc3 827 fi
d815b018
MJ
828 fi
829
7a76a4d0 830 # On arm64 between 4.13 and 4.15 this object is required to build with ftrace support
a1ae361e 831 if [ "${karch}" = "arm64" ]; then
c236528e 832 if [ -f "arch/arm64/kernel/ftrace-mod.S" ]; then
a86b55bc 833 make arch/arm64/kernel/ftrace-mod.o "${make_args[@]}"
a1ae361e
MJ
834 fi
835 fi
836
7e02032c 837 # Version specific tasks
a1ae361e 838 case "$ktag" in
7e02032c
MJ
839 Ubuntu*)
840 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
a1ae361e 841 ABINUM="$(echo "$ktag" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')"
5a196804
MJ
842 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> include/generated/utsrelease.h
843 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${LINUX_HDROBJ_DIR}/include/generated/utsrelease.h"
7e02032c
MJ
844 ;;
845 esac
7e02032c
MJ
846}
847
848
339db64d
MJ
849build_modules() {
850
5a196804
MJ
851 local kdir="$1"
852 local outdir="$2"
853 local kversion
854
855 kversion=$(make -C "$LINUX_HDROBJ_DIR" -s kernelversion)
339db64d 856
2456f978
MJ
857 # Try to catch some compatibility problems by turning some
858 # warnings into errors.
999a2aa0 859 #export KCFLAGS="$KCFLAGS -Wall -Werror"
2456f978 860
339db64d 861 # Enter lttng-modules source dir
5a196804 862 cd "${MODULES_GIT_DIR}"
339db64d
MJ
863
864 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
865 # timekeeping subsystem. We want those build to fail.
5a196804
MJ
866 if { vergte "$kversion" "3.10" && verlte "$kversion" "3.10.13"; } || \
867 { vergte "$kversion" "3.11" && verlte "$kversion" "3.11.2"; }; then
339db64d
MJ
868
869 set +e
870
871 # Build modules
a86b55bc 872 KERNELDIR="${kdir}" make -j"${NPROC}" V=1 "${make_args[@]}"
53300bf0 873 ret=$?
339db64d 874
5a196804
MJ
875 set -e
876
339db64d 877 # We expect this build to fail, if it doesn't, fail the job.
0f71a764 878 if [ "$ret" -eq 0 ]; then
e9b44189 879 echo "This build should have failed."
339db64d
MJ
880 exit 1
881 fi
882
883 # We have to publish at least one file or the build will fail
5a196804 884 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${outdir}/BROKEN.txt.ko"
339db64d 885
5a196804 886 KERNELDIR="${kdir}" make clean
7e02032c 887
339db64d
MJ
888 else # Regular build
889
890 # Build modules against full kernel sources
a86b55bc 891 KERNELDIR="${kdir}" make -j"${NPROC}" V=1 "${make_args[@]}"
339db64d
MJ
892
893 # Install modules to build dir
5a196804 894 KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${outdir}" modules_install
339db64d
MJ
895
896 # Clean build dir
5a196804 897 KERNELDIR="${kdir}" make clean
339db64d
MJ
898 fi
899}
900
901
902## MAIN ##
903
f3d8604b
MJ
904# Use all CPU cores
905NPROC=$(nproc)
906
5a196804
MJ
907MODULES_GIT_DIR="${WORKSPACE}/src/lttng-modules"
908LINUX_GIT_DIR="${WORKSPACE}/src/linux"
339db64d 909
5a196804
MJ
910LINUX_OBJ_DIR="${WORKSPACE}/linux"
911LINUX_SRCOBJ_DIR="${LINUX_OBJ_DIR}/sources"
912LINUX_HDROBJ_DIR="${LINUX_OBJ_DIR}/headers"
913LINUX_INSTOBJ_DIR="${LINUX_OBJ_DIR}/install"
339db64d 914
5a196804
MJ
915MODULES_OUTPUT_KSRC_DIR="${WORKSPACE}/build/lttng-modules-ksrc"
916MODULES_OUTPUT_KHDR_DIR="${WORKSPACE}/build/lttng-modules-khdr"
339db64d 917
5a196804
MJ
918LINUX_GIT_REF_REPO_DIR="$HOME/gitcache/linux-stable.git/"
919
920OBJ_STORE_URL="s3://jenkins"
921
922cd "$WORKSPACE"
923
924# Create build directories
925mkdir -p "${LINUX_SRCOBJ_DIR}" "${LINUX_HDROBJ_DIR}" "${LINUX_INSTOBJ_DIR}" "${MODULES_OUTPUT_KSRC_DIR}" "${MODULES_OUTPUT_KHDR_DIR}"
926
53300bf0 927print_header "Clone LTTng-modules sources"
5a196804 928git_clone_modules_sources
339db64d 929
7e02032c 930# Setup cross compile env if available
39961776 931if [ "x${cross_arch}" != "x" ]; then
7e02032c
MJ
932
933 case "$cross_arch" in
934 "armhf")
935 karch="arm"
936 cross_compile="arm-linux-gnueabihf-"
53b51a15 937 vanilla_config="imx_v6_v7_defconfig"
7e02032c
MJ
938 ubuntu_config="armhf-config.flavour.generic"
939 ;;
940
941 "arm64")
942 karch="arm64"
943 cross_compile="aarch64-linux-gnu-"
53b51a15 944 vanilla_config="defconfig"
7e02032c
MJ
945 ubuntu_config="arm64-config.flavour.generic"
946 ;;
947
948 "powerpc")
949 karch="powerpc"
950 cross_compile="powerpc-linux-gnu-"
e9b44189 951 vanilla_config="ppc44x_defconfig"
7e02032c
MJ
952 ubuntu_config="powerpc-config.flavour.powerpc-smp"
953 ;;
954
955 "ppc64el")
956 karch="powerpc"
957 cross_compile="powerpc64le-linux-gnu-"
e9b44189 958 vanilla_config="pseries_le_defconfig"
7e02032c
MJ
959 ubuntu_config="ppc64el-config.flavour.generic"
960 ;;
961
962 *)
51fa2ab3 963 echo "Unsupported cross arch $cross_arch"
7e02032c
MJ
964 exit 1
965 ;;
966 esac
339db64d 967
7e02032c
MJ
968 # Export variables used by Kbuild for cross compilation
969 export ARCH="${karch}"
970 export CROSS_COMPILE="${cross_compile}"
339db64d 971
7e02032c 972# Set arch specific values if we are not cross compiling
39961776 973elif [ "x${arch}" != "x" ]; then
e9b44189 974
7e02032c 975 case "$arch" in
16844a6d 976 "i386")
7e02032c 977 karch="x86"
1490b049 978 vanilla_config="allmodconfig"
7e02032c
MJ
979 ubuntu_config="i386-config.flavour.generic"
980 ;;
981
16844a6d 982 "amd64")
7e02032c 983 karch="x86"
1490b049 984 vanilla_config="allmodconfig"
7e02032c
MJ
985 ubuntu_config="amd64-config.flavour.generic"
986 ;;
987
988 "armhf")
989 karch="arm"
1490b049 990 vanilla_config="allmodconfig"
7e02032c
MJ
991 ubuntu_config="armhf-config.flavour.generic"
992 ;;
993
994 "arm64")
995 karch="arm64"
1490b049 996 vanilla_config="allmodconfig"
7e02032c
MJ
997 ubuntu_config="arm64-config.flavour.generic"
998 ;;
999
1000 "powerpc")
1001 karch="powerpc"
1490b049 1002 vanilla_config="allmodconfig"
7e02032c
MJ
1003 ubuntu_config="powerpc-config.flavour.powerpc-smp"
1004 ;;
1005
1006 "ppc64el")
1007 karch="powerpc"
1490b049 1008 vanilla_config="allmodconfig"
7e02032c
MJ
1009 ubuntu_config="ppc64el-config.flavour.generic"
1010 ;;
1011
1012 *)
1013 echo "Unsupported arch $arch"
1014 exit 1
1015 ;;
1016 esac
1017else
04873cc3 1018 echo "No arch or cross_arch specified"
7e02032c
MJ
1019 exit 1
1020fi
339db64d 1021
339db64d 1022
b214d997 1023
5a196804
MJ
1024# First get the kernel build from the object store, or build it, if it's
1025# not available.
339db64d 1026
53300bf0 1027set +x
5a196804
MJ
1028echo "# Setup endpoint
1029host_base = obj.internal.efficios.com
1030host_bucket = obj.internal.efficios.com
1031bucket_location = us-east-1
1032use_https = True
7e02032c 1033
5a196804
MJ
1034# Setup access keys
1035access_key = jenkins
1036secret_key = echo123456
339db64d 1037
5a196804
MJ
1038# Enable S3 v4 signature APIs
1039signature_v2 = False" > "$WORKSPACE/.s3cfg"
53300bf0 1040set -x
339db64d 1041
c45b04df 1042url_hash="$(echo -n "$kgitrepo" | md5sum | awk '{ print $1 }')"
5a196804 1043obj_name="linux.tar.bz2"
87445931 1044
efdab1b7 1045if [ -z "${cross_arch}" ]; then
53300bf0 1046 obj_url_prefix="$OBJ_STORE_URL/linux-build/$url_hash/$ktag/platform-${platform}/$arch/native"
87445931 1047else
53300bf0 1048 obj_url_prefix="$OBJ_STORE_URL/linux-build/$url_hash/$ktag/platform-${platform}/${cross_arch}"
87445931
MJ
1049fi
1050
5a196804 1051obj_url="$obj_url_prefix/$obj_name"
339db64d 1052
5a196804 1053set +e
e18b6e95
KS
1054# In s3cmd 2.3, the return code of get when an object does not exist (64)
1055# is different than in 2.2 (12). The return codes of 's3cmd info' are
1056# consistent between 2.2 and 2.3.
1057s3cmd -c "$WORKSPACE/.s3cfg" info "$obj_url"
5a196804
MJ
1058ret=$?
1059set -e
339db64d 1060
5a196804
MJ
1061case "$ret" in
1062 "0")
53300bf0 1063 print_header "Get sources and prebuilt kernel"
e18b6e95 1064 s3cmd -c "$WORKSPACE/.s3cfg" get "$obj_url"
5a196804 1065 extract_archive_obj
53300bf0
MJ
1066
1067 print_header "Select compiler and set build flags"
1068 select_compiler
1069 export_kbuild_flags
5a196804 1070 ;;
a1ae361e 1071
5a196804 1072 "12")
53300bf0 1073 print_header "Clone kernel sources"
339db64d 1074
5a196804
MJ
1075 # Build all the things and upload
1076 # then finish the module build...
339db64d 1077
5a196804
MJ
1078 git_clone_linux_sources
1079 git_export_linux_sources
339db64d 1080
53300bf0 1081 print_header "Select compiler and set build flags"
5a196804 1082 select_compiler
53300bf0 1083 export_kbuild_flags
a1ae361e 1084
5a196804 1085 ## PREPARE FULL LINUX SOURCE TREE
53300bf0 1086 print_header "Build kernel from source"
5a196804 1087 build_linux_kernel
d138fc44 1088
5a196804
MJ
1089 ## EXTRACT DISTRO STYLE KERNEL HEADERS / DEVEL
1090 extract_distro_headers
339db64d 1091
53300bf0 1092 print_header "Upload kernel to object storage"
5a196804 1093 tar_archive_obj
5a196804 1094 upload_archive_obj
339db64d 1095
5a196804 1096 ;;
339db64d 1097
5a196804
MJ
1098 *)
1099 echo "Unknown error? Abort"
1100 exit 1
1101 ;;
1102esac
339db64d 1103
a86b55bc 1104
7e02032c 1105## BUILD modules
5a196804
MJ
1106# Either we downloaded a pre-build kernel or we built it and uploaded
1107# the archive for future builds.
1108
1109cd "$WORKSPACE"
f3d8604b 1110
53300bf0 1111print_header "Build modules against full kernel sources"
5a196804 1112build_modules "${LINUX_SRCOBJ_DIR}" "${MODULES_OUTPUT_KSRC_DIR}"
f3d8604b 1113
53300bf0 1114print_header "Build modules against kernel headers"
5a196804 1115build_modules "${LINUX_HDROBJ_DIR}" "${MODULES_OUTPUT_KHDR_DIR}"
f3d8604b 1116
53300bf0
MJ
1117
1118print_header "Check for built modules in install directory"
1119
5a196804
MJ
1120# Make sure some modules were actually built
1121tree "${MODULES_OUTPUT_KSRC_DIR}"
1122if [ "x$(find "${MODULES_OUTPUT_KSRC_DIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
7e02032c
MJ
1123 echo "No modules built!"
1124 exit 1
1125fi
1126
5a196804
MJ
1127tree "${MODULES_OUTPUT_KHDR_DIR}"
1128if [ "x$(find "${MODULES_OUTPUT_KHDR_DIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
7e02032c
MJ
1129 echo "No modules built!"
1130 exit 1
1131fi
b214d997 1132
f3d8604b 1133# EOF
This page took 0.084262 seconds and 4 git commands to generate.