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