• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

systemd / systemd / 14630481637

23 Apr 2025 07:04PM UTC coverage: 72.178% (-0.002%) from 72.18%
14630481637

push

github

DaanDeMeyer
mkosi: Run clangd within the tools tree instead of the build container

Running within the build sandbox has a number of disadvantages:
- We have a separate clangd cache for each distribution/release combo
- It requires to build the full image before clangd can be used
- It breaks every time the image becomes out of date and requires a
  rebuild
- We can't look at system headers as we don't have the knowledge to map
  them from inside the build sandbox to the corresponding path on the host

Instead, let's have mkosi.clangd run clangd within the tools tree. We
already require building systemd for both the host and the target anyway,
and all the dependencies to build systemd are installed in the tools tree
already for that, as well as clangd since it's installed together with the
other clang tooling we install in the tools tree. Unlike the previous approach,
this approach only requires the mkosi tools tree to be built upfront, which has
a much higher chance of not invalidating its cache. We can also trivially map
system header lookups from within the sandbox to the path within mkosi.tools
on the host so that starts working as well.

297054 of 411557 relevant lines covered (72.18%)

686269.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.0
/src/shared/bpf-compat.h
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3

4
#include <bpf/libbpf.h>
5

6
/* libbpf has been moving quickly.
7
 * They added new symbols in the 0.x versions and shortly after removed
8
 * deprecated symbols in 1.0.
9
 * We only need bpf_map_create and libbpf_probe_bpf_prog_type so we work
10
 * around the incompatibility here by:
11
 *  - declaring both symbols, and looking for either depending on the libbpf
12
 *    so version we found
13
 *  - having helpers that automatically use the appropriate version behind the
14
 *    new API for easy cleanup later
15
 *
16
 * The advantage of doing this instead of only looking for the symbols declared at
17
 * compile time is that we can then load either the old or the new symbols at runtime
18
 * regardless of the version we were compiled with */
19

20
/* declare the struct for libbpf <= 0.6.0 -- it causes no harm on newer versions */
21
struct bpf_map_create_opts;
22

23
/* new symbols available from 0.7.0.
24
 * We need the symbols here:
25
 *  - after bpf_map_create_opts struct has been defined for older libbpf
26
 *  - before the compat static inline helpers that use them.
27
 * When removing this file move these back to bpf-dlopen.h */
28
extern int (*sym_bpf_map_create)(enum bpf_map_type,  const char *, __u32, __u32, __u32, const struct bpf_map_create_opts *);
29
extern int (*sym_libbpf_probe_bpf_prog_type)(enum bpf_prog_type, const void *);
30
extern struct bpf_map* (*sym_bpf_object__next_map)(const struct bpf_object *obj, const struct bpf_map *map);
31

32
/* compat symbols removed in libbpf 1.0 */
33
extern int (*sym_bpf_create_map)(enum bpf_map_type, int key_size, int value_size, int max_entries, __u32 map_flags);
34
extern bool (*sym_bpf_probe_prog_type)(enum bpf_prog_type, __u32);
35

36
/* helpers to use the available variant behind new API */
37
static inline int compat_bpf_map_create(enum bpf_map_type map_type,
92✔
38
                const char *map_name,
39
                __u32 key_size,
40
                __u32 value_size,
41
                __u32 max_entries,
42
                const struct bpf_map_create_opts *opts) {
43
        if (sym_bpf_map_create)
92✔
44
                return sym_bpf_map_create(map_type, map_name, key_size,
92✔
45
                                          value_size, max_entries, opts);
46

47
        return sym_bpf_create_map(map_type, key_size, value_size, max_entries,
×
48
                                  0 /* opts->map_flags, but opts is always NULL for us so skip build dependency on the type */);
49
}
50

51
static inline int compat_libbpf_probe_bpf_prog_type(enum bpf_prog_type prog_type, const void *opts) {
468✔
52
        if (sym_libbpf_probe_bpf_prog_type)
468✔
53
                return sym_libbpf_probe_bpf_prog_type(prog_type, opts);
468✔
54

55
        return sym_bpf_probe_prog_type(prog_type, 0);
×
56
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc