Skip to content

Commit 4fa3ebc

Browse files
committed
Makefile: add 'format' target for calling clang-format
This commit adds the clang-format make target, runs it on the whole repository and rebuilds all testdata and example ELFs. Signed-off-by: Timo Beckers <timo@isovalent.com>
1 parent 4bf2043 commit 4fa3ebc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+61
-55
lines changed

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ clean:
6262
-$(RM) testdata/*.elf
6363
-$(RM) internal/btf/testdata/*.elf
6464

65-
all: $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) generate
65+
format:
66+
find . -type f -name "*.c" | xargs clang-format -i
67+
68+
all: format $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) generate
6669
ln -srf testdata/loader-$(CLANG)-el.elf testdata/loader-el.elf
6770
ln -srf testdata/loader-$(CLANG)-eb.elf testdata/loader-eb.elf
6871

cmd/bpf2go/test/test_bpfeb.o

-8 Bytes
Binary file not shown.

cmd/bpf2go/test/test_bpfel.o

-8 Bytes
Binary file not shown.

examples/cgroup_skb/bpf_bpfeb.o

-16 Bytes
Binary file not shown.

examples/cgroup_skb/bpf_bpfel.o

-16 Bytes
Binary file not shown.

examples/cgroup_skb/cgroup_skb.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
char __license[] SEC("license") = "Dual MIT/GPL";
66

77
struct bpf_map_def SEC("maps") pkt_count = {
8-
.type = BPF_MAP_TYPE_ARRAY,
9-
.key_size = sizeof(u32),
10-
.value_size = sizeof(u64),
11-
.max_entries = 1,
8+
.type = BPF_MAP_TYPE_ARRAY,
9+
.key_size = sizeof(u32),
10+
.value_size = sizeof(u64),
11+
.max_entries = 1,
1212
};
1313

1414
SEC("cgroup_skb/egress")
1515
int count_egress_packets(struct __sk_buff *skb) {
16-
u32 key = 0;
17-
u64 init_val = 1;
16+
u32 key = 0;
17+
u64 init_val = 1;
1818

19-
u64 *count = bpf_map_lookup_elem(&pkt_count, &key);
20-
if (!count) {
21-
bpf_map_update_elem(&pkt_count, &key, &init_val, BPF_ANY);
22-
return 1;
23-
}
24-
__sync_fetch_and_add(count, 1);
19+
u64 *count = bpf_map_lookup_elem(&pkt_count, &key);
20+
if (!count) {
21+
bpf_map_update_elem(&pkt_count, &key, &init_val, BPF_ANY);
22+
return 1;
23+
}
24+
__sync_fetch_and_add(count, 1);
2525

26-
return 1;
26+
return 1;
2727
}

examples/fentry/bpf_bpfeb.o

-8 Bytes
Binary file not shown.

examples/fentry/bpf_bpfel.o

-8 Bytes
Binary file not shown.

examples/kprobe/bpf_bpfeb.o

-16 Bytes
Binary file not shown.

examples/kprobe/bpf_bpfel.o

-16 Bytes
Binary file not shown.

examples/kprobe/kprobe.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
char __license[] SEC("license") = "Dual MIT/GPL";
66

77
struct bpf_map_def SEC("maps") kprobe_map = {
8-
.type = BPF_MAP_TYPE_ARRAY,
9-
.key_size = sizeof(u32),
10-
.value_size = sizeof(u64),
11-
.max_entries = 1,
8+
.type = BPF_MAP_TYPE_ARRAY,
9+
.key_size = sizeof(u32),
10+
.value_size = sizeof(u64),
11+
.max_entries = 1,
1212
};
1313

1414
SEC("kprobe/sys_execve")
1515
int kprobe_execve() {
16-
u32 key = 0;
17-
u64 initval = 1, *valp;
16+
u32 key = 0;
17+
u64 initval = 1, *valp;
1818

19-
valp = bpf_map_lookup_elem(&kprobe_map, &key);
20-
if (!valp) {
21-
bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
22-
return 0;
23-
}
24-
__sync_fetch_and_add(valp, 1);
19+
valp = bpf_map_lookup_elem(&kprobe_map, &key);
20+
if (!valp) {
21+
bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
22+
return 0;
23+
}
24+
__sync_fetch_and_add(valp, 1);
2525

26-
return 0;
26+
return 0;
2727
}

examples/kprobe_percpu/bpf_bpfeb.o

0 Bytes
Binary file not shown.

examples/kprobe_percpu/bpf_bpfel.o

0 Bytes
Binary file not shown.

examples/kprobepin/bpf_bpfeb.o

-8 Bytes
Binary file not shown.

examples/kprobepin/bpf_bpfel.o

-8 Bytes
Binary file not shown.

examples/ringbuffer/bpf_bpfeb.o

0 Bytes
Binary file not shown.

examples/ringbuffer/bpf_bpfel.o

0 Bytes
Binary file not shown.

examples/tracepoint_in_c/bpf_bpfeb.o

0 Bytes
Binary file not shown.

examples/tracepoint_in_c/bpf_bpfel.o

0 Bytes
Binary file not shown.

examples/uretprobe/bpf_bpfel_x86.o

0 Bytes
Binary file not shown.

internal/btf/testdata/relocs-eb.elf

0 Bytes
Binary file not shown.

internal/btf/testdata/relocs-el.elf

0 Bytes
Binary file not shown.

internal/btf/testdata/relocs.c

-1
Original file line numberDiff line numberDiff line change
@@ -238,4 +238,3 @@ __section("socket_filter/err_ambiguous") int err_ambiguous() {
238238
__section("socket_filter/err_ambiguous_flavour") int err_ambiguous_flavour() {
239239
return bpf_core_type_id_kernel(struct ambiguous___flavour);
240240
}
241-
-8 Bytes
Binary file not shown.
-8 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

testdata/btf_map_init-eb.elf

0 Bytes
Binary file not shown.

testdata/btf_map_init-el.elf

0 Bytes
Binary file not shown.

testdata/btf_map_init.c

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,22 @@ struct {
1313
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
1414
__uint(key_size, sizeof(uint32_t));
1515
__uint(max_entries, 2);
16-
__array(values, int ());
16+
__array(values, int());
1717
} prog_array_init __section(".maps") = {
18-
.values = {
19-
// Skip index 0 to exercise empty array slots.
20-
[1] = &tail_1,
21-
},
18+
.values =
19+
{
20+
// Skip index 0 to exercise empty array slots.
21+
[1] = &tail_1,
22+
},
2223
};
2324

2425
int __section("socket/main") tail_main(void *ctx) {
25-
// If prog_array_init is correctly populated, the tail call
26-
// will succeed and the program will continue in tail_1 and
27-
// not return here.
28-
tail_call(ctx, &prog_array_init, 1);
26+
// If prog_array_init is correctly populated, the tail call
27+
// will succeed and the program will continue in tail_1 and
28+
// not return here.
29+
tail_call(ctx, &prog_array_init, 1);
2930

30-
return 0;
31+
return 0;
3132
}
3233

3334
// Inner map with a single possible entry.
@@ -46,10 +47,11 @@ struct {
4647
__uint(value_size, sizeof(uint32_t));
4748
__array(values, typeof(inner_map));
4849
} outer_map_init __section(".maps") = {
49-
.values = {
50-
// Skip index 0 to exercise empty array slots.
51-
[1] = &inner_map,
52-
},
50+
.values =
51+
{
52+
// Skip index 0 to exercise empty array slots.
53+
[1] = &inner_map,
54+
},
5355
};
5456

5557
#else

testdata/docker/Dockerfile

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ COPY llvm.list /etc/apt/sources.list.d
1717
RUN apt-get update && \
1818
apt-get -y --no-install-recommends install \
1919
make git \
20+
clang-format \
2021
clang-7 llvm-7 \
2122
clang-9 llvm-9 \
2223
clang-14 llvm-14 && \

testdata/docker/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1637058444
1+
1648566014

testdata/freplace-eb.elf

-8 Bytes
Binary file not shown.

testdata/freplace-el.elf

-8 Bytes
Binary file not shown.

testdata/fwd_decl-eb.elf

0 Bytes
Binary file not shown.

testdata/fwd_decl-el.elf

0 Bytes
Binary file not shown.

testdata/invalid_btf_map_init-eb.elf

-8 Bytes
Binary file not shown.

testdata/invalid_btf_map_init-el.elf

-8 Bytes
Binary file not shown.

testdata/invalid_map-eb.elf

0 Bytes
Binary file not shown.

testdata/invalid_map-el.elf

0 Bytes
Binary file not shown.

testdata/invalid_map_static-eb.elf

0 Bytes
Binary file not shown.

testdata/invalid_map_static-el.elf

0 Bytes
Binary file not shown.

testdata/iproute2_map_compat-eb.elf

0 Bytes
Binary file not shown.

testdata/iproute2_map_compat-el.elf

0 Bytes
Binary file not shown.

testdata/iproute2_map_compat.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "common.h"
44

5-
#define PIN_GLOBAL_NS 2
5+
#define PIN_GLOBAL_NS 2
66

77
// bpf_elf_map is a custom BPF map definition used by iproute2.
88
// It contains the id, pinning, inner_id and inner_idx fields

testdata/loader-clang-13-eb.elf

-8.84 KB
Binary file not shown.

testdata/loader-clang-13-el.elf

-8.84 KB
Binary file not shown.

testdata/loader-clang-14-eb.elf

8.84 KB
Binary file not shown.

testdata/loader-clang-14-el.elf

8.84 KB
Binary file not shown.

testdata/loader-clang-7-eb.elf

0 Bytes
Binary file not shown.

testdata/loader-clang-7-el.elf

0 Bytes
Binary file not shown.

testdata/loader-clang-9-eb.elf

0 Bytes
Binary file not shown.

testdata/loader-clang-9-el.elf

0 Bytes
Binary file not shown.

testdata/loader-eb.elf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
loader-clang-13-eb.elf
1+
loader-clang-14-eb.elf

testdata/loader-el.elf

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
loader-clang-13-el.elf
1+
loader-clang-14-el.elf

testdata/loader.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ struct {
5151
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
5252
__uint(key_size, sizeof(uint32_t));
5353
__uint(max_entries, 1);
54-
__array(values, struct {
55-
__uint(type, BPF_MAP_TYPE_HASH);
56-
__uint(max_entries, 1);
57-
__type(key, uint32_t);
58-
__type(value, uint32_t);
59-
});
54+
__array(
55+
values, struct {
56+
__uint(type, BPF_MAP_TYPE_HASH);
57+
__uint(max_entries, 1);
58+
__type(key, uint32_t);
59+
__type(value, uint32_t);
60+
});
6061
} btf_outer_map_anon __section(".maps");
6162

6263
struct {

testdata/map_spin_lock-eb.elf

0 Bytes
Binary file not shown.

testdata/map_spin_lock-el.elf

0 Bytes
Binary file not shown.

testdata/map_spin_lock.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#include "common.h"
44

55
struct bpf_spin_lock {
6-
uint32_t val;
6+
uint32_t val;
77
};
88

99
struct hash_elem {
10-
int cnt;
11-
struct bpf_spin_lock lock;
10+
int cnt;
11+
struct bpf_spin_lock lock;
1212
};
1313

1414
#if __clang_major__ >= 9

testdata/raw_tracepoint-eb.elf

0 Bytes
Binary file not shown.

testdata/raw_tracepoint-el.elf

0 Bytes
Binary file not shown.

testdata/strings-eb.elf

0 Bytes
Binary file not shown.

testdata/strings-el.elf

0 Bytes
Binary file not shown.

testdata/subprog_reloc-eb.elf

0 Bytes
Binary file not shown.

testdata/subprog_reloc-el.elf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)