已开启
Support clang build (modify 2 meson.build) #619
AtomGit-Bot创建于 2024年9月19日
Support clang build (modify 2 meson.build) #619
已开启
AtomGit-Bot创建于 2024年9月19日
从refs/pull/619/head合入到master
共 2 个文件变更+88-2
@@ -0,0 +1,79 @@
1+From 6a7fdd684f17f6f2ec8fedd5bc5c1e354426df3f Mon Sep 17 00:00:00 2001
2+From: yanying <201250106@smail.nju.edu.cn>
3+Date: Sat, 28 Sep 2024 22:14:13 +0800
4+Subject: [PATCH] modify some meson.build to fix clang build -
5+ drivers/meson.build - default_cflags add '-pie' and '-Wtrampolines' only
6+ if the compiler has the arguments - move
7+ '-Wl,-z,relro,-z,now,-z,noexecstack' to default_ldflags which will pass to
8+ linker args
9+ 
10+- kernel/linux/igb_uio/meson.build
11+ - Add the CC parameter to the make command to specify using clang if kernel was built by clang
12+---
13+ drivers/meson.build | 14 ++++++++++++--
14+ kernel/linux/igb_uio/meson.build | 14 +++++++++++++-
15+ 2 files changed, 25 insertions(+), 3 deletions(-)
16+ 
17+diff --git a/drivers/meson.build b/drivers/meson.build
18+index 1891192..f795250 100644
19+--- a/drivers/meson.build
20++++ b/drivers/meson.build
21+@@ -57,8 +57,17 @@ enable_drivers += always_enable
22+ default_cflags = machine_args
23+ default_cflags += ['-DALLOW_EXPERIMENTAL_API']
24+ default_cflags += ['-DALLOW_INTERNAL_API']
25+-default_cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall']
26+-default_cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines']
27++default_cflags += ['-fPIE', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall']
28++
29++if cc.has_argument('-pie')
30++ default_cflags += '-pie'
31++endif
32++
33++if cc.has_argument('-Wtrampolines')
34++ default_cflags += '-Wtrampolines'
35++endif
36++
37++default_ldflags = ['-Wl,-z,relro,-z,now,-z,noexecstack']
38+
39+ if cc.has_argument('-Wno-format-truncation')
40+ default_cflags += '-Wno-format-truncation'
41+@@ -255,6 +264,7 @@ foreach subpath:subdirs
42+
43+ lk_deps = []
44+ lk_args = []
45++ lk_args += default_ldflags
46+ if not fs.is_file(version_map)
47+ version_map = '@0@/version.map'.format(meson.current_source_dir())
48+ lk_deps += [version_map]
49+diff --git a/kernel/linux/igb_uio/meson.build b/kernel/linux/igb_uio/meson.build
50+index ff8f97c..e8458e7 100644
51+--- a/kernel/linux/igb_uio/meson.build
52++++ b/kernel/linux/igb_uio/meson.build
53+@@ -14,10 +14,22 @@ igb_uio_sources = files(
54+ 'Kbuild',
55+ )
56+
57++cc_param = ''
58++kernel_compile_file = '/lib/modules/' + run_command('uname', '-r').stdout().strip() + '/build/include/generated/compile.h'
xiajingze
xiajingzexiajingze2024年10月11日

是不是可以在/usr/src/kernels/${uname -r}/.config中查看CONFIG_CC_VERSION_TEXT

likedislike
59++
60++if fs.exists(kernel_compile_file)
61++ kernel_compile_info = run_command('grep', '-oP', '(clang).*', kernel_compile_file)
62++ if kernel_compile_info.returncode() == 0
63++ if kernel_compile_info.stdout().strip().contains('clang')
64++ cc_param = 'CC=clang'
65++ endif
66++ endif
67++endif
68++
69+ custom_target('igb_uio',
70+ input: igb_uio_sources,
71+ output: 'igb_uio.ko',
72+- command: ['make', '-j4', '-C', kernel_build_dir,
73++ command: ['make', '-j4', '-C', kernel_build_dir, cc_param,
74+ 'M=' + meson.current_build_dir(),
75+ 'src=' + meson.current_source_dir(),
76+ 'modules'] + cross_args,
77+--
78+2.41.0.windows.1
79+ 
@@ -10,7 +10,7 @@
10 10 
11Name: dpdk11Name: dpdk
12Version: 23.1112Version: 23.11
13-Release: 2013+Release: 21
14URL: http://dpdk.org14URL: http://dpdk.org
15Source: https://fast.dpdk.org/rel/dpdk-%{version}.tar.xz15Source: https://fast.dpdk.org/rel/dpdk-%{version}.tar.xz
16 16 
@@ -71,6 +71,8 @@ Patch9037: 0043-remove-symbol-for-examples-and-app.patch
71Patch6044: 0044-net-hns3-support-more-VLAN-fields-matching.patch71Patch6044: 0044-net-hns3-support-more-VLAN-fields-matching.patch
72Patch6045: 0045-net-hns3-add-Rx-DMA-address-align-check.patch72Patch6045: 0045-net-hns3-add-Rx-DMA-address-align-check.patch
73 73 
74+Patch9046: 0046-modify-some-meson.build-to-fix-clang-build.patch
75+ 
74BuildRequires: meson76BuildRequires: meson
75BuildRequires: python3-pyelftools77BuildRequires: python3-pyelftools
76BuildRequires: diffutils78BuildRequires: diffutils
@@ -170,7 +172,7 @@ end
170%autosetup -n %{name}-%{version} -S git_am172%autosetup -n %{name}-%{version} -S git_am
171 173 
172%build174%build
173-CFLAGS="$(echo %{optflags} -fcommon)" \175+CFLAGS="$(echo %{optflags} -fcommon %[ "%{toolchain}" == "clang" ? "-fgcc-compatible" : "" ])" \
174%meson --includedir=include/dpdk \176%meson --includedir=include/dpdk \
175 -Ddrivers_install_subdir=dpdk-pmds \177 -Ddrivers_install_subdir=dpdk-pmds \
176 -Denable_docs=false \178 -Denable_docs=false \
@@ -260,6 +262,11 @@ strip -g $RPM_BUILD_ROOT/lib/modules/%{kern_devel_ver}/extra/dpdk/igb_uio.ko
260%endif262%endif
261 263 
262%changelog264%changelog
265+* Thu Sep 19 2024 yanying <201250106@smail.nju.edu.cn> - 23.11-21
266+ Support clang build
267+ - modify drivers/meson.build and kernel/linux/igb_uio/meson.build
268+ - add "-fgcc-compatible" when building with clang
269+ 
263* Tue Aug 20 2024 jiangheng <jiangheng14@huawei.com> - 23.11-20270* Tue Aug 20 2024 jiangheng <jiangheng14@huawei.com> - 23.11-20
264 - add static library271 - add static library
265 - remove unused requires/buildrequires272 - remove unused requires/buildrequires