jjb: lava: kprobe-fuzzing: Don't fuzz ftrace functions
[lttng-ci.git] / scripts / latency-tracker / param-build.sh
CommitLineData
81fa42ce
MJ
1#!/bin/sh -exu
2#
3# Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
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
6f1411b1
MJ
18# Parameters
19arch=${arch:-}
20cross_arch=${cross_arch:-}
21ktag=${ktag:-}
22
23
81fa42ce
MJ
24## FUNCTIONS ##
25
26# Kernel version compare functions
27verlte() {
6f1411b1 28 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | head -n1)" ]
81fa42ce
MJ
29}
30
31verlt() {
6f1411b1 32 [ "$1" = "$2" ] && return 1 || verlte "$1" "$2"
81fa42ce
MJ
33}
34
35vergte() {
6f1411b1 36 [ "$1" = "$(printf '%s\n%s' "$1" "$2" | sort -V | tail -n1)" ]
81fa42ce
MJ
37}
38
39vergt() {
6f1411b1 40 [ "$1" = "$2" ] && return 1 || vergte "$1" "$2"
81fa42ce
MJ
41}
42
43
44prepare_lnx_sources() {
45
46 outdir=$1
47
48 if [ "$outdir" = "." ]; then
49 koutput=""
50 else
cbd45bc3 51 koutput="O=${outdir}"
81fa42ce
MJ
52 fi
53
54 # Generate kernel configuration
6f1411b1 55 case "$ktag" in
81fa42ce 56 Ubuntu*)
6f1411b1
MJ
57 if [ "${cross_arch}" = "powerpc" ]; then
58 if vergte "$KVERSION" "4.10"; then
59 echo "Ubuntu removed big endian powerpc configuration from kernel >= 4.10. Don't try to build it."
60 exit 0
61 fi
62 fi
81fa42ce
MJ
63 fakeroot debian/rules clean
64 fakeroot debian/rules genconfigs
6f1411b1 65 cp CONFIGS/"${ubuntu_config}" "${outdir}"/.config
81fa42ce
MJ
66 ;;
67 *)
68 # Que sera sera
6f1411b1 69 make "${vanilla_config}" CC="$CC" ${koutput}
81fa42ce
MJ
70 ;;
71 esac
72
73 # GCC 4.8
74 sed -i "s/CONFIG_CC_STACKPROTECTOR_STRONG=y/# CONFIG_CC_STACKPROTECTOR_STRONG is not set/g" "${outdir}"/.config
75
76 # Don't try to sign modules
77 sed -i "s/CONFIG_MODULE_SIG=y/# CONFIG_MODULE_SIG is not set/g" "${outdir}"/.config
78
79 # Disable kernel stack frame correctness validation, introduced in 4.6.0 and currently fails
80 sed -i "s/CONFIG_STACK_VALIDATION=y/# CONFIG_STACK_VALIDATION is not set/g" "${outdir}"/.config
81
6f1411b1
MJ
82 # Set required options
83 {
84 echo "CONFIG_KPROBES=y";
85 echo "CONFIG_FTRACE=y";
86 echo "CONFIG_BLK_DEV_IO_TRACE=y";
87 echo "CONFIG_TRACEPOINTS=y";
88 echo "CONFIG_KALLSYMS_ALL=y";
89 } >> "${outdir}"/.config
90
91
92 make "$oldconf_target" CC="$CC" ${koutput}
93 make modules_prepare CC="$CC" ${koutput}
94
95 # Debug
96 #cat "${outdir}"/.config
81fa42ce 97
6f1411b1
MJ
98 # On powerpc this object is required to link modules
99 if [ "${karch}" = "powerpc" ]; then
100 make arch/powerpc/lib/crtsavres.o CC="$CC" ${koutput}
101 fi
81fa42ce 102
6f1411b1
MJ
103 # On arm64 this object is required to build with ftrace support
104 if [ "${karch}" = "arm64" ]; then
105 if vergte "$KVERSION" "4.13-rc1"; then
106 make arch/arm64/kernel/ftrace-mod.o CC="$CC" ${koutput}
107 fi
108 fi
81fa42ce
MJ
109
110 # Version specific tasks
6f1411b1 111 case "$ktag" in
81fa42ce
MJ
112 Ubuntu*)
113 # Add Ubuntu ABI number to kernel headers, this is normally done by the packaging code
6f1411b1
MJ
114 ABINUM="$(echo "$ktag" | grep -P -o 'Ubuntu-(lts-)?.*-\K\d+(?=\..*)')"
115 echo "#define UTS_UBUNTU_RELEASE_ABI $ABINUM" >> "${outdir}"/include/generated/utsrelease.h
81fa42ce
MJ
116 ;;
117 esac
81fa42ce
MJ
118}
119
120
121
122build_modules() {
123
124 kdir="$1"
125 bdir="$2"
126
81fa42ce
MJ
127 # Enter latency-tracker source dir
128 cd "${LTTSRCDIR}"
129
130 # kernels 3.10 to 3.10.13 and 3.11 to 3.11.2 introduce a deadlock in the
131 # timekeeping subsystem. We want those build to fail.
6f1411b1
MJ
132 if { vergte "$KVERSION" "3.10" && verlte "$KVERSION" "3.10.13"; } || \
133 { vergte "$KVERSION" "3.11" && verlte "$KVERSION" "3.11.2"; }; then
81fa42ce
MJ
134
135 set +e
136
137 # Build modules
6f1411b1 138 KERNELDIR="${kdir}" make -j"${NPROC}" V=1 CC="$CC"
81fa42ce
MJ
139
140 # We expect this build to fail, if it doesn't, fail the job.
141 if [ "$?" -eq 0 ]; then
e9b44189 142 echo "This build should have failed."
81fa42ce
MJ
143 exit 1
144 fi
145
146 # We have to publish at least one file or the build will fail
147 echo "This kernel is broken, there is a deadlock in the timekeeping subsystem." > "${bdir}/BROKEN.txt.ko"
148
149 set -e
150
6f1411b1 151 KERNELDIR="${kdir}" make clean CC="$CC"
81fa42ce
MJ
152
153 else # Regular build
154
155 # Build modules against full kernel sources
6f1411b1 156 KERNELDIR="${kdir}" make -j"${NPROC}" V=1 CC="$CC"
81fa42ce
MJ
157
158 # Install modules to build dir
6f1411b1 159 KERNELDIR="${kdir}" make INSTALL_MOD_PATH="${bdir}" modules_install CC="$CC"
81fa42ce
MJ
160
161 # Clean build dir
6f1411b1 162 KERNELDIR="${kdir}" make clean CC="$CC"
81fa42ce
MJ
163 fi
164}
165
166
167## MAIN ##
168
81fa42ce
MJ
169# Use all CPU cores
170NPROC=$(nproc)
171
172LTTSRCDIR="${WORKSPACE}/src/latency-tracker"
173LNXSRCDIR="${WORKSPACE}/src/linux"
174
175LNXBUILDDIR="${WORKSPACE}/build/linux"
176LNXHDRDIR="${WORKSPACE}/build/linux-headers"
177
178LTTBUILDKSRCDIR="${WORKSPACE}/build/latency-tracker-ksrc"
179LTTBUILDKHDRDIR="${WORKSPACE}/build/latency-tracker-khdr"
180
181
182# Setup cross compile env if available
6f1411b1 183if [ "x${cross_arch}" != "x" ]; then
81fa42ce
MJ
184
185 case "$cross_arch" in
186 "armhf")
187 karch="arm"
188 cross_compile="arm-linux-gnueabihf-"
6f1411b1 189 vanilla_config="allyesconfig"
81fa42ce
MJ
190 ubuntu_config="armhf-config.flavour.generic"
191 ;;
192
193 "arm64")
194 karch="arm64"
195 cross_compile="aarch64-linux-gnu-"
6f1411b1 196 vanilla_config="allyesconfig"
81fa42ce
MJ
197 ubuntu_config="arm64-config.flavour.generic"
198 ;;
199
200 "powerpc")
201 karch="powerpc"
202 cross_compile="powerpc-linux-gnu-"
6f1411b1 203 vanilla_config="ppc44x_defconfig"
81fa42ce
MJ
204 ubuntu_config="powerpc-config.flavour.powerpc-smp"
205 ;;
206
207 "ppc64el")
208 karch="powerpc"
209 cross_compile="powerpc64le-linux-gnu-"
6f1411b1 210 vanilla_config="pseries_le_defconfig"
81fa42ce
MJ
211 ubuntu_config="ppc64el-config.flavour.generic"
212 ;;
213
214 *)
6f1411b1 215 echo "Unsupported cross arch $cross_arch"
81fa42ce
MJ
216 exit 1
217 ;;
218 esac
219
6f1411b1
MJ
220 # Use gcc 4.9, older kernel don't build with gcc 5
221 CC="${cross_compile}gcc-4.9"
e9b44189 222
81fa42ce
MJ
223 # Export variables used by Kbuild for cross compilation
224 export ARCH="${karch}"
225 export CROSS_COMPILE="${cross_compile}"
226
6f1411b1
MJ
227 oldconf_target="olddefconfig"
228
81fa42ce 229# Set arch specific values if we are not cross compiling
6f1411b1 230elif [ "x${arch}" != "x" ]; then
e9b44189 231
81fa42ce
MJ
232 case "$arch" in
233 "x86-32")
234 karch="x86"
6f1411b1 235 vanilla_config="allyesconfig"
81fa42ce
MJ
236 ubuntu_config="i386-config.flavour.generic"
237 ;;
238
239 "x86-64")
240 karch="x86"
6f1411b1 241 vanilla_config="allyesconfig"
81fa42ce
MJ
242 ubuntu_config="amd64-config.flavour.generic"
243 ;;
244
245 "armhf")
246 karch="arm"
6f1411b1 247 vanilla_config="allyesconfig"
81fa42ce
MJ
248 ubuntu_config="armhf-config.flavour.generic"
249 ;;
250
251 "arm64")
252 karch="arm64"
6f1411b1 253 vanilla_config="allyesconfig"
81fa42ce
MJ
254 ubuntu_config="arm64-config.flavour.generic"
255 ;;
256
257 "powerpc")
258 karch="powerpc"
6f1411b1 259 vanilla_config="allyesconfig"
81fa42ce
MJ
260 ubuntu_config="powerpc-config.flavour.powerpc-smp"
261 ;;
262
263 "ppc64el")
264 karch="powerpc"
6f1411b1 265 vanilla_config="allyesconfig"
81fa42ce
MJ
266 ubuntu_config="ppc64el-config.flavour.generic"
267 ;;
268
269 *)
270 echo "Unsupported arch $arch"
271 exit 1
272 ;;
273 esac
e9b44189
MJ
274
275 # Use gcc 4.9, older kernel don't build with gcc 5
276 CC=gcc-4.9
277
6f1411b1
MJ
278 oldconf_target="silentoldconfig"
279
81fa42ce
MJ
280else
281 echo "Not arch or cross_arch specified"
282 exit 1
283fi
284
285
286
287
288# Create build directories
289mkdir -p "${LNXBUILDDIR}" "${LNXHDRDIR}" "${LTTBUILDKSRCDIR}" "${LTTBUILDKHDRDIR}"
290
291
292
293## PREPARE DISTRO STYLE KERNEL HEADERS / DEVEL
294
295# Enter linux source dir
296cd "${LNXSRCDIR}"
297
6f1411b1
MJ
298# Get kernel version from source tree
299KVERSION=$(make kernelversion)
300
81fa42ce
MJ
301prepare_lnx_sources "."
302
303# For RT kernels, copy version file
304if [ -s localversion-rt ]; then
305 cp -a localversion-rt "${LNXHDRDIR}"
306fi
307
308# Copy all Makefile related stuff
309find . -path './include/*' -prune \
310 -o -path './scripts/*' -prune -o -type f \
311 \( -name 'Makefile*' -o -name 'Kconfig*' -o -name 'Kbuild*' -o \
312 -name '*.sh' -o -name '*.pl' -o -name '*.lds' \) \
313 -print | cpio -pd --preserve-modification-time "${LNXHDRDIR}"
314
315# Copy base scripts and include dirs
316cp -a scripts include "${LNXHDRDIR}"
317
318# Copy arch includes
6f1411b1
MJ
319(find arch -name include -type d -print0 | \
320 xargs -0 -n1 -i: find : -type f) | \
81fa42ce
MJ
321 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
322
323# Copy arch scripts
6f1411b1
MJ
324(find arch -name scripts -type d -print0 | \
325 xargs -0 -n1 -i: find : -type f) | \
81fa42ce
MJ
326 cpio -pd --preserve-modification-time "${LNXHDRDIR}"
327
328# Cleanup scripts
329rm -f "${LNXHDRDIR}/scripts/*.o"
330rm -f "${LNXHDRDIR}/scripts/*/*.o"
331
332# On powerpc this object is required to link modules
333if [ "${karch}" = "powerpc" ]; then
334 cp -a --parents arch/powerpc/lib/crtsavres.[So] "${LNXHDRDIR}/"
335fi
336
6f1411b1
MJ
337# On arm64 this object is required to build with ftrace support
338if [ "${karch}" = "arm64" ]; then
339 if vergte "$KVERSION" "4.13-rc1"; then
340 cp -a --parents arch/arm64/kernel/ftrace-mod.[So] "${LNXHDRDIR}/"
341 fi
342fi
343
81fa42ce
MJ
344# Copy modules related stuff, if available
345if [ -s Module.symvers ]; then
346 cp Module.symvers "${LNXHDRDIR}"
347fi
348
349if [ -s System.map ]; then
350 cp System.map "${LNXHDRDIR}"
351fi
352
353if [ -s Module.markers ]; then
354 cp Module.markers "${LNXHDRDIR}"
355fi
356
357# Copy config file
358cp .config "${LNXHDRDIR}"
359
360# Make sure the Makefile and version.h have a matching timestamp so that
361# external modules can be built
362if [ -s "${LNXHDRDIR}/include/generated/uapi/linux/version.h" ]; then
363 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/generated/uapi/linux/version.h"
364elif [ -s "${LNXHDRDIR}/include/linux/version.h" ]; then
365 touch -r "${LNXHDRDIR}/Makefile" "${LNXHDRDIR}/include/linux/version.h"
366else
367 echo "Missing version.h"
368 exit 1
369fi
370touch -r "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/generated/autoconf.h"
371
372# Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
373cp "${LNXHDRDIR}/.config" "${LNXHDRDIR}/include/config/auto.conf"
374
375
376
377
378## PREPARE FULL LINUX SOURCE TREE
379
380# Enter linux source dir
381cd "${LNXSRCDIR}"
382
383# Make sure linux source dir is clean
384git clean -xdf
385
386prepare_lnx_sources "${LNXBUILDDIR}"
387
388
389## BUILD modules
390
391# Build modules against full kernel sources
392build_modules "${LNXBUILDDIR}" "${LTTBUILDKSRCDIR}"
393
394# Build modules against kernel headers
395build_modules "${LNXHDRDIR}" "${LTTBUILDKHDRDIR}"
396
397# Make sure modules were built
398tree "${LTTBUILDKSRCDIR}"
399if [ "x$(find "${LTTBUILDKSRCDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
400 echo "No modules built!"
401 exit 1
402fi
403
404tree "${LTTBUILDKHDRDIR}"
405if [ "x$(find "${LTTBUILDKHDRDIR}" -name '*.ko*' -printf yes -quit)" != "xyes" ]; then
406 echo "No modules built!"
407 exit 1
408fi
409
410# EOF
This page took 0.039567 seconds and 4 git commands to generate.