Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to LLVM 14, introduce clang-format #612

Merged
merged 4 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ blocks:
- ( export GOARCH=arm64; go build ./... && for p in $(go list ./...) ; do go test -c $p || exit ; done )
- make clean
- make container-all
- git diff --exit-code || { echo "generated files are not up to date" >&2; false; }
- git diff --exit-code || { echo "found unformatted source files, or generated files are not up to date, run 'make'" >&2; false; }
- pushd ./examples
- go build -v -o "$(mktemp -d)" ./...
- popd
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# The development version of clang is distributed as the 'clang' binary,
# while stable/released versions have a version number attached.
# Pin the default clang to a stable version.
CLANG ?= clang-13
STRIP ?= llvm-strip-13
CLANG ?= clang-14
STRIP ?= llvm-strip-14
CFLAGS := -O2 -g -Wall -Werror $(CFLAGS)

# Obtain an absolute path to the directory of the Makefile.
Expand Down 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.
27 changes: 13 additions & 14 deletions examples/cgroup_skb/cgroup_skb.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
// +build ignore

#include "common.h"
#include "bpf_helpers.h"

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.
1 change: 1 addition & 0 deletions examples/headers/bpf_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* in advance since bpf_helper_defs.h uses such types
* as __u64.
*/
#include "common.h"
#include "bpf_helper_defs.h"

#define __uint(name, val) int (*name)[val]
Expand Down
Binary file modified examples/kprobe/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/kprobe/bpf_bpfel.o
Binary file not shown.
27 changes: 13 additions & 14 deletions examples/kprobe/kprobe.c
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
// +build ignore

#include "common.h"
#include "bpf_helpers.h"

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.
1 change: 0 additions & 1 deletion examples/kprobepin/kprobe_pin.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// +build ignore

#include "common.h"
#include "bpf_helpers.h"

char __license[] SEC("license") = "Dual MIT/GPL";
Expand Down
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
3 changes: 2 additions & 1 deletion testdata/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ 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-13 llvm-13 && \
clang-14 llvm-14 && \
rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion testdata/docker/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1637058444
1648566014
10 changes: 2 additions & 8 deletions testdata/docker/llvm.list
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,5 @@ deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-7 main
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-9 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-9 main

deb http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-11 main

deb http://apt.llvm.org/buster/ llvm-toolchain-buster-12 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-12 main

deb http://apt.llvm.org/buster/ llvm-toolchain-buster-13 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-13 main
deb http://apt.llvm.org/buster/ llvm-toolchain-buster-14 main
deb-src http://apt.llvm.org/buster/ llvm-toolchain-buster-14 main
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.