From a5af4084da7ac7ea3b6193b0f055ae4c85ee0894 Mon Sep 17 00:00:00 2001 From: yanying <201250106@smail.nju.edu.cn> Date: Thu, 19 Sep 2024 13:58:15 +0800 Subject: [PATCH] Support clang build - modify some meson.build to fix clang build - drivers/meson.build - default_cflags add '-pie' and '-Wtrampolines' only if the compiler has the arguments - move '-Wl,-z,relro,-z,now,-z,noexecstack' to default_ldflags which will pass to linker args - kernel/linux/igb_uio/meson.build - Add the CC parameter to the make command to specify using clang if kernel was built by clang - add "-fgcc-compatible" to cflags when building with clang --- ...-some-meson.build-to-fix-clang-build.patch | 79 +++++++++++++++++++ dpdk.spec | 11 ++- 2 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 0046-modify-some-meson.build-to-fix-clang-build.patch diff --git a/0046-modify-some-meson.build-to-fix-clang-build.patch b/0046-modify-some-meson.build-to-fix-clang-build.patch new file mode 100644 index 0000000..a30d593 --- /dev/null +++ b/0046-modify-some-meson.build-to-fix-clang-build.patch @@ -0,0 +1,79 @@ +From 6a7fdd684f17f6f2ec8fedd5bc5c1e354426df3f Mon Sep 17 00:00:00 2001 +From: yanying <201250106@smail.nju.edu.cn> +Date: Sat, 28 Sep 2024 22:14:13 +0800 +Subject: [PATCH] modify some meson.build to fix clang build - + drivers/meson.build - default_cflags add '-pie' and '-Wtrampolines' only + if the compiler has the arguments - move + '-Wl,-z,relro,-z,now,-z,noexecstack' to default_ldflags which will pass to + linker args + +- kernel/linux/igb_uio/meson.build + - Add the CC parameter to the make command to specify using clang if kernel was built by clang +--- + drivers/meson.build | 14 ++++++++++++-- + kernel/linux/igb_uio/meson.build | 14 +++++++++++++- + 2 files changed, 25 insertions(+), 3 deletions(-) + +diff --git a/drivers/meson.build b/drivers/meson.build +index 1891192..f795250 100644 +--- a/drivers/meson.build ++++ b/drivers/meson.build +@@ -57,8 +57,17 @@ enable_drivers += always_enable + default_cflags = machine_args + default_cflags += ['-DALLOW_EXPERIMENTAL_API'] + default_cflags += ['-DALLOW_INTERNAL_API'] +-default_cflags += ['-fPIE', '-pie', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall'] +-default_cflags += ['-Wl,-z,relro,-z,now,-z,noexecstack', '-Wtrampolines'] ++default_cflags += ['-fPIE', '-fPIC', '-fstack-protector-strong', '-D_FORTIFY_SOURCE=2', '-O2', '-Wall'] ++ ++if cc.has_argument('-pie') ++ default_cflags += '-pie' ++endif ++ ++if cc.has_argument('-Wtrampolines') ++ default_cflags += '-Wtrampolines' ++endif ++ ++default_ldflags = ['-Wl,-z,relro,-z,now,-z,noexecstack'] + + if cc.has_argument('-Wno-format-truncation') + default_cflags += '-Wno-format-truncation' +@@ -255,6 +264,7 @@ foreach subpath:subdirs + + lk_deps = [] + lk_args = [] ++ lk_args += default_ldflags + if not fs.is_file(version_map) + version_map = '@0@/version.map'.format(meson.current_source_dir()) + lk_deps += [version_map] +diff --git a/kernel/linux/igb_uio/meson.build b/kernel/linux/igb_uio/meson.build +index ff8f97c..e8458e7 100644 +--- a/kernel/linux/igb_uio/meson.build ++++ b/kernel/linux/igb_uio/meson.build +@@ -14,10 +14,22 @@ igb_uio_sources = files( + 'Kbuild', + ) + ++cc_param = '' ++kernel_compile_file = '/lib/modules/' + run_command('uname', '-r').stdout().strip() + '/build/include/generated/compile.h' ++ ++if fs.exists(kernel_compile_file) ++ kernel_compile_info = run_command('grep', '-oP', '(clang).*', kernel_compile_file) ++ if kernel_compile_info.returncode() == 0 ++ if kernel_compile_info.stdout().strip().contains('clang') ++ cc_param = 'CC=clang' ++ endif ++ endif ++endif ++ + custom_target('igb_uio', + input: igb_uio_sources, + output: 'igb_uio.ko', +- command: ['make', '-j4', '-C', kernel_build_dir, ++ command: ['make', '-j4', '-C', kernel_build_dir, cc_param, + 'M=' + meson.current_build_dir(), + 'src=' + meson.current_source_dir(), + 'modules'] + cross_args, +-- +2.41.0.windows.1 + diff --git a/dpdk.spec b/dpdk.spec index 1f81f20..7bff69e 100644 --- a/dpdk.spec +++ b/dpdk.spec @@ -10,7 +10,7 @@ Name: dpdk Version: 23.11 -Release: 20 +Release: 21 URL: http://dpdk.org Source: https://fast.dpdk.org/rel/dpdk-%{version}.tar.xz @@ -71,6 +71,8 @@ Patch9037: 0043-remove-symbol-for-examples-and-app.patch Patch6044: 0044-net-hns3-support-more-VLAN-fields-matching.patch Patch6045: 0045-net-hns3-add-Rx-DMA-address-align-check.patch +Patch9046: 0046-modify-some-meson.build-to-fix-clang-build.patch + BuildRequires: meson BuildRequires: python3-pyelftools BuildRequires: diffutils @@ -170,7 +172,7 @@ end %autosetup -n %{name}-%{version} -S git_am %build -CFLAGS="$(echo %{optflags} -fcommon)" \ +CFLAGS="$(echo %{optflags} -fcommon %[ "%{toolchain}" == "clang" ? "-fgcc-compatible" : "" ])" \ %meson --includedir=include/dpdk \ -Ddrivers_install_subdir=dpdk-pmds \ -Denable_docs=false \ @@ -260,6 +262,11 @@ strip -g $RPM_BUILD_ROOT/lib/modules/%{kern_devel_ver}/extra/dpdk/igb_uio.ko %endif %changelog +* Thu Sep 19 2024 yanying <201250106@smail.nju.edu.cn> - 23.11-21 + Support clang build + - modify drivers/meson.build and kernel/linux/igb_uio/meson.build + - add "-fgcc-compatible" when building with clang + * Tue Aug 20 2024 jiangheng - 23.11-20 - add static library - remove unused requires/buildrequires -- Gitee