Skip to content

Commit 9268a6f

Browse files
committedMay 1, 2024
cc: add CLang support with INPUT_CLANG=1
It will compile the kernel and dependences with CLang. Build and CCache dir will be separated. run-tests-clang.sh and run-tests-dev-clang.sh set the env var. Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
1 parent 250be7e commit 9268a6f

5 files changed

+32
-2
lines changed
 

‎README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ If you didn't change the kernel code, it can be useful to skip the compilation
8989
part. You can then set `INPUT_BUILD_SKIP=1` to save a few seconds to start the
9090
VM.
9191

92+
#### Use CLang instead of GCC
93+
94+
Simply set `INPUT_CLANG=1` env var with all the commands you use.
95+
9296
#### Not blocking with questions
9397

9498
You can set `INPUT_NO_BLOCK=1` env var not to block if these files are present.
@@ -227,5 +231,5 @@ case, it will be required to clean the build dir in `.virtme/build`, e.g.
227231
```bash
228232
docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --rm -it \
229233
mptcp/mptcp-upstream-virtme-docker:latest \
230-
cmd rm -r .virtme/build/tools
234+
cmd rm -r .virtme/build*/tools
231235
```

‎entrypoint.sh

+14-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ set_trace_off() {
3535
fi
3636
}
3737

38+
with_clang() {
39+
[ "${INPUT_CLANG}" = "1" ]
40+
}
41+
3842
set_trace_on
3943

4044
# The behaviour can be changed with 'input' env var
@@ -83,6 +87,7 @@ BASH_PROFILE="/root/.bash_profile"
8387

8488
VIRTME_WORKDIR="${KERNEL_SRC}/.virtme"
8589
VIRTME_BUILD_DIR="${VIRTME_WORKDIR}/build"
90+
with_clang && VIRTME_BUILD_DIR+="-clang"
8691
VIRTME_SCRIPTS_DIR="${VIRTME_WORKDIR}/scripts"
8792
VIRTME_PERF_DIR="${VIRTME_BUILD_DIR}/tools/perf"
8893
VIRTME_TOOLS_SBIN_DIR="${VIRTME_BUILD_DIR}/tools/sbin"
@@ -102,6 +107,7 @@ BPFTESTS_CONFIG="${BPFTESTS_DIR}/config"
102107

103108
export CCACHE_MAXSIZE="${INPUT_CCACHE_MAXSIZE}"
104109
export CCACHE_DIR="${VIRTME_WORKDIR}/ccache"
110+
with_clang && CCACHE_DIR+="-clang"
105111

106112
export KBUILD_OUTPUT="${VIRTME_BUILD_DIR}"
107113
export KCONFIG_CONFIG="${VIRTME_KCONFIG}"
@@ -300,6 +306,7 @@ check_source_exec_all() {
300306
}
301307

302308
read -ra MAKE_ARGS <<< "${INPUT_MAKE_ARGS}"
309+
with_clang && MAKE_ARGS+=(LLVM=1 LLVM_IAS=1 CC=clang ARCH="${VIRTME_ARCH}")
303310
MAKE_ARGS_O=("${MAKE_ARGS[@]}" O="${VIRTME_BUILD_DIR}")
304311

305312
_make_j() {
@@ -355,7 +362,13 @@ gen_kconfig() { local mode kconfig=() vck rc=0
355362
kconfig+=(-e PANIC_ON_OOPS)
356363

357364
# Debug info for developers
358-
kconfig+=(-e DEBUG_INFO -e DEBUG_INFO_DWARF4 -e GDB_SCRIPTS)
365+
kconfig+=(-e DEBUG_INFO -e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT -e GDB_SCRIPTS)
366+
if with_clang; then
367+
kconfig+=(-e DEBUG_INFO_DWARF_TOOLCHAIN_DEFAULT)
368+
else
369+
# decode_stacktrace.sh script reports '??:?' with GCC and DWARF5
370+
kconfig+=(-e DEBUG_INFO_DWARF4)
371+
fi
359372

360373
# Compressed (old/new option)
361374
kconfig+=(-e DEBUG_INFO_COMPRESSED -e DEBUG_INFO_COMPRESSED_ZLIB)

‎run-tests-clang.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -e
2+
# SPDX-License-Identifier: GPL-2.0
3+
DIR="$(dirname "$(realpath -P "${0}")")"
4+
export INPUT_CLANG=1
5+
6+
bash "-${-}" "${DIR}/run-tests.sh" "${@}"

‎run-tests-dev-clang.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash -ex
2+
# SPDX-License-Identifier: GPL-2.0
3+
DIR="$(dirname "$(realpath -P "${0}")")"
4+
export INPUT_CLANG=1
5+
6+
bash "-${-}" "${DIR}/run-tests-dev.sh" "${@}"

‎run.sh

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ docker run \
1616
${VIRTME_PACKETDRILL_PATH:+-v "${VIRTME_PACKETDRILL_PATH}:/opt/packetdrill:rw"} \
1717
-v "${HOME_DIR}:/root" \
1818
-w "${PWD}" \
19+
-e "INPUT_CLANG" \
1920
-e "INPUT_TRACE" \
2021
-e "INPUT_NO_BLOCK" \
2122
-e "INPUT_RUN_LOOP_CONTINUE" \

0 commit comments

Comments
 (0)