From bab172c956cfc07ac690ab9d08ce3867c6faddfa Mon Sep 17 00:00:00 2001 From: liyunfei Date: Thu, 24 Aug 2023 16:10:05 +0800 Subject: [PATCH] add clang toolchain support --- 0002-cpupower-clang-compile-support.patch | 49 +++++++++++ ...gy_perf_policy-clang-compile-support.patch | 24 +++++ 0004-turbostat-clang-compile-support.patch | 24 +++++ kernel.spec | 88 +++++++++++++------ 4 files changed, 157 insertions(+), 28 deletions(-) create mode 100644 0002-cpupower-clang-compile-support.patch create mode 100644 0003-x86_energy_perf_policy-clang-compile-support.patch create mode 100644 0004-turbostat-clang-compile-support.patch diff --git a/0002-cpupower-clang-compile-support.patch b/0002-cpupower-clang-compile-support.patch new file mode 100644 index 0000000..1363e9b --- /dev/null +++ b/0002-cpupower-clang-compile-support.patch @@ -0,0 +1,49 @@ +From 6289f9462859513b4fa3137faf0332b84e46558a Mon Sep 17 00:00:00 2001 +From: liyunfei +Date: Mon, 28 Aug 2023 10:55:20 +0800 +Subject: [PATCH] cpupower clang compile support + +Modified Makefile with tools/scripts/Makefile.include for clang compile and clang cross compile support. +--- + tools/power/cpupower/Makefile | 17 ++--------------- + 1 file changed, 2 insertions(+), 15 deletions(-) + +diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile +index 59bfa05..1e606a4 100644 +--- a/tools/power/cpupower/Makefile ++++ b/tools/power/cpupower/Makefile +@@ -8,16 +8,7 @@ + # Copyright (C) 2003,2004 Greg Kroah-Hartman + # + OUTPUT=./ +-ifeq ("$(origin O)", "command line") +- OUTPUT := $(O)/ +-endif +- +-ifneq ($(OUTPUT),) +-# check that the output directory actually exists +-OUTDIR := $(shell cd $(OUTPUT) && pwd) +-$(if $(OUTDIR),, $(error output directory "$(OUTPUT)" does not exist)) +-endif +- ++include ../../scripts/Makefile.include + + # --- CONFIGURATION BEGIN --- + +@@ -86,12 +77,8 @@ INSTALL_SCRIPT = ${INSTALL} -m 644 + # to something more interesting, like "arm-linux-". If you want + # to compile vs uClibc, that can be done here as well. + CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc- +-CC = $(CROSS)gcc +-LD = $(CROSS)gcc +-AR = $(CROSS)ar +-STRIP = $(CROSS)strip ++CROSS_COMPILE ?= $(CROSS) + RANLIB = $(CROSS)ranlib +-HOSTCC = gcc + MKDIR = mkdir + + # 64bit library detection +-- +2.28.0.windows.1 + diff --git a/0003-x86_energy_perf_policy-clang-compile-support.patch b/0003-x86_energy_perf_policy-clang-compile-support.patch new file mode 100644 index 0000000..2384105 --- /dev/null +++ b/0003-x86_energy_perf_policy-clang-compile-support.patch @@ -0,0 +1,24 @@ +From 55391ef2c74c32675038a7eb9c81769eba4622f6 Mon Sep 17 00:00:00 2001 +From: liyunfei +Date: Mon, 28 Aug 2023 11:06:32 +0800 +Subject: [PATCH] x86_energy_perf_policy clang compile support + +Modified Makefile with tools/scripts/Makefile.include for clang compile and clang cross compile support. +--- + tools/power/x86/x86_energy_perf_policy/Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tools/power/x86/x86_energy_perf_policy/Makefile b/tools/power/x86/x86_energy_perf_policy/Makefile +index 666b325..c61227b 100644 +--- a/tools/power/x86/x86_energy_perf_policy/Makefile ++++ b/tools/power/x86/x86_energy_perf_policy/Makefile +@@ -1,5 +1,5 @@ + # SPDX-License-Identifier: GPL-2.0 +-CC = $(CROSS_COMPILE)gcc ++include ../../../scripts/Makefile.include + BUILD_OUTPUT := $(CURDIR) + PREFIX := /usr + DESTDIR := +-- +2.28.0.windows.1 + diff --git a/0004-turbostat-clang-compile-support.patch b/0004-turbostat-clang-compile-support.patch new file mode 100644 index 0000000..d21c9ef --- /dev/null +++ b/0004-turbostat-clang-compile-support.patch @@ -0,0 +1,24 @@ +From bddde6f3d75afb734862150e2fb80af9cf3e00f9 Mon Sep 17 00:00:00 2001 +From: liyunfei +Date: Mon, 28 Aug 2023 11:09:03 +0800 +Subject: [PATCH] turbostat clang compile support + +Modified Makefile with tools/scripts/Makefile.include for clang compile and clang cross compile support. +--- + tools/power/x86/turbostat/Makefile | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tools/power/x86/turbostat/Makefile b/tools/power/x86/turbostat/Makefile +index 92e139b..f4de368 100644 +--- a/tools/power/x86/turbostat/Makefile ++++ b/tools/power/x86/turbostat/Makefile +@@ -1,5 +1,5 @@ + # SPDX-License-Identifier: GPL-2.0 +-CC = $(CROSS_COMPILE)gcc ++include ../../../scripts/Makefile.include + BUILD_OUTPUT := $(CURDIR) + PREFIX ?= /usr + DESTDIR ?= +-- +2.28.0.windows.1 + diff --git a/kernel.spec b/kernel.spec index b711de3..8d173ac 100644 --- a/kernel.spec +++ b/kernel.spec @@ -1,6 +1,13 @@ %define with_signmodules 1 %define with_kabichk 0 +# Default without toolchain_clang +%bcond_with toolchain_clang + +%if %{with toolchain_clang} +%global toolchain clang +%endif + %define modsign_cmd %{SOURCE10} %global Arch $(echo %{_host_cpu} | sed -e s/i.86/x86/ -e s/x86_64/x86/ -e s/aarch64.*/arm64/ -e s/riscv.*/riscv/) @@ -12,7 +19,7 @@ %global upstream_sublevel 0 %global devel_release 1 %global maintenance_release .0.2 -%global pkg_release .7 +%global pkg_release .8 %define with_debuginfo 1 # Do not recompute the build-id of vmlinux in find-debuginfo.sh @@ -72,6 +79,9 @@ Source9998: patches.tar.bz2 %endif Patch0001: 0001-kconfig-Add-script-to-update-openeuler_defconfig.patch +Patch0002: 0002-cpupower-clang-compile-support.patch +Patch0003: 0003-x86_energy_perf_policy-clang-compile-support.patch +Patch0004: 0004-turbostat-clang-compile-support.patch #BuildRequires: BuildRequires: module-init-tools, patch >= 2.5.4, bash >= 2.03, tar @@ -298,6 +308,11 @@ Applypatches series.conf %{_builddir}/kernel-%{version}/linux-%{KernelVer} %endif %patch0001 -p1 +%if "%toolchain" == "clang" +%patch0002 -p1 +%patch0003 -p1 +%patch0004 -p1 +%endif find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null find . -name .gitignore -exec rm -f {} \; >/dev/null @@ -330,12 +345,26 @@ sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_VA_BITS=.*/CON sed -i arch/arm64/configs/openeuler_defconfig -e 's/^CONFIG_ARM64_VA_BITS_.*/CONFIG_ARM64_VA_BITS_52=y/' %endif -make ARCH=%{Arch} openeuler_defconfig +%if "%toolchain" == "clang" + +%ifarch s390x ppc64le +%global llvm_ias 0 +%else +%global llvm_ias 1 +%endif + +%global clang_make_opts HOSTCC=clang CC=clang LLVM_IAS=%{llvm_ias} + +%endif + +%global make %{__make} %{?clang_make_opts} HOSTCFLAGS="%{?build_cflags}" HOSTLDFLAGS="%{?build_ldflags}" + +%{make} ARCH=%{Arch} openeuler_defconfig TargetImage=$(basename $(make -s image_name)) -make ARCH=%{Arch} $TargetImage %{?_smp_mflags} -make ARCH=%{Arch} modules %{?_smp_mflags} +%{make} ARCH=%{Arch} $TargetImage %{?_smp_mflags} +%{make} ARCH=%{Arch} modules %{?_smp_mflags} %if 0%{?with_kabichk} chmod 0755 %{SOURCE18} @@ -348,14 +377,14 @@ make ARCH=%{Arch} modules %{?_smp_mflags} # aarch64 make dtbs %ifarch aarch64 riscv64 - make ARCH=%{Arch} dtbs + %{make} ARCH=%{Arch} dtbs %endif ## make tools %if %{with_perf} # perf %global perf_make \ - make EXTRA_CFLAGS="-Wl,-z,now -g -Wall -fstack-protector-strong -fPIC" EXTRA_PERFLIBS="-fpie -pie" %{?_smp_mflags} -s V=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_LIBNUMA=1 NO_STRLCPY=1 prefix=%{_prefix} + make %{?clang_make_opts} EXTRA_LDFLAGS="%[ "%{toolchain}" == "clang" ? "-z now" : "" ]" EXTRA_CFLAGS="%[ "%{toolchain}" == "clang" ? "" : "-Wl,-z,now" ] -g -Wall -fstack-protector-strong -fPIC" EXTRA_PERFLIBS="-fpie -pie" %{?_smp_mflags} -s V=1 WERROR=0 NO_LIBUNWIND=1 HAVE_CPLUS_DEMANGLE=1 NO_GTK2=1 NO_LIBNUMA=1 NO_STRLCPY=1 prefix=%{_prefix} %if 0%{?with_python2} %global perf_python2 -C tools/perf PYTHON=%{__python2} %global perf_python3 -C tools/python3-perf PYTHON=%{__python3} @@ -374,51 +403,51 @@ chmod +x tools/python3-perf/check-headers.sh %{perf_make} %{perf_python3} all pushd tools/perf/Documentation/ -make %{?_smp_mflags} man +%{make} %{?_smp_mflags} man popd %endif # bpftool pushd tools/bpf/bpftool -make +%{make} popd # cpupower chmod +x tools/power/cpupower/utils/version-gen.sh -make %{?_smp_mflags} -C tools/power/cpupower CPUFREQ_BENCH=false +%{make} %{?_smp_mflags} -C tools/power/cpupower CPUFREQ_BENCH=false %ifarch %{ix86} pushd tools/power/cpupower/debug/i386 - make %{?_smp_mflags} centrino-decode powernow-k8-decode + %{make} %{?_smp_mflags} centrino-decode powernow-k8-decode popd %endif %ifarch x86_64 pushd tools/power/cpupower/debug/x86_64 - make %{?_smp_mflags} centrino-decode powernow-k8-decode + %{make} %{?_smp_mflags} centrino-decode powernow-k8-decode popd %endif %ifarch %{ix86} x86_64 pushd tools/power/x86/x86_energy_perf_policy/ - make + %{make} popd pushd tools/power/x86/turbostat - make + %{make} popd %endif # thermal pushd tools/thermal/tmon/ -make +%{make} popd # iio pushd tools/iio/ -make +%{make} popd # gpio pushd tools/gpio/ -make +%{make} popd # kvm pushd tools/kvm/kvm_stat/ -make %{?_smp_mflags} man +%{make} %{?_smp_mflags} man popd %install @@ -460,7 +489,7 @@ install -m 755 %{SOURCE200} $RPM_BUILD_ROOT%{_sbindir}/mkgrub-menu-%{version}-%{ %endif # deal with module, if not kdump -make ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=%{KernelVer} mod-fw= +%{make} ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=%{KernelVer} mod-fw= ######## to collect ko to module.filelist about netwoking. block. drm. modesetting ############### pushd $RPM_BUILD_ROOT/lib/modules/%{KernelVer} find -type f -name "*.ko" >modnames @@ -522,7 +551,7 @@ popd %{nil} # deal with header -make ARCH=%{Arch} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install +%{make} ARCH=%{Arch} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr KBUILD_SRC= headers_install find $RPM_BUILD_ROOT/usr/include -name "\.*" -exec rm -rf {} \; # dtbs install @@ -533,7 +562,7 @@ find $RPM_BUILD_ROOT/usr/include -name "\.*" -exec rm -rf {} \; %endif # deal with vdso -make -s ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT vdso_install KERNELRELEASE=%{KernelVer} +%{make} -s ARCH=%{Arch} INSTALL_MOD_PATH=$RPM_BUILD_ROOT vdso_install KERNELRELEASE=%{KernelVer} if [ ! -s ldconfig-kernel.conf ]; then echo "# Placeholder file, no vDSO hwcap entries used in this kernel." >ldconfig-kernel.conf fi @@ -646,7 +675,7 @@ install -pm0644 tools/perf/Documentation/*.1 %{buildroot}/%{_mandir}/man1/ # bpftool pushd tools/bpf/bpftool -make DESTDIR=%{buildroot} prefix=%{_prefix} bash_compdir=%{_sysconfdir}/bash_completion.d/ mandir=%{_mandir} install doc-install +%{make} DESTDIR=%{buildroot} prefix=%{_prefix} bash_compdir=%{_sysconfdir}/bash_completion.d/ mandir=%{_mandir} install doc-install popd # resolve_btfids @@ -654,7 +683,7 @@ mkdir -p %{buildroot}/usr/src/kernels/%{KernelVer}/tools/bpf/resolve_btfids cp tools/bpf/resolve_btfids/resolve_btfids %{buildroot}/usr/src/kernels/%{KernelVer}/tools/bpf/resolve_btfids # cpupower -make -C tools/power/cpupower DESTDIR=%{buildroot} libdir=%{_libdir} mandir=%{_mandir} CPUFREQ_BENCH=false install +%{make} -C tools/power/cpupower DESTDIR=%{buildroot} libdir=%{_libdir} mandir=%{_mandir} CPUFREQ_BENCH=false install rm -f %{buildroot}%{_libdir}/*.{a,la} %find_lang cpupower mv cpupower.lang ../ @@ -677,27 +706,27 @@ install -m644 %{SOURCE2001} %{buildroot}%{_sysconfdir}/sysconfig/cpupower %ifarch %{ix86} x86_64 mkdir -p %{buildroot}%{_mandir}/man8 pushd tools/power/x86/x86_energy_perf_policy - make DESTDIR=%{buildroot} install + %{make} DESTDIR=%{buildroot} install popd pushd tools/power/x86/turbostat - make DESTDIR=%{buildroot} install + %{make} DESTDIR=%{buildroot} install popd %endif # thermal pushd tools/thermal/tmon -make INSTALL_ROOT=%{buildroot} install +%{make} INSTALL_ROOT=%{buildroot} install popd # iio pushd tools/iio -make DESTDIR=%{buildroot} install +%{make} DESTDIR=%{buildroot} install popd # gpio pushd tools/gpio -make DESTDIR=%{buildroot} install +%{make} DESTDIR=%{buildroot} install popd # kvm pushd tools/kvm/kvm_stat -make INSTALL_ROOT=%{buildroot} install-tools +%{make} INSTALL_ROOT=%{buildroot} install-tools popd %define __spec_install_post\ @@ -879,6 +908,9 @@ fi %endif %changelog +* Fri Aug 25 2023 liyunfei - 6.4.0-1.0.2.8 +- add clang toolchain support + * Fri Aug 25 2023 bitcoffee - 6.4.0-1.0.2.7 - add resolver_btfids tool to kernel-devel for compiling ko