From: Don Zickus <dzickus(a)redhat.com>
Add clang config framework
Compiling for clang is getting trickier to do because the configs are
different than gcc in some cases. Mimic the kgcov framework (which uses
priority files) to setup clang to be easier to update their configs.
This leads to strange cases where clang debug configs need different
settings than clang non-debug configs. The priority.snip can handle the
variety of partial snippets for variants and arches well, the
kernel.spec needed to be updated to apply it reasonably.
I created a generic partial snippet loop that focuses on arch and
non-debug vs debug. This required adding debug options to
priority.snip. Once implemented it is a matter of collecting the
snippets and applying them based on arch and debug. This should provide
a variety of flexibility for teams like clang and make it easier to roll
in config changes based on which compiler is used.
Signed-off-by: Don Zickus <dzickus(a)redhat.com>
diff --git a/redhat/configs/common/clang/debug/CONFIG_KASAN_STACK
b/redhat/configs/common/clang/debug/CONFIG_KASAN_STACK
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang/debug/CONFIG_KASAN_STACK
@@ -0,0 +1 @@
+CONFIG_KASAN_STACK=y
diff --git a/redhat/configs/common/clang/debug/CONFIG_KMSAN
b/redhat/configs/common/clang/debug/CONFIG_KMSAN
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang/debug/CONFIG_KMSAN
@@ -0,0 +1 @@
+# CONFIG_KMSAN is not set
diff --git a/redhat/configs/common/clang/generic/CONFIG_KASAN_STACK
b/redhat/configs/common/clang/generic/CONFIG_KASAN_STACK
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang/generic/CONFIG_KASAN_STACK
@@ -0,0 +1 @@
+# CONFIG_KASAN_STACK is not set
diff --git a/redhat/configs/common/clang/generic/CONFIG_KMSAN
b/redhat/configs/common/clang/generic/CONFIG_KMSAN
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang/generic/CONFIG_KMSAN
@@ -0,0 +1 @@
+# CONFIG_KMSAN is not set
diff --git a/redhat/configs/common/clang_lto/debug/README
b/redhat/configs/common/clang_lto/debug/README
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang_lto/debug/README
diff --git a/redhat/configs/common/clang_lto/generic/README
b/redhat/configs/common/clang_lto/generic/README
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang_lto/generic/README
diff --git a/redhat/configs/common/clang_lto/generic/arm/CONFIG_LTO_CLANG_THIN
b/redhat/configs/common/clang_lto/generic/arm/CONFIG_LTO_CLANG_THIN
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang_lto/generic/arm/CONFIG_LTO_CLANG_THIN
@@ -0,0 +1 @@
+CONFIG_LTO_CLANG_THIN=y
diff --git a/redhat/configs/common/clang_lto/generic/arm/CONFIG_LTO_NONE
b/redhat/configs/common/clang_lto/generic/arm/CONFIG_LTO_NONE
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang_lto/generic/arm/CONFIG_LTO_NONE
@@ -0,0 +1 @@
+# CONFIG_LTO_NONE is not set
diff --git a/redhat/configs/common/clang_lto/generic/x86/CONFIG_LTO_CLANG_THIN
b/redhat/configs/common/clang_lto/generic/x86/CONFIG_LTO_CLANG_THIN
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang_lto/generic/x86/CONFIG_LTO_CLANG_THIN
@@ -0,0 +1 @@
+CONFIG_LTO_CLANG_THIN=y
diff --git a/redhat/configs/common/clang_lto/generic/x86/CONFIG_LTO_NONE
b/redhat/configs/common/clang_lto/generic/x86/CONFIG_LTO_NONE
new file mode 100644
index blahblah..blahblah 100644
--- /dev/null
+++ b/redhat/configs/common/clang_lto/generic/x86/CONFIG_LTO_NONE
@@ -0,0 +1 @@
+# CONFIG_LTO_NONE is not set
diff --git a/redhat/configs/priority.snip b/redhat/configs/priority.snip
index blahblah..blahblah 100644
--- a/redhat/configs/priority.snip
+++ b/redhat/configs/priority.snip
@@ -10,3 +10,12 @@ EMPTY=
# gcov options
kgcov=kgcov
+kgcov-debug=kgcov
+
+# clang options
+clang=clang-generic
+clang-debug=clang-debug
+clang_lto-x86_64=clang-generic:clang_lto-generic:clang_lto-generic-x86
+clang_lto-x86_64-debug=clang-debug:clang_lto-debug
+clang_lto-aarch64=clang-generic:clang_lto-generic:clang_lto-generic-arm
+clang_lto-aarch64-debug=clang-debug:clang_lto-debug
diff --git a/redhat/kernel.spec.template b/redhat/kernel.spec.template
index blahblah..blahblah 100644
--- a/redhat/kernel.spec.template
+++ b/redhat/kernel.spec.template
@@ -908,7 +908,14 @@ Source65: filter-s390x.sh.fedora
Source66: filter-modules.sh.fedora
%endif
-Source75: partial-kgcov-snip.config
+Source70: partial-kgcov-snip.config
+Source71: partial-kgcov-debug-snip.config
+Source72: partial-clang-snip.config
+Source73: partial-clang-debug-snip.config
+Source74: partial-clang_lto-x86_64-snip.config
+Source75: partial-clang_lto-x86_64-debug-snip.config
+Source76: partial-clang_lto-aarch64-snip.config
+Source77: partial-clang_lto-aarch64-debug-snip.config
Source80: generate_all_configs.sh
Source81: process_configs.sh
@@ -1771,30 +1778,56 @@ cp $RPM_SOURCE_DIR/%{name}-*.config .
cp %{SOURCE80} .
# merge.py
cp %{SOURCE3000} .
-# kernel-local
+# kernel-local - rename and copy for partial snippet config process
cp %{SOURCE3001} .
+cp kernel-local partial-kernel-local-snip.config
+cp kernel-local partial-kernel-local-debug-snip.config
FLAVOR=%{primary_target} SPECPACKAGE_NAME=%{name} SPECVERSION=%{specversion}
SPECRPMVERSION=%{specrpmversion} ./generate_all_configs.sh %{debugbuildsenabled}
-# Merge in any user-provided local config option changes
-%ifnarch %nobuildarches
-for i in %{all_arch_configs}
-do
- mv $i $i.tmp
- ./merge.py %{SOURCE3001} $i.tmp > $i
+# Collect custom defined config options
+PARTIAL_CONFIGS="partial-kernel-local-snip.config
partial-kernel-local-debug-snip.config"
%if %{with_gcov}
- echo "Merging with gcov options"
- cat %{SOURCE75}
- mv $i $i.tmp
- ./merge.py %{SOURCE75} $i.tmp > $i
+PARTIAL_CONFIGS="$PARTIAL_CONFIGS %{SOURCE70} %{SOURCE71}"
%endif
- rm $i.tmp
-done
+%if %{with toolchain_clang}
+PARTIAL_CONFIGS="$PARTIAL_CONFIGS %{SOURCE72} %{SOURCE73}"
%endif
-
%if %{with clang_lto}
-for i in *aarch64*.config *x86_64*.config; do
- sed -i 's/# CONFIG_LTO_CLANG_THIN is not set/CONFIG_LTO_CLANG_THIN=y/' $i
- sed -i 's/CONFIG_LTO_NONE=y/# CONFIG_LTO_NONE is not set/' $i
+PARTIAL_CONFIGS="$PARTIAL_CONFIGS %{SOURCE74} %{SOURCE75} %{SOURCE76}
%{SOURCE77}"
+%endif
+
+GetArch()
+{
+ case "$1" in
+ *aarch64*) echo "aarch64" ;;
+ *ppc64le*) echo "ppc64le" ;;
+ *s390x*) echo "s390x" ;;
+ *x86_64*) echo "x86_64" ;;
+ # no arch, apply everywhere
+ *) echo "" ;;
+ esac
+}
+
+# Merge in any user-provided local config option changes
+%ifnarch %nobuildarches
+for i in %{all_arch_configs}
+do
+ kern_arch="$(GetArch $i)"
+ kern_debug="$(echo $i | grep -q debug && echo "debug" || echo
"")"
+
+ for j in $PARTIAL_CONFIGS
+ do
+ part_arch="$(GetArch $j)"
+ part_debug="$(echo $j | grep -q debug && echo "debug" || echo
"")"
+
+ # empty arch means apply to all arches
+ if [ "$part_arch" == "" -o "$part_arch" ==
"$kern_arch" ] && [ "$part_debug" == "$kern_debug"
]
+ then
+ mv $i $i.tmp
+ ./merge.py $j $i.tmp > $i
+ fi
+ done
+ rm -f $i.tmp
done
%endif
--
https://gitlab.com/cki-project/kernel-ark/-/merge_requests/2654