mirror of
https://github.com/netdata/libbpf.git
synced 2026-11-09 04:10:13 +08:00
libbpf: fix -Wformat warnings from format/argument type mismatches
Building libbpf with -Wall (as happens via bpftool's bootstrap build)
surfaces ~120 -Wformat warnings where pr_warn/pr_debug format specifiers
don't match their argument types: %d for __u32/Elf64_Word, %u for signed
ints, %zd for size_t, %ld for unsigned long, and %x/%lx/%llx applied to
signed values.
Match each specifier to its argument's type where a correctly-signed
specifier exists (%d<->%u, %ld->%lu, %zd->%zu). For hex conversions,
which have no signed form, cast the argument instead (%x->(unsigned),
%lx->(unsigned long), %llx->(unsigned long long)). No functional change.
Note, the fdinfo map_flags sscanf used %i into a __u32 *, which warns.
The kernel prints map_flags as hex ("map_flags:\t%#x\n" in
bpf_map_show_fdinfo(), unchanged since the field was added to fdinfo), so
switch the conversion to %x: it parses the 0x-prefixed value and expects
unsigned int *, matching the destination, so the warning is gone with no
cast.
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20260624204946.2901178-1-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
1 parent
8dae7836fb
commit
a205255dda
9 files changed
+89
-86
No files matched your search
+11
-11
@@ -216,7 +216,7 @@ recur:
|
||||
goto recur;
|
||||
}
|
||||
default:
|
||||
pr_warn("unexpected kind %s relocated, local [%d], target [%d]\n",
|
||||
pr_warn("unexpected kind %s relocated, local [%u], target [%u]\n",
|
||||
btf_kind_str(local_type), local_id, targ_id);
|
||||
return 0;
|
||||
}
|
||||
@@ -384,7 +384,7 @@ int bpf_core_parse_spec(const char *prog_name, const struct btf *btf,
|
||||
return sz;
|
||||
spec->bit_offset += access_idx * sz * 8;
|
||||
} else {
|
||||
pr_warn("prog '%s': relo for [%u] %s (at idx %d) captures type [%d] of unexpected kind %s\n",
|
||||
pr_warn("prog '%s': relo for [%u] %s (at idx %d) captures type [%u] of unexpected kind %s\n",
|
||||
prog_name, relo->type_id, spec_str, i, id, btf_kind_str(t));
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -725,7 +725,7 @@ static int bpf_core_calc_field_relo(const char *prog_name,
|
||||
return -EINVAL;
|
||||
*val = sz;
|
||||
} else {
|
||||
pr_warn("prog '%s': relo %d at insn #%d can't be applied to array access\n",
|
||||
pr_warn("prog '%s': relo %u at insn #%u can't be applied to array access\n",
|
||||
prog_name, relo->kind, relo->insn_off / 8);
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -747,7 +747,7 @@ static int bpf_core_calc_field_relo(const char *prog_name,
|
||||
while (bit_off + bit_sz - byte_off * 8 > byte_sz * 8) {
|
||||
if (byte_sz >= 8) {
|
||||
/* bitfield can't be read with 64-bit read */
|
||||
pr_warn("prog '%s': relo %d at insn #%d can't be satisfied for bitfield\n",
|
||||
pr_warn("prog '%s': relo %u at insn #%u can't be satisfied for bitfield\n",
|
||||
prog_name, relo->kind, relo->insn_off / 8);
|
||||
return -E2BIG;
|
||||
}
|
||||
@@ -971,7 +971,7 @@ done:
|
||||
err = 0;
|
||||
} else if (err == -EOPNOTSUPP) {
|
||||
/* EOPNOTSUPP means unknown/unsupported relocation */
|
||||
pr_warn("prog '%s': relo #%d: unrecognized CO-RE relocation %s (%d) at insn #%d\n",
|
||||
pr_warn("prog '%s': relo #%d: unrecognized CO-RE relocation %s (%u) at insn #%u\n",
|
||||
prog_name, relo_idx, core_relo_kind_str(relo->kind),
|
||||
relo->kind, relo->insn_off / 8);
|
||||
}
|
||||
@@ -1067,7 +1067,7 @@ poison:
|
||||
if (BPF_SRC(insn->code) != BPF_K)
|
||||
return -EINVAL;
|
||||
if (res->validate && insn->imm != orig_val) {
|
||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %u, exp %llu -> %llu\n",
|
||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (ALU/ALU64) value: got %d, exp %llu -> %llu\n",
|
||||
prog_name, relo_idx,
|
||||
insn_idx, insn->imm, (unsigned long long)orig_val,
|
||||
(unsigned long long)new_val);
|
||||
@@ -1083,7 +1083,7 @@ poison:
|
||||
case BPF_ST:
|
||||
case BPF_STX:
|
||||
if (res->validate && insn->off != orig_val) {
|
||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %u, exp %llu -> %llu\n",
|
||||
pr_warn("prog '%s': relo #%d: unexpected insn #%d (LDX/ST/STX) value: got %d, exp %llu -> %llu\n",
|
||||
prog_name, relo_idx, insn_idx, insn->off, (unsigned long long)orig_val,
|
||||
(unsigned long long)new_val);
|
||||
return -EINVAL;
|
||||
@@ -1159,7 +1159,7 @@ poison:
|
||||
default:
|
||||
pr_warn("prog '%s': relo #%d: trying to relocate unrecognized insn #%d, code:0x%x, src:0x%x, dst:0x%x, off:0x%x, imm:0x%x\n",
|
||||
prog_name, relo_idx, insn_idx, insn->code,
|
||||
insn->src_reg, insn->dst_reg, insn->off, insn->imm);
|
||||
(unsigned)insn->src_reg, (unsigned)insn->dst_reg, (unsigned)insn->off, (unsigned)insn->imm);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
@@ -1323,7 +1323,7 @@ int bpf_core_calc_relo_insn(const char *prog_name,
|
||||
const char *spec_str;
|
||||
|
||||
spec_str = btf__name_by_offset(local_btf, relo->access_str_off);
|
||||
pr_warn("prog '%s': relo #%d: parsing [%d] %s %s + %s failed: %d\n",
|
||||
pr_warn("prog '%s': relo #%d: parsing [%u] %s %s + %s failed: %d\n",
|
||||
prog_name, relo_idx, local_id, btf_kind_str(local_type),
|
||||
str_is_empty(local_name) ? "<anon>" : local_name,
|
||||
spec_str ?: "<?>", err);
|
||||
@@ -1346,7 +1346,7 @@ int bpf_core_calc_relo_insn(const char *prog_name,
|
||||
|
||||
/* libbpf doesn't support candidate search for anonymous types */
|
||||
if (str_is_empty(local_name)) {
|
||||
pr_warn("prog '%s': relo #%d: <%s> (%d) relocation doesn't support anonymous types\n",
|
||||
pr_warn("prog '%s': relo #%d: <%s> (%u) relocation doesn't support anonymous types\n",
|
||||
prog_name, relo_idx, core_relo_kind_str(relo->kind), relo->kind);
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
@@ -1697,7 +1697,7 @@ recur:
|
||||
goto recur;
|
||||
}
|
||||
default:
|
||||
pr_warn("unexpected kind %s relocated, local [%d], target [%d]\n",
|
||||
pr_warn("unexpected kind %s relocated, local [%u], target [%u]\n",
|
||||
btf_kind_str(local_t), local_id, targ_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user