Skip to content

Commit

Permalink
Merge pull request iovisor#3662 from chenhengqi/enable-warn-unused-vars
Browse files Browse the repository at this point in the history
libbpf-tools: Enable compilation warnings for BPF programs
  • Loading branch information
davemarchevsky committed Oct 16, 2021
2 parents 8b350fd + 531b698 commit d1afbf6
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion libbpf-tools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ $(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT)

$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(ARCH)/vmlinux.h | $(OUTPUT)
$(call msg,BPF,$@)
$(Q)$(CLANG) -g -O2 -target bpf -D__TARGET_ARCH_$(ARCH) \
$(Q)$(CLANG) $(CFLAGS) -target bpf -D__TARGET_ARCH_$(ARCH) \
-I$(ARCH)/ $(INCLUDES) -c $(filter %.c,$^) -o $@ && \
$(LLVM_STRIP) -g $@

Expand Down
2 changes: 1 addition & 1 deletion libbpf-tools/biopattern.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct {
SEC("tracepoint/block/block_rq_complete")
int handle__block_rq_complete(struct trace_event_raw_block_rq_complete *ctx)
{
sector_t *last_sectorp, sector = ctx->sector;
sector_t sector = ctx->sector;
struct counter *counterp, zero = {};
u32 nr_sector = ctx->nr_sector;
dev_t dev = ctx->dev;
Expand Down
2 changes: 1 addition & 1 deletion libbpf-tools/biosnoop.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ SEC("tp_btf/block_rq_complete")
int BPF_PROG(block_rq_complete, struct request *rq, int error,
unsigned int nr_bytes)
{
u64 slot, ts = bpf_ktime_get_ns();
u64 ts = bpf_ktime_get_ns();
struct piddata *piddatap;
struct event event = {};
struct stage *stagep;
Expand Down
1 change: 0 additions & 1 deletion libbpf-tools/biostacks.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ int BPF_PROG(blk_account_io_done, struct request *rq)
{
u64 slot, ts = bpf_ktime_get_ns();
struct internal_rqinfo *i_rqinfop;
struct rqinfo *rqinfop;
struct hist *histp;
s64 delta;

Expand Down
2 changes: 0 additions & 2 deletions libbpf-tools/filelife.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ int BPF_KPROBE(vfs_unlink, struct inode *dir, struct dentry *dentry)
const u8 *qs_name_ptr;
u32 tgid = id >> 32;
u64 *tsp, delta_ns;
u32 qs_len;

tsp = bpf_map_lookup_elem(&start, &dentry);
if (!tsp)
Expand All @@ -67,7 +66,6 @@ int BPF_KPROBE(vfs_unlink, struct inode *dir, struct dentry *dentry)
bpf_map_delete_elem(&start, &dentry);

qs_name_ptr = BPF_CORE_READ(dentry, d_name.name);
qs_len = BPF_CORE_READ(dentry, d_name.len);
bpf_probe_read_kernel_str(&event.file, sizeof(event.file), qs_name_ptr);
bpf_get_current_comm(&event.task, sizeof(event.task));
event.delta_ns = delta_ns;
Expand Down
4 changes: 1 addition & 3 deletions libbpf-tools/fsdist.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ static int probe_entry()

static int probe_return(enum fs_file_op op)
{
__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
__u32 tid = (__u32)pid_tgid;
__u32 tid = (__u32)bpf_get_current_pid_tgid();
__u64 ts = bpf_ktime_get_ns();
__u64 *tsp, slot;
__s64 delta;
Expand Down
4 changes: 1 addition & 3 deletions libbpf-tools/gethostlatency.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ static int probe_entry(struct pt_regs *ctx)

static int probe_return(struct pt_regs *ctx)
{
__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = pid_tgid >> 32;
__u32 tid = (__u32)pid_tgid;
__u32 tid = (__u32)bpf_get_current_pid_tgid();
struct event *eventp;

eventp = bpf_map_lookup_elem(&starts, &tid);
Expand Down
12 changes: 3 additions & 9 deletions libbpf-tools/ksnoop.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,14 @@ static void output_stashed_traces(struct pt_regs *ctx,
{
struct func_stack *func_stack;
struct trace *trace = NULL;
__u8 stack_depth, i;
__u8 i;
__u64 task = 0;

task = bpf_get_current_task();
func_stack = bpf_map_lookup_elem(&ksnoop_func_stack, &task);
if (!func_stack)
return;

stack_depth = func_stack->stack_depth;

if (entry) {
/* iterate from bottom to top of stack, outputting stashed
* data we find. This corresponds to the set of functions
Expand Down Expand Up @@ -294,9 +292,7 @@ static int ksnoop(struct pt_regs *ctx, bool entry)
{
void *data_ptr = NULL;
struct trace *trace;
struct func *func;
__u16 trace_len;
__u64 data, pg;
__u64 data;
__u32 currpid;
int ret;
__u8 i;
Expand All @@ -305,8 +301,6 @@ static int ksnoop(struct pt_regs *ctx, bool entry)
if (!trace)
return 0;

func = &trace->func;

/* make sure we want events from this pid */
currpid = bpf_get_current_pid_tgid();
if (trace->filter_pid && trace->filter_pid != currpid)
Expand Down Expand Up @@ -399,7 +393,7 @@ static int ksnoop(struct pt_regs *ctx, bool entry)
if (!ok) {
clear_trace(trace);
return 0;
}
}
}

if (currtrace->flags & (KSNOOP_F_PTR | KSNOOP_F_MEMBER))
Expand Down
1 change: 0 additions & 1 deletion libbpf-tools/syscount.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ int sys_enter(struct trace_event_raw_sys_enter *args)
SEC("tracepoint/raw_syscalls/sys_exit")
int sys_exit(struct trace_event_raw_sys_exit *args)
{
struct task_struct *current;
u64 id = bpf_get_current_pid_tgid();
static const struct data_t zero;
pid_t pid = id >> 32;
Expand Down

0 comments on commit d1afbf6

Please sign in to comment.