Skip to content

Commit

Permalink
examples: annotate ringbuf and perf event arrays with value type info…
Browse files Browse the repository at this point in the history
…rmation

This obviates the need for declaring these unused variables, which would otherwise
get included in bpf2go-generated Go code in a follow-up commit.

Signed-off-by: Timo Beckers <timo@isovalent.com>
  • Loading branch information
ti-mo committed Dec 16, 2024
1 parent e9bcebb commit 60405bb
Show file tree
Hide file tree
Showing 14 changed files with 5 additions and 9 deletions.
Binary file modified examples/fentry/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/fentry/bpf_bpfel.o
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/fentry/fentry.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct sock {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
__type(value, struct event);
} events SEC(".maps");

/**
Expand All @@ -71,7 +72,6 @@ struct event {
__be32 saddr;
__be32 daddr;
};
struct event *unused __attribute__((unused));

SEC("fentry/tcp_connect")
int BPF_PROG(tcp_connect, struct sock *sk) {
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.
4 changes: 1 addition & 3 deletions examples/ringbuffer/ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ struct event {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
__type(value, struct event);
} events SEC(".maps");

// Force emitting struct event into the ELF.
const struct event *unused __attribute__((unused));

SEC("kprobe/sys_execve")
int kprobe_execve(struct pt_regs *ctx) {
u64 id = bpf_get_current_pid_tgid();
Expand Down
Binary file modified examples/tcprtt/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/tcprtt/bpf_bpfel.o
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/tcprtt/tcprtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct tcp_sock {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
__type(value, struct event);
} events SEC(".maps");

/**
Expand All @@ -82,7 +83,6 @@ struct event {
u32 daddr;
u32 srtt;
};
struct event *unused_event __attribute__((unused));

SEC("fentry/tcp_close")
int BPF_PROG(tcp_close, struct sock *sk) {
Expand Down
Binary file modified examples/tcprtt_sockops/bpf_bpfeb.o
Binary file not shown.
Binary file modified examples/tcprtt_sockops/bpf_bpfel.o
Binary file not shown.
2 changes: 1 addition & 1 deletion examples/tcprtt_sockops/tcprtt_sockops.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct sk_info {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
__type(value, struct rtt_event);
} rtt_events SEC(".maps");

struct rtt_event {
Expand All @@ -47,7 +48,6 @@ struct rtt_event {
u32 daddr;
u32 srtt;
};
struct rtt_event *unused_event __attribute__((unused));

static inline void init_sk_key(struct bpf_sock_ops *skops, struct sk_key *sk_key) {
sk_key->local_ip4 = bpf_ntohl(skops->local_ip4);
Expand Down
Binary file modified examples/uretprobe/bpf_x86_bpfel.o
Binary file not shown.
4 changes: 1 addition & 3 deletions examples/uretprobe/uretprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ struct event {

struct {
__uint(type, BPF_MAP_TYPE_PERF_EVENT_ARRAY);
__type(value, struct event);
} events SEC(".maps");

// Force emitting struct event into the ELF.
const struct event *unused __attribute__((unused));

SEC("uretprobe/bash_readline")
int uretprobe_bash_readline(struct pt_regs *ctx) {
struct event event;
Expand Down

0 comments on commit 60405bb

Please sign in to comment.