Skip to content

Commit

Permalink
Makefile: add 'format' target for calling clang-format
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ti-mo committed Mar 29, 2022
1 parent 4bf2043 commit 4fa3ebc
Show file tree
Hide file tree
Showing 65 changed files with 61 additions and 55 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ clean:
-$(RM) testdata/*.elf
-$(RM) internal/btf/testdata/*.elf

all: $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) generate
format:
find . -type f -name "*.c" | xargs clang-format -i

all: format $(addsuffix -el.elf,$(TARGETS)) $(addsuffix -eb.elf,$(TARGETS)) generate
ln -srf testdata/loader-$(CLANG)-el.elf testdata/loader-el.elf
ln -srf testdata/loader-$(CLANG)-eb.elf testdata/loader-eb.elf

Expand Down
Binary file modified cmd/bpf2go/test/test_bpfeb.o
Binary file not shown.
Binary file modified cmd/bpf2go/test/test_bpfel.o
Binary file not shown.
Binary file modified examples/cgroup_skb/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/cgroup_skb/bpf_bpfel.o
Binary file not shown.
26 changes: 13 additions & 13 deletions examples/cgroup_skb/cgroup_skb.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
char __license[] SEC("license") = "Dual MIT/GPL";

struct bpf_map_def SEC("maps") pkt_count = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u64),
.max_entries = 1,
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u64),
.max_entries = 1,
};

SEC("cgroup_skb/egress")
int count_egress_packets(struct __sk_buff *skb) {
u32 key = 0;
u64 init_val = 1;
u32 key = 0;
u64 init_val = 1;

u64 *count = bpf_map_lookup_elem(&pkt_count, &key);
if (!count) {
bpf_map_update_elem(&pkt_count, &key, &init_val, BPF_ANY);
return 1;
}
__sync_fetch_and_add(count, 1);
u64 *count = bpf_map_lookup_elem(&pkt_count, &key);
if (!count) {
bpf_map_update_elem(&pkt_count, &key, &init_val, BPF_ANY);
return 1;
}
__sync_fetch_and_add(count, 1);

return 1;
return 1;
}
Binary file modified examples/fentry/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/fentry/bpf_bpfel.o
Binary file not shown.
Binary file modified examples/kprobe/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/kprobe/bpf_bpfel.o
Binary file not shown.
26 changes: 13 additions & 13 deletions examples/kprobe/kprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
char __license[] SEC("license") = "Dual MIT/GPL";

struct bpf_map_def SEC("maps") kprobe_map = {
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u64),
.max_entries = 1,
.type = BPF_MAP_TYPE_ARRAY,
.key_size = sizeof(u32),
.value_size = sizeof(u64),
.max_entries = 1,
};

SEC("kprobe/sys_execve")
int kprobe_execve() {
u32 key = 0;
u64 initval = 1, *valp;
u32 key = 0;
u64 initval = 1, *valp;

valp = bpf_map_lookup_elem(&kprobe_map, &key);
if (!valp) {
bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
return 0;
}
__sync_fetch_and_add(valp, 1);
valp = bpf_map_lookup_elem(&kprobe_map, &key);
if (!valp) {
bpf_map_update_elem(&kprobe_map, &key, &initval, BPF_ANY);
return 0;
}
__sync_fetch_and_add(valp, 1);

return 0;
return 0;
}
Binary file modified examples/kprobe_percpu/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/kprobe_percpu/bpf_bpfel.o
Binary file not shown.
Binary file modified examples/kprobepin/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/kprobepin/bpf_bpfel.o
Binary file not shown.
Binary file modified examples/ringbuffer/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/ringbuffer/bpf_bpfel.o
Binary file not shown.
Binary file modified examples/tracepoint_in_c/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/tracepoint_in_c/bpf_bpfel.o
Binary file not shown.
Binary file modified examples/uretprobe/bpf_bpfel_x86.o
Binary file not shown.
Binary file modified internal/btf/testdata/relocs-eb.elf
Binary file not shown.
Binary file modified internal/btf/testdata/relocs-el.elf
Binary file not shown.
1 change: 0 additions & 1 deletion internal/btf/testdata/relocs.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,3 @@ __section("socket_filter/err_ambiguous") int err_ambiguous() {
__section("socket_filter/err_ambiguous_flavour") int err_ambiguous_flavour() {
return bpf_core_type_id_kernel(struct ambiguous___flavour);
}

Binary file modified internal/btf/testdata/relocs_read-eb.elf
Binary file not shown.
Binary file modified internal/btf/testdata/relocs_read-el.elf
Binary file not shown.
Binary file modified internal/btf/testdata/relocs_read_tgt-eb.elf
Binary file not shown.
Binary file modified internal/btf/testdata/relocs_read_tgt-el.elf
Binary file not shown.
Binary file modified testdata/btf_map_init-eb.elf
Binary file not shown.
Binary file modified testdata/btf_map_init-el.elf
Binary file not shown.
30 changes: 16 additions & 14 deletions testdata/btf_map_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ struct {
__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
__uint(key_size, sizeof(uint32_t));
__uint(max_entries, 2);
__array(values, int ());
__array(values, int());
} prog_array_init __section(".maps") = {
.values = {
// Skip index 0 to exercise empty array slots.
[1] = &tail_1,
},
.values =
{
// Skip index 0 to exercise empty array slots.
[1] = &tail_1,
},
};

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

return 0;
return 0;
}

// Inner map with a single possible entry.
Expand All @@ -46,10 +47,11 @@ struct {
__uint(value_size, sizeof(uint32_t));
__array(values, typeof(inner_map));
} outer_map_init __section(".maps") = {
.values = {
// Skip index 0 to exercise empty array slots.
[1] = &inner_map,
},
.values =
{
// Skip index 0 to exercise empty array slots.
[1] = &inner_map,
},
};

#else
Expand Down
1 change: 1 addition & 0 deletions testdata/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY llvm.list /etc/apt/sources.list.d
RUN apt-get update && \
apt-get -y --no-install-recommends install \
make git \
clang-format \
clang-7 llvm-7 \
clang-9 llvm-9 \
clang-14 llvm-14 && \
Expand Down
2 changes: 1 addition & 1 deletion testdata/docker/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1637058444
1648566014
Binary file modified testdata/freplace-eb.elf
Binary file not shown.
Binary file modified testdata/freplace-el.elf
Binary file not shown.
Binary file modified testdata/fwd_decl-eb.elf
Binary file not shown.
Binary file modified testdata/fwd_decl-el.elf
Binary file not shown.
Binary file modified testdata/invalid_btf_map_init-eb.elf
Binary file not shown.
Binary file modified testdata/invalid_btf_map_init-el.elf
Binary file not shown.
Binary file modified testdata/invalid_map-eb.elf
Binary file not shown.
Binary file modified testdata/invalid_map-el.elf
Binary file not shown.
Binary file modified testdata/invalid_map_static-eb.elf
Binary file not shown.
Binary file modified testdata/invalid_map_static-el.elf
Binary file not shown.
Binary file modified testdata/iproute2_map_compat-eb.elf
Binary file not shown.
Binary file modified testdata/iproute2_map_compat-el.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion testdata/iproute2_map_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "common.h"

#define PIN_GLOBAL_NS 2
#define PIN_GLOBAL_NS 2

// bpf_elf_map is a custom BPF map definition used by iproute2.
// It contains the id, pinning, inner_id and inner_idx fields
Expand Down
Binary file removed testdata/loader-clang-13-eb.elf
Binary file not shown.
Binary file removed testdata/loader-clang-13-el.elf
Binary file not shown.
Binary file added testdata/loader-clang-14-eb.elf
Binary file not shown.
Binary file added testdata/loader-clang-14-el.elf
Binary file not shown.
Binary file modified testdata/loader-clang-7-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-7-el.elf
Binary file not shown.
Binary file modified testdata/loader-clang-9-eb.elf
Binary file not shown.
Binary file modified testdata/loader-clang-9-el.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion testdata/loader-eb.elf
2 changes: 1 addition & 1 deletion testdata/loader-el.elf
13 changes: 7 additions & 6 deletions testdata/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__uint(key_size, sizeof(uint32_t));
__uint(max_entries, 1);
__array(values, struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, uint32_t);
__type(value, uint32_t);
});
__array(
values, struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 1);
__type(key, uint32_t);
__type(value, uint32_t);
});
} btf_outer_map_anon __section(".maps");

struct {
Expand Down
Binary file modified testdata/map_spin_lock-eb.elf
Binary file not shown.
Binary file modified testdata/map_spin_lock-el.elf
Binary file not shown.
6 changes: 3 additions & 3 deletions testdata/map_spin_lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include "common.h"

struct bpf_spin_lock {
uint32_t val;
uint32_t val;
};

struct hash_elem {
int cnt;
struct bpf_spin_lock lock;
int cnt;
struct bpf_spin_lock lock;
};

#if __clang_major__ >= 9
Expand Down
Binary file modified testdata/raw_tracepoint-eb.elf
Binary file not shown.
Binary file modified testdata/raw_tracepoint-el.elf
Binary file not shown.
Binary file modified testdata/strings-eb.elf
Binary file not shown.
Binary file modified testdata/strings-el.elf
Binary file not shown.
Binary file modified testdata/subprog_reloc-eb.elf
Binary file not shown.
Binary file modified testdata/subprog_reloc-el.elf
Binary file not shown.

0 comments on commit 4fa3ebc

Please sign in to comment.