From 34269a63986e7b297e0b66b9f1a02df2fe286988 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 23 May 2025 11:27:31 +0200 Subject: [PATCH 1/6] generate-sym-test: Only include required headers If we don't use any symbols from a header, let's not include it. --- src/test/generate-sym-test.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/generate-sym-test.py b/src/test/generate-sym-test.py index 7b5ded936c..5aaf372c1d 100755 --- a/src/test/generate-sym-test.py +++ b/src/test/generate-sym-test.py @@ -19,7 +19,9 @@ def process_sym_file(file: IO[str]) -> None: print(f' {{ "{m[1]}", {m[1]} }},') -def process_header_file(file: IO[str]) -> None: +def process_header_file(file: IO[str]) -> str: + text = '' + for line in file: if ( line.startswith('#') @@ -43,22 +45,24 @@ def process_header_file(file: IO[str]) -> None: # Functions m = re.search(r'^(\S+\s+)+\**(\w+)\s*\(', line) if m: - print(f' {{ "{m[2]}", {m[2]} }},') + text += f' {{ "{m[2]}", {m[2]} }},\n' continue # Variables m = re.search(r'^extern\s', line) if m: n = line.split()[-1].rstrip(';') - print(f' {{ "{n}", &{n} }},') + text += f' {{ "{n}", &{n} }},\n' continue # Functions defined by macro m = re.search(r'_SD_DEFINE_POINTER_CLEANUP_FUNC\(\w+,\s*(\w+)\)', line) if m: - print(f' {{ "{m[1]}", {m[1]} }},') + text += f' {{ "{m[1]}", {m[1]} }},\n' continue + return text + def process_source_file(file: IO[str]) -> None: for line in file: @@ -107,7 +111,9 @@ print("""/* SPDX-License-Identifier: LGPL-2.1-or-later */ """) for header in sys.argv[3:]: - print('#include "{}"'.format(header.split('/')[-1])) + with open(header, 'r') as f: + if process_header_file(f): + print('#include "{}"'.format(header.split('/')[-1])) print(""" /* We want to check deprecated symbols too, without complaining */ @@ -129,7 +135,7 @@ print(""" {} for header in sys.argv[3:]: with open(header, 'r') as f: - process_header_file(f) + print(process_header_file(f), end='') print(""" {} }, symbols_from_source[] = {""") From a119c648f8219d73f4331fd53ecfb569d0ca2f45 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 23 May 2025 13:32:52 +0200 Subject: [PATCH 2/6] fundamental: Move declaration of free() to macro-fundamental.h Let's put it together with the macro that needs it (mfree()). Also, get rid of the unnecessary include in iovec-util-fundamental.h. --- src/fundamental/iovec-util-fundamental.h | 5 ----- src/fundamental/macro-fundamental.h | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fundamental/iovec-util-fundamental.h b/src/fundamental/iovec-util-fundamental.h index 4c86197e6f..024dd9bf78 100644 --- a/src/fundamental/iovec-util-fundamental.h +++ b/src/fundamental/iovec-util-fundamental.h @@ -2,7 +2,6 @@ #pragma once #if !SD_BOOT -#include #include #endif @@ -15,10 +14,6 @@ struct iovec { void *iov_base; size_t iov_len; }; - -DISABLE_WARNING_REDUNDANT_DECLS; -void free(void *p); -REENABLE_WARNING; #endif /* This accepts both const and non-const pointers */ diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index 6a75d7864a..69bbeead48 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -396,6 +396,10 @@ assert_cc(sizeof(long long) == sizeof(intmax_t)); */ #define STRLEN(x) (sizeof(""x"") - sizeof(typeof(x[0]))) +DISABLE_WARNING_REDUNDANT_DECLS; +void free(void *p); +REENABLE_WARNING; + #define mfree(memory) \ ({ \ free(memory); \ From b4f3a3ad06266ed7a089c6c4783c495826e55521 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 23 May 2025 13:36:55 +0200 Subject: [PATCH 3/6] core: Add missing bpf-dlopen.h includes to bpf skeleton headers --- src/core/bpf/restrict_fs/restrict-fs-skel.h | 2 ++ src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h | 2 ++ src/core/bpf/socket_bind/socket-bind-skel.h | 2 ++ 3 files changed, 6 insertions(+) diff --git a/src/core/bpf/restrict_fs/restrict-fs-skel.h b/src/core/bpf/restrict_fs/restrict-fs-skel.h index 412cf62eda..825b8131f9 100644 --- a/src/core/bpf/restrict_fs/restrict-fs-skel.h +++ b/src/core/bpf/restrict_fs/restrict-fs-skel.h @@ -6,6 +6,8 @@ * fine given that LGPL-2.1-or-later downgrades to GPL if needed. */ +#include "bpf-dlopen.h" + /* libbpf is used via dlopen(), so rename symbols */ #define bpf_object__open_skeleton sym_bpf_object__open_skeleton #define bpf_object__load_skeleton sym_bpf_object__load_skeleton diff --git a/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h b/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h index f937490954..f0675f270b 100644 --- a/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h +++ b/src/core/bpf/restrict_ifaces/restrict-ifaces-skel.h @@ -6,6 +6,8 @@ * fine given that LGPL-2.1-or-later downgrades to GPL if needed. */ +#include "bpf-dlopen.h" + /* libbpf is used via dlopen(), so rename symbols */ #define bpf_object__open_skeleton sym_bpf_object__open_skeleton #define bpf_object__load_skeleton sym_bpf_object__load_skeleton diff --git a/src/core/bpf/socket_bind/socket-bind-skel.h b/src/core/bpf/socket_bind/socket-bind-skel.h index e0d16269cd..c92eae002d 100644 --- a/src/core/bpf/socket_bind/socket-bind-skel.h +++ b/src/core/bpf/socket_bind/socket-bind-skel.h @@ -6,6 +6,8 @@ * fine given that LGPL-2.1-or-later downgrades to GPL if needed. */ +#include "bpf-dlopen.h" + /* libbpf is used via dlopen(), so rename symbols */ #define bpf_object__open_skeleton sym_bpf_object__open_skeleton #define bpf_object__load_skeleton sym_bpf_object__load_skeleton From 91a82e790e14228a2b8921e2361b074202e61029 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Wed, 21 May 2025 12:55:35 +0200 Subject: [PATCH 4/6] ci: Setup clang-tidy meson env with extra options We want the relevant code to be compiled so that it can be analyzed by clang-tidy. --- .github/workflows/linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml index 5aca56290d..252ae4eb6a 100644 --- a/.github/workflows/linter.yml +++ b/.github/workflows/linter.yml @@ -71,7 +71,7 @@ jobs: fi - name: Configure meson - run: mkosi sandbox -- env CC=clang CXX=clang++ meson setup build + run: mkosi sandbox -- env CC=clang CXX=clang++ meson setup -Dlocalegen-path=/usr/bin/locale-gen -Dcompat-mutable-uid-boundaries=true build - name: Run clang-tidy run: mkosi sandbox -- meson test -C build --suite=clang-tidy --print-errorlogs --no-stdsplit From 8ad0d6d4790f18528d8d52ebdd4fccce62c03e88 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 23 May 2025 13:03:57 +0200 Subject: [PATCH 5/6] clang-tidy: Skip public headers We're very limited in our ability to change these due to backwards compat, so let's skip them from analysis since we won't be able to fix the errors anyway. --- meson.build | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 4618520bca..c1cdfb2c8e 100644 --- a/meson.build +++ b/meson.build @@ -2841,6 +2841,10 @@ alias_target('gensources', generated_sources) clang_tidy = find_program('clang-tidy', required : false) if meson.version().version_compare('>=1.4.0') foreach source : sources + if systemd_headers.contains(source) + continue + endif + if not source.full_path().endswith('.c') and not source.full_path().endswith('.h') continue endif @@ -2848,7 +2852,7 @@ if meson.version().version_compare('>=1.4.0') inputs = [source] header = source.full_path().replace('.c', '.h') - if fs.exists(header) and header != source.full_path() + if fs.exists(header) and header != source.full_path() and header != libudev_h_path inputs += header endif From b065d3529ad3fb8ff2df447705633bc0f0dfdfda Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Fri, 23 May 2025 13:54:46 +0200 Subject: [PATCH 6/6] clangd: Enable UnusedIncludes feature again Now that the entire free doesn't trigger any clang unused include violations anymore, let's re-enable the clangd option as it's much more useful now that the tree is clean. --- .clangd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.clangd b/.clangd index 8cc437ab81..24886efe9e 100644 --- a/.clangd +++ b/.clangd @@ -1,4 +1,4 @@ # SPDX-License-Identifier: LGPL-2.1-or-later Diagnostics: - UnusedIncludes: None + UnusedIncludes: Strict