Skip to content

Commit 76426e2

Browse files
committed
kbuild: add dummy toolchains to enable all cc-option etc. in Kconfig
Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG options your compiler does not support. This works well if you configure and build the kernel on the same host machine. It is inconvenient if you prepare the .config that is carried to a different build environment (typically this happens when you package the kernel for distros) because using a different compiler potentially produces different CONFIG options than the real build environment. So, you probably want to make as many options visible as possible. In other words, you need to create a super-set of CONFIG options that cover any build environment. If some of the CONFIG options turned out to be unsupported on the build machine, they are automatically disabled by the nature of Kconfig. However, it is not feasible to get a full-featured compiler for every arch. This issue was discussed here: https://lkml.org/lkml/2019/12/9/620 Other than distros, savedefconfig is also a problem. Some arch sub-systems periodically resync defconfig files. If you use a less-capable compiler for savedefconfig, options that do not meet 'depends on $(cc-option,...)' will be forcibly disabled. So, 'make defconfig && make savedefconfig' may silently change the behavior. This commit adds a set of dummy toolchains that pretend to support any feature. Most of compiler features are tested by cc-option, which simply checks the exit code of $(CC). The dummy tools are shell scripts that always exit with 0. So, $(cc-option, ...) is evaluated as 'y'. There are more complicated checks such as: scripts/gcc-x86_{32,64}-has-stack-protector.sh scripts/gcc-plugin.sh scripts/tools-support-relr.sh scripts/dummy-tools/gcc passes all checks. From the top directory of the source tree, you can do: $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Philipp Rudo <[email protected]> Tested-by: Jeremy Cline <[email protected]>
1 parent 7273ad2 commit 76426e2

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed

scripts/dummy-tools/gcc

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
#
4+
# Staring v4.18, Kconfig evaluates compiler capabilities, and hides CONFIG
5+
# options your compiler does not support. This works well if you configure and
6+
# build the kernel on the same host machine.
7+
#
8+
# It is inconvenient if you prepare the .config that is carried to a different
9+
# build environment (typically this happens when you package the kernel for
10+
# distros) because using a different compiler potentially produces different
11+
# CONFIG options than the real build environment. So, you probably want to make
12+
# as many options visible as possible. In other words, you need to create a
13+
# super-set of CONFIG options that cover any build environment. If some of the
14+
# CONFIG options turned out to be unsupported on the build machine, they are
15+
# automatically disabled by the nature of Kconfig.
16+
#
17+
# However, it is not feasible to get a full-featured compiler for every arch.
18+
# Hence these dummy toolchains to make all compiler tests pass.
19+
#
20+
# Usage:
21+
#
22+
# From the top directory of the source tree, run
23+
#
24+
# $ make CROSS_COMPILE=scripts/dummy-tools/ oldconfig
25+
#
26+
# Most of compiler features are tested by cc-option, which simply checks the
27+
# exit code of $(CC). This script does nothing and just exits with 0 in most
28+
# cases. So, $(cc-option, ...) is evaluated as 'y'.
29+
#
30+
# This scripts caters to more checks; handle --version and pre-process __GNUC__
31+
# etc. to pretend to be GCC, and also do right things to satisfy some scripts.
32+
33+
# Check if the first parameter appears in the rest. Succeeds if found.
34+
# This helper is useful if a particular option was passed to this script.
35+
# Typically used like this:
36+
# arg_contain <word-you-are-searching-for> "$@"
37+
arg_contain ()
38+
{
39+
search="$1"
40+
shift
41+
42+
while [ $# -gt 0 ]
43+
do
44+
if [ "$search" = "$1" ]; then
45+
return 0
46+
fi
47+
shift
48+
done
49+
50+
return 1
51+
}
52+
53+
# To set CONFIG_CC_IS_GCC=y
54+
if arg_contain --version "$@"; then
55+
echo "gcc (scripts/dummy-tools/gcc)"
56+
exit 0
57+
fi
58+
59+
if arg_contain -E "$@"; then
60+
# For scripts/gcc-version.sh; This emulates GCC 20.0.0
61+
if arg_contain - "$@"; then
62+
sed 's/^__GNUC__$/20/; s/^__GNUC_MINOR__$/0/; s/^__GNUC_PATCHLEVEL__$/0/'
63+
exit 0
64+
else
65+
echo "no input files" >&2
66+
exit 1
67+
fi
68+
fi
69+
70+
if arg_contain -S "$@"; then
71+
# For scripts/gcc-x86-*-has-stack-protector.sh
72+
if arg_contain -fstack-protector "$@"; then
73+
echo "%gs"
74+
exit 0
75+
fi
76+
fi
77+
78+
# For scripts/gcc-plugin.sh
79+
if arg_contain -print-file-name=plugin "$@"; then
80+
plugin_dir=$(mktemp -d)
81+
82+
sed -n 's/.*#include "\(.*\)"/\1/p' $(dirname $0)/../gcc-plugins/gcc-common.h |
83+
while read header
84+
do
85+
mkdir -p $plugin_dir/include/$(dirname $header)
86+
touch $plugin_dir/include/$header
87+
done
88+
89+
echo $plugin_dir
90+
exit 0
91+
fi

scripts/dummy-tools/ld

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# SPDX-License-Identifier: GPL-2.0-only
3+
4+
# Dummy script that always succeeds.
5+
6+
# Check if the first parameter appears in the rest. Succeeds if found.
7+
# This helper is useful if a particular option was passed to this script.
8+
# Typically used like this:
9+
# arg_contain <word-you-are-searching-for> "$@"
10+
arg_contain ()
11+
{
12+
search="$1"
13+
shift
14+
15+
while [ $# -gt 0 ]
16+
do
17+
if [ "$search" = "$1" ]; then
18+
return 0
19+
fi
20+
shift
21+
done
22+
23+
return 1
24+
}
25+
26+
if arg_contain --version "$@" || arg_contain -v "$@"; then
27+
progname=$(basename $0)
28+
echo "GNU $progname (scripts/dummy-tools/$progname) 2.50"
29+
exit 0
30+
fi

scripts/dummy-tools/nm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ld

scripts/dummy-tools/objcopy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ld

0 commit comments

Comments
 (0)