Add clang compile support
Backport commit 6ddb09145930b03c88e63f5930e718a33501024d Support CC=clang and LD=ld.lld & add clang llvm lld requires
This commit is contained in:
parent
86c35af2fd
commit
3d552b93e0
59
Support-CC-clang-and-LD-ld.lld.patch
Normal file
59
Support-CC-clang-and-LD-ld.lld.patch
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
From cfe6363124a0d0495727c6f4e8a1809b295a8cbf Mon Sep 17 00:00:00 2001
|
||||||
|
From: liyunfei <liyunfei33@huawei.com>
|
||||||
|
Date: Wed, 13 Sep 2023 10:05:33 +0800
|
||||||
|
Subject: [PATCH] Support CC=clang and LD=ld.lld When building the Linux
|
||||||
|
kernel, one may use `make LLVM=1` to set multiple flags, akin to `make
|
||||||
|
CC=clang LD=ld.lld NM=llvm-nm ...` (see the link below for kernel docs
|
||||||
|
explaining this further in detail).
|
||||||
|
|
||||||
|
When building kernel modules, to ensure we're using the same toolchain
|
||||||
|
as the underlying core kernel image, Kbuild will error if it's reinvoked
|
||||||
|
with a toolchain that differs. This causes DKMS to fail, since it's not
|
||||||
|
re-specifying the same compiler (or linker, etc).
|
||||||
|
|
||||||
|
Check the .comment section of the vmlinux file in the Linux kernel
|
||||||
|
source dir, and set CC= and LD= flags for make based on that.
|
||||||
|
|
||||||
|
If vmlinux does not exist, grep .config for CONFIG_CC_IS_CLANG=y and
|
||||||
|
CONFIG_LD_IS_LLD=y.
|
||||||
|
|
||||||
|
Fixes: #124
|
||||||
|
Fixes: ClangBuiltLinux/linux#1104
|
||||||
|
Link: https://docs.kernel.org/kbuild/llvm.html
|
||||||
|
Suggested-by: Colin Ian King <colin.king@canonical.com>
|
||||||
|
Signed-off-by: Nick Desaulniers <nick.desaulniers@gmail.com>
|
||||||
|
---
|
||||||
|
dkms | 17 +++++++++++++++++
|
||||||
|
1 file changed, 17 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/dkms b/dkms
|
||||||
|
index c4b9a26..983aefc 100755
|
||||||
|
--- a/dkms
|
||||||
|
+++ b/dkms
|
||||||
|
@@ -699,6 +699,23 @@ read_conf()
|
||||||
|
[[ ${MODULES_CONF[$index]} ]] && modules_conf_array[$index]="${MODULES_CONF[$index]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
+ # Check if clang was used to compile or lld was used to link the kernel.
|
||||||
|
+ if [[ -e $kernel_source_dir/vmlinux ]]; then
|
||||||
|
+ if readelf -p .comment $kernel_source_dir/vmlinux | grep -q clang; then
|
||||||
|
+ make_command="${make_command} CC=clang"
|
||||||
|
+ fi
|
||||||
|
+ if readelf -p .comment $kernel_source_dir/vmlinux | grep -q LLD; then
|
||||||
|
+ make_command="${make_command} LD=ld.lld"
|
||||||
|
+ fi
|
||||||
|
+ elif [[ -e $kernel_source_dir/.config ]]; then
|
||||||
|
+ if grep -q CONFIG_CC_IS_CLANG=y $kernel_source_dir/.config; then
|
||||||
|
+ make_command="${make_command} CC=clang"
|
||||||
|
+ fi
|
||||||
|
+ if grep -q CONFIG_LD_IS_LLD=y $kernel_source_dir/.config; then
|
||||||
|
+ make_command="${make_command} LD=ld.lld"
|
||||||
|
+ fi
|
||||||
|
+ fi
|
||||||
|
+
|
||||||
|
# Set patch_array (including kernel specific patches)
|
||||||
|
count=0
|
||||||
|
for ((index=0; index < ${#PATCH[@]}; index++)); do
|
||||||
|
--
|
||||||
|
2.27.0
|
||||||
|
|
||||||
@ -1,19 +1,21 @@
|
|||||||
Summary: Dynamic Kernel Module Support Framework
|
Summary: Dynamic Kernel Module Support Framework
|
||||||
Name: dkms
|
Name: dkms
|
||||||
Version: 2.6.1
|
Version: 2.6.1
|
||||||
Release: 7
|
Release: 8
|
||||||
License: GPLv2+
|
License: GPLv2+
|
||||||
BuildArch: noarch
|
BuildArch: noarch
|
||||||
URL: https://github.com/dell/dkms
|
URL: https://github.com/dell/dkms
|
||||||
Source0: https://github.com/dell/dkms/archive/v%{version}.tar.gz#/dkms-%{version}.tar.gz
|
Source0: https://github.com/dell/dkms/archive/v%{version}.tar.gz#/dkms-%{version}.tar.gz
|
||||||
# because Mandriva calls this package dkms-minimal
|
# because Mandriva calls this package dkms-minimal
|
||||||
Patch0: change-deprecated-egrep-for-grep-E.patch
|
Patch0: change-deprecated-egrep-for-grep-E.patch
|
||||||
|
Patch1: Support-CC-clang-and-LD-ld.lld.patch
|
||||||
Provides: dkms-minimal = %{version}
|
Provides: dkms-minimal = %{version}
|
||||||
Requires: coreutils
|
Requires: coreutils
|
||||||
Requires: cpio
|
Requires: cpio
|
||||||
Requires: findutils
|
Requires: findutils
|
||||||
Requires: gawk
|
Requires: gawk
|
||||||
Requires: gcc
|
Requires: gcc
|
||||||
|
Requires: clang llvm lld
|
||||||
Requires: grep
|
Requires: grep
|
||||||
Requires: gzip
|
Requires: gzip
|
||||||
Requires: kernel-devel
|
Requires: kernel-devel
|
||||||
@ -128,6 +130,9 @@ fi
|
|||||||
%{_sysconfdir}/bash_completion.d/%{name}
|
%{_sysconfdir}/bash_completion.d/%{name}
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Tue Sep 19 2023 liyunfei <liyunfei@huawei.com> - 2.6.1-8
|
||||||
|
- Add clang compile support
|
||||||
|
|
||||||
* Mon Mar 27 2023 wangkai <wangkai385@h-partners.com> - 2.6.1-7
|
* Mon Mar 27 2023 wangkai <wangkai385@h-partners.com> - 2.6.1-7
|
||||||
- Change deprecated egrep for grep -E
|
- Change deprecated egrep for grep -E
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user