libbpf: fix -Wformat warnings from format/argument type mismatches
Andrii Nakryiko
maintainerPATCH 1/1 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.
--- tools/lib/bpf/btf.c | 10 ++--- tools/lib/bpf/btf_dump.c | 4 +- tools/lib/bpf/btf_relocate.c | 8 ++-- tools/lib/bpf/elf.c | 2 +- tools/lib/bpf/gen_loader.c | 16 ++++---- tools/lib/bpf/libbpf.c | 78 ++++++++++++++++++------------------ tools/lib/bpf/nlattr.c | 2 +- tools/lib/bpf/relo_core.c | 22 +++++----- tools/lib/bpf/usdt.c | 33 ++++++++------- 9 files changed, 89 insertions(+), 86 deletions(-)
tools/lib/bpf/btf.c +5 -5
@@ -589,7 +589,7 @@ static int btf_parse_type_sec(struct btf *btf)if (type_size <0 )return type_size;if (next_type + type_size > end_type) { -pr_warn ("BTF type [%d] is malformed\n" , btf->start_id + btf->nr_types); +pr_warn ("BTF type [%u] is malformed\n" , btf->start_id + btf->nr_types);return -EINVAL ; }
@@ -1424,7 +1424,7 @@ static int btf_find_elf_sections(Elf *elf, const char *path, struct btf_elf_secscontinue ;if (sh.sh_type !=SHT_PROGBITS ) { -pr_warn ("unexpected section type (%d) of section(%d, %s) from %s\n" , +pr_warn ("unexpected section type (%u) of section(%d, %s) from %s\n" , sh.sh_type, idx, name, path); goto err; }
@@ -4854,7 +4854,7 @@ static bool btf_dedup_identical_types(struct btf_dedup *d, __u32 id1, __u32 id2,continue ;if (!btf_dedup_identical_types (d, m1->type, m2->type, depth -1 )) {if (t1->name_off) { - pr_debug("%s '%s' size=%d vlen=%d id1[%u] id2[%u] shallow-equal but not identical for field#%d '%s'\n", + pr_debug("%s '%s' size=%u vlen=%u id1[%u] id2[%u] shallow-equal but not identical for field#%d '%s'\n", k1 == BTF_KIND_STRUCT ? "STRUCT" : "UNION", btf__name_by_offset(d->btf, t1->name_off), t1->size, btf_vlen(t1), id1, id2, i,
@@ -5104,7 +5104,7 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, eq =btf_dedup_is_equiv (d, cand_m->type, canon_m->type);if (eq <=0 ) {if (cand_type->name_off) { - pr_debug("%s '%s' size=%d vlen=%d cand_id[%u] canon_id[%u] shallow-equal but not equiv for field#%d '%s': %d\n", + pr_debug("%s '%s' size=%u vlen=%u cand_id[%u] canon_id[%u] shallow-equal but not equiv for field#%d '%s': %d\n", cand_kind == BTF_KIND_STRUCT ? "STRUCT" : "UNION", btf__name_by_offset(d->btf, cand_type->name_off), cand_type->size, vlen, cand_id, canon_id, i,
@@ -6069,7 +6069,7 @@ static int btf_add_distilled_types(struct btf_distill *dist) err =btf_add_type (&dist->pipe, t);break ;default : -pr_warn ("unexpected kind when adding base type '%s'[%u] of kind [%u] to distilled base BTF.\n" , +pr_warn ("unexpected kind when adding base type '%s'[%d] of kind [%d] to distilled base BTF.\n" , name, i, kind);return -EINVAL ;
tools/lib/bpf/btf_dump.c +2 -2
@@ -1776,7 +1776,7 @@ static int btf_dump_get_bitfield_value(struct btf_dump *d,/* Maximum supported bitfield size is 64 bits */ if (t->size >8 ) { -pr_warn ("unexpected bitfield size %d\n" , t->size); +pr_warn ("unexpected bitfield size %u\n" , t->size);return -EINVAL ; }
@@ -2251,7 +2251,7 @@ static int btf_dump_get_enum_value(struct btf_dump *d, *value = is_signed ? *(__s8 *)data : *(__u8 *)data;return 0 ;default : -pr_warn ("unexpected size %d for enum, id:[%u]\n" , t->size, id); +pr_warn ("unexpected size %u for enum, id:[%u]\n" , t->size, id);return -EINVAL ; } }
tools/lib/bpf/btf_relocate.c +4 -4
@@ -280,7 +280,7 @@ static int btf_relocate_map_distilled_base(struct btf_relocate *r)cmp_btf_name_size (&base_info, dist_info) ==0 ; dist_info++) {if (!dist_info->id || dist_info->id >= r->nr_dist_base_types) { -pr_warn ("base BTF id [%d] maps to invalid distilled base BTF id [%d]\n" , +pr_warn ("base BTF id [%u] maps to invalid distilled base BTF id [%u]\n" , id, dist_info->id); err = -EINVAL ; goto done;
@@ -368,7 +368,7 @@ static int btf_relocate_map_distilled_base(struct btf_relocate *r)continue ; dist_t =btf_type_by_id (r->dist_base_btf, id); name =btf__name_by_offset (r->dist_base_btf, dist_t->name_off); -pr_warn ("distilled base BTF type '%s' [%d] is not mapped to base BTF id\n" , +pr_warn ("distilled base BTF type '%s' [%u] is not mapped to base BTF id\n" , name, id); err = -EINVAL ;break ;
@@ -397,11 +397,11 @@ static int btf_relocate_validate_distilled_base(struct btf_relocate *r)case BTF_KIND_FWD :if (t->name_off)break ; -pr_warn ("type [%d], kind [%d] is invalid for distilled base BTF; it is anonymous\n" , +pr_warn ("type [%u], kind [%d] is invalid for distilled base BTF; it is anonymous\n" , i, kind);return -EINVAL ;default : -pr_warn ("type [%d] in distilled based BTF has unexpected kind [%d]\n" , +pr_warn ("type [%u] in distilled based BTF has unexpected kind [%d]\n" , i, kind);return -EINVAL ; }
tools/lib/bpf/elf.c +1 -1
@@ -354,7 +354,7 @@ long elf_find_func_offset(Elf *elf, const char *binary_path, const char *name)if (ret >0 ) {pr_debug ("elf: symbol address match for '%s' in '%s': 0x%lx\n" , name, binary_path, - ret); + (unsigned long )ret); }else {if (ret ==0 ) { pr_warn("elf: '%s' is 0 in symtab for '%s': %s\n", name, binary_path,
tools/lib/bpf/gen_loader.c +8 -8
@@ -384,7 +384,7 @@ int bpf_gen__finish(struct bpf_gen *gen, int nr_progs, int nr_maps)int i;if (nr_progs < gen->nr_progs || nr_maps != gen->nr_maps) { -pr_warn ("nr_progs %d/%d nr_maps %d/%d mismatch\n" , +pr_warn ("nr_progs %d/%u nr_maps %d/%u mismatch\n" , nr_progs, gen->nr_progs, nr_maps, gen->nr_maps); gen->error = -EFAULT ;return gen->error;
@@ -488,7 +488,7 @@ void bpf_gen__load_btf(struct bpf_gen *gen, const void *btf_raw_data, attr.btf_size =tgt_endian (btf_raw_size); btf_load_attr =add_data (gen, &attr, attr_size); -pr_debug ("gen: load_btf: off %d size %d, attr: off %d size %d\n" , +pr_debug ("gen: load_btf: off %d size %u, attr: off %d size %d\n" , btf_data, btf_raw_size, btf_load_attr, attr_size);/* populate union bpf_attr with user provided log details */
@@ -534,7 +534,7 @@ void bpf_gen__map_create(struct bpf_gen *gen, attr.btf_value_type_id =tgt_endian (map_attr->btf_value_type_id); map_create_attr =add_data (gen, &attr, attr_size); -pr_debug ("gen: map_create: %s idx %d type %d value_type_id %d, attr: off %d size %d\n" , +pr_debug ("gen: map_create: %s idx %d type %u value_type_id %u, attr: off %d size %d\n" , map_name, map_idx, map_type, map_attr->btf_value_type_id, map_create_attr, attr_size);
@@ -1082,7 +1082,7 @@ void bpf_gen__prog_load(struct bpf_gen *gen, license_off =add_data (gen, license,strlen (license) +1 );/* add insns to blob of bytes */ insns_off =add_data (gen, insns, insn_cnt *sizeof (struct bpf_insn )); -pr_debug ("gen: prog_load: prog_idx %d type %d insn off %d insns_cnt %zd license off %d\n" , +pr_debug ("gen: prog_load: prog_idx %d type %u insn off %d insns_cnt %zu license off %d\n" , prog_idx, prog_type, insns_off, insn_cnt, license_off);/* convert blob insns to target endianness */
@@ -1105,21 +1105,21 @@ void bpf_gen__prog_load(struct bpf_gen *gen, attr.func_info_rec_size =tgt_endian (load_attr->func_info_rec_size); attr.func_info_cnt =tgt_endian (load_attr->func_info_cnt); func_info =add_data (gen, load_attr->func_info, func_info_tot_sz); -pr_debug ("gen: prog_load: func_info: off %d cnt %d rec size %d\n" , +pr_debug ("gen: prog_load: func_info: off %d cnt %u rec size %u\n" , func_info, load_attr->func_info_cnt, load_attr->func_info_rec_size); attr.line_info_rec_size =tgt_endian (load_attr->line_info_rec_size); attr.line_info_cnt =tgt_endian (load_attr->line_info_cnt); line_info =add_data (gen, load_attr->line_info, line_info_tot_sz); -pr_debug ("gen: prog_load: line_info: off %d cnt %d rec size %d\n" , +pr_debug ("gen: prog_load: line_info: off %d cnt %u rec size %u\n" , line_info, load_attr->line_info_cnt, load_attr->line_info_rec_size); attr.core_relo_rec_size =tgt_endian ((__u32 )sizeof (struct bpf_core_relo )); attr.core_relo_cnt =tgt_endian (gen->core_relo_cnt); core_relos =add_data (gen, gen->core_relos, core_relo_tot_sz); -pr_debug ("gen: prog_load: core_relos: off %d cnt %d rec size %zd\n" , +pr_debug ("gen: prog_load: core_relos: off %d cnt %d rec size %zu\n" , core_relos, gen->core_relo_cnt,sizeof (struct bpf_core_relo ));
@@ -1234,7 +1234,7 @@ void bpf_gen__map_update_elem(struct bpf_gen *gen, int map_idx, void *pvalue, } map_update_attr =add_data (gen, &attr, attr_size); -pr_debug ("gen: map_update_elem: idx %d, value: off %d size %d, attr: off %d size %d\n" , +pr_debug ("gen: map_update_elem: idx %d, value: off %d size %u, attr: off %d size %d\n" , map_idx, value, value_size, map_update_attr, attr_size);move_blob2blob (gen,attr_field (map_update_attr, map_fd),4 ,blob_fd_array_off (gen, map_idx));
tools/lib/bpf/libbpf.c +39 -39
300 lines not on this page · raw message
tools/lib/bpf/nlattr.c +1 -1
@@ -123,7 +123,7 @@ int libbpf_nla_parse(struct nlattr *tb[], int maxtype, struct nlattr *head,if (tb[type]) {pr_warn ("Attribute of type %#x found multiple times in message, " -"previous attribute is being ignored.\n" , type); +"previous attribute is being ignored.\n" , (unsigned )type); } tb[type] = nla;
tools/lib/bpf/relo_core.c +11 -11
@@ -216,7 +216,7 @@ int __bpf_core_types_are_compat(const struct btf *local_btf, __u32 local_id, 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 @@ static int bpf_core_calc_relo(const char *prog_name, 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 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,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 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,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 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,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 @@ int __bpf_core_types_match(const struct btf *local_btf, __u32 local_id, const st 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 ; }
tools/lib/bpf/usdt.c +18 -15
@@ -327,7 +327,7 @@ static int sanity_check_usdt_elf(Elf *elf, const char *path)int endianness;if (elf_kind (elf) !=ELF_K_ELF ) { -pr_warn ("usdt: unrecognized ELF kind %d for '%s'\n" ,elf_kind (elf), path); +pr_warn ("usdt: unrecognized ELF kind %u for '%s'\n" ,elf_kind (elf), path);return -EBADF ; }
@@ -438,8 +438,9 @@ static int parse_elf_segs(Elf *elf, const char *path, struct elf_seg **segs, siz }pr_debug ("usdt: discovered PHDR #%d in '%s': vaddr 0x%lx memsz 0x%lx offset 0x%lx type 0x%lx flags 0x%lx\n" , - i, path, (long )phdr.p_vaddr, (long )phdr.p_memsz, (long )phdr.p_offset, - (long )phdr.p_type, (long )phdr.p_flags); + i, path, + (unsigned long )phdr.p_vaddr, (unsigned long )phdr.p_memsz, (unsigned long )phdr.p_offset, + (unsigned long )phdr.p_type, (unsigned long )phdr.p_flags);if (phdr.p_type !=PT_LOAD )continue ;
@@ -719,14 +720,14 @@ static int collect_usdt_targets(struct usdt_manager *man, struct elf_fd *elf_fd,if (!seg) { err = -ESRCH ;pr_warn ("usdt: failed to find ELF program segment for '%s:%s' in '%s' at IP 0x%lx\n" , - usdt_provider, usdt_name, path, usdt_abs_ip); + usdt_provider, usdt_name, path, (unsigned long )usdt_abs_ip); goto err_out; }if (!seg->is_exec) { err = -ESRCH ;pr_warn ("usdt: matched ELF binary '%s' segment [0x%lx, 0x%lx) for '%s:%s' at IP 0x%lx is not executable\n" , - path, seg->start, seg->end, usdt_provider, usdt_name, - usdt_abs_ip); + path, (unsigned long )seg->start, (unsigned long )seg->end, usdt_provider, usdt_name, + (unsigned long )usdt_abs_ip); goto err_out; }/* translate from virtual address to file offset */
@@ -766,7 +767,7 @@ static int collect_usdt_targets(struct usdt_manager *man, struct elf_fd *elf_fd,if (!seg) { err = -ESRCH ;pr_warn ("usdt: failed to find shared lib memory segment for '%s:%s' in '%s' at relative IP 0x%lx\n" , - usdt_provider, usdt_name, path, usdt_rel_ip); + usdt_provider, usdt_name, path, (unsigned long )usdt_rel_ip); goto err_out; }
@@ -775,8 +776,10 @@ static int collect_usdt_targets(struct usdt_manager *man, struct elf_fd *elf_fd,pr_debug ("usdt: probe for '%s:%s' in %s '%s': addr 0x%lx base 0x%lx (resolved abs_ip 0x%lx rel_ip 0x%lx) args '%s' in segment [0x%lx, 0x%lx) at offset 0x%lx\n" , usdt_provider, usdt_name, ehdr.e_type ==ET_EXEC ?"exec" :"lib " , path, - note.loc_addr, note.base_addr, usdt_abs_ip, usdt_rel_ip, note.args, - seg ? seg->start :0 , seg ? seg->end :0 , seg ? seg->offset :0 ); + (unsigned long )note.loc_addr, (unsigned long )note.base_addr, + (unsigned long )usdt_abs_ip, (unsigned long )usdt_rel_ip, note.args, + (unsigned long )(seg ? seg->start :0 ), (unsigned long )(seg ? seg->end :0 ), + (unsigned long )(seg ? seg->offset :0 ));/* Adjust semaphore address to be a file offset */ if (note.sema_addr) {
@@ -791,14 +794,14 @@ static int collect_usdt_targets(struct usdt_manager *man, struct elf_fd *elf_fd,if (!seg) { err = -ESRCH ;pr_warn ("usdt: failed to find ELF loadable segment with semaphore of '%s:%s' in '%s' at 0x%lx\n" , - usdt_provider, usdt_name, path, note.sema_addr); + usdt_provider, usdt_name, path, (unsigned long )note.sema_addr); goto err_out; }if (seg->is_exec) { err = -ESRCH ;pr_warn ("usdt: matched ELF binary '%s' segment [0x%lx, 0x%lx] for semaphore of '%s:%s' at 0x%lx is executable\n" , - path, seg->start, seg->end, usdt_provider, usdt_name, - note.sema_addr); + path, (unsigned long )seg->start, (unsigned long )seg->end, usdt_provider, usdt_name, + (unsigned long )note.sema_addr); goto err_out; }
@@ -806,8 +809,8 @@ static int collect_usdt_targets(struct usdt_manager *man, struct elf_fd *elf_fd,pr_debug ("usdt: sema for '%s:%s' in %s '%s': addr 0x%lx base 0x%lx (resolved 0x%lx) in segment [0x%lx, 0x%lx] at offset 0x%lx\n" , usdt_provider, usdt_name, ehdr.e_type ==ET_EXEC ?"exec" :"lib " , - path, note.sema_addr, note.base_addr, usdt_sema_off, - seg->start, seg->end, seg->offset); + path, (unsigned long )note.sema_addr, (unsigned long )note.base_addr, (unsigned long )usdt_sema_off, + (unsigned long )seg->start, (unsigned long )seg->end, (unsigned long )seg->offset); }/* Record adjusted addresses and offsets and parse USDT spec */
@@ -1117,7 +1120,7 @@ struct bpf_link *usdt_manager_attach_usdt(struct usdt_manager *man, const struct spec_id, usdt_provider, usdt_name, path); }else {pr_warn ("usdt: failed to map IP 0x%lx to spec #%d for '%s:%s' in '%s': %s\n" , - target->abs_ip, spec_id, usdt_provider, usdt_name, + (unsigned long )target->abs_ip, spec_id, usdt_provider, usdt_name, path,errstr (err)); } goto err_out;
Signature · 1 line
2.53.0-Meta
[email protected]
AI reviewThis isn't a bug, but src_reg, dst_reg, off and imm each picked up an (unsigned) cast for their %x conversions here, while insn->code, also printed with %x just above, was left as-is.
Quoted 4 lines
tools/lib/bpf/relo_core.c +0
-0
[ ... ]
tools/lib/bpf/relo_core.c int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn, · line 1162
Quoted 6 lines
tools/lib/bpf/relo_core.c +1
-1@@ -1159,7 +1159,7 @@ int bpf_core_patch_insn(const char *prog_name, struct bpf_insn *insn,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);
This isn't a bug, but src_reg, dst_reg, off and imm each picked up an (unsigned) cast for their %x conversions here, while insn->code, also printed with %x just above, was left as-is.
insn->code is a __u8 like src_reg and dst_reg, so it promotes to int and hits the same %x/int mismatch the casts address for the others. Was leaving code uncast intentional, or should it get the (unsigned) cast too for consistency within this statement?
---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md
CI run summary: https://github.com/kernel-patches/bpf/actions/runs/28211699373
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 6 lines · On Wed, 24 Jun 2026 13:49:46 -0700 you wrote:
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.
Quoted 6 lines
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.
[...]
Here is the summary with links:
- [bpf-next] libbpf: fix -Wformat warnings from format/argument type mismatches
https://git.kernel.org/bpf/bpf-next/c/df3153758ddb
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html
Quoted 18 lines · On Fri, Jun 26, 2026 at 6:30 AM <[email protected]> wrote:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Wed, 24 Jun 2026 13:49:46 -0700 you wrote:
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.
Quoted 6 lines
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] libbpf: fix -Wformat warnings from format/argument type mismatcheshttps://git.kernel.org/bpf/bpf-next/c/df3153758ddb
Quentin,
I synced these changes to libbpf's Github mirror. Can you please update bpftool mirror's libbpf reference to include this change, so that I can fix these noisy warnings for wprof? Thanks!
Quoted 6 lines
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
2026-06-30 11:32 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 26 lines · On Fri, Jun 26, 2026 at 6:30 AM <[email protected]> wrote:
Quoted 18 lines
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Wed, 24 Jun 2026 13:49:46 -0700 you wrote:
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.
Quoted 6 lines
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] libbpf: fix -Wformat warnings from format/argument type mismatcheshttps://git.kernel.org/bpf/bpf-next/c/df3153758ddb
Quoted 5 lines
Quentin,
I synced these changes to libbpf's Github mirror. Can you please update bpftool mirror's libbpf reference to include this change, so that I can fix these noisy warnings for wprof? Thanks!
Hi Andrii, I just synced it, thank you.
Quentin
Quoted 28 lines · Quentin Monnet
2026-06-30 11:32 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 26 lines · On Fri, Jun 26, 2026 at 6:30 AM <[email protected]> wrote:
Quoted 24 lines
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 6 lines · On Wed, 24 Jun 2026 13:49:46 -0700 you wrote:
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.Quoted 6 lines
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.
[...]
Here is the summary with links:
- [bpf-next] libbpf: fix -Wformat warnings from format/argument type mismatcheshttps://git.kernel.org/bpf/bpf-next/c/df3153758ddb
Quoted 9 lines
Quoted 5 lines
Quentin,
I synced these changes to libbpf's Github mirror. Can you please update bpftool mirror's libbpf reference to include this change, so that I can fix these noisy warnings for wprof? Thanks!
Hi Andrii, I just synced it, thank you.
Thanks, Quentin!
I got a bunch of new ones with latest bpftool sync, I haven't looked into it, but thought I'll mention in case it's something on bpftool's Github Makefile side:
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/btf_dump.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/hashmap.o
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/ringbuf.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/strset.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/linker.o
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/gen_loader.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/relo_core.o
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/usdt.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/zip.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/elf.o
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/features.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/btf_iter.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
CC /home/andriin/wprof/src/.output/bpftool/bootstrap/libbpf/staticobjs/btf_relocate.o
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
cc1: warning: ‘-Wformat-y2k’ ignored without ‘-Wformat’ [-Wformat-y2k]
cc1: warning: ‘-Wformat-security’ ignored without ‘-Wformat’ [-Wformat-security]
Quoted 1 line
Quentin
2026-06-30 13:15 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 36 lines · Quentin Monnet
Quoted 35 lines
2026-06-30 11:32 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 31 lines · On Fri, Jun 26, 2026 at 6:30 AM <[email protected]> wrote:
Quoted 18 lines
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Wed, 24 Jun 2026 13:49:46 -0700 you wrote:
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.
Quoted 6 lines
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] libbpf: fix -Wformat warnings from format/argument type mismatcheshttps://git.kernel.org/bpf/bpf-next/c/df3153758ddbQuentin,
I synced these changes to libbpf's Github mirror. Can you please update bpftool mirror's libbpf reference to include this change, so that I can fix these noisy warnings for wprof? Thanks!
Quoted 8 lines
Quoted 2 lines
Hi Andrii, I just synced it, thank you.
Thanks, Quentin!
I got a bunch of new ones with latest bpftool sync, I haven't looked into it, but thought I'll mention in case it's something on bpftool's Github
Makefileside:
[...]
Oh, I haven't observed these on my setup, I'll try to look into it when I can. What compiler do you use? And do you see the same when compiling from the kernel repo? The Makefiles should be rather close, in theory.
Quentin
Quoted 47 lines · Quentin Monnet
2026-06-30 13:15 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 36 lines · Quentin Monnet
Quoted 35 lines
2026-06-30 11:32 UTC-0700 ~ Andrii Nakryiko <[email protected]>
Quoted 31 lines · On Fri, Jun 26, 2026 at 6:30 AM <[email protected]> wrote:
Quoted 18 lines
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 11 lines · On Wed, 24 Jun 2026 13:49:46 -0700 you wrote:
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.
Quoted 6 lines
Quoted 1 line
[...]
Here is the summary with links:
- [bpf-next] libbpf: fix -Wformat warnings from format/argument type mismatcheshttps://git.kernel.org/bpf/bpf-next/c/df3153758ddbQuentin,
I synced these changes to libbpf's Github mirror. Can you please update bpftool mirror's libbpf reference to include this change, so that I can fix these noisy warnings for wprof? Thanks!
Quoted 8 lines
Quoted 2 lines
Hi Andrii, I just synced it, thank you.
Thanks, Quentin!
I got a bunch of new ones with latest bpftool sync, I haven't looked into it, but thought I'll mention in case it's something on bpftool's Github
Makefileside:
Quoted 6 lines
[...]
Oh, I haven't observed these on my setup, I'll try to look into it when I can. What compiler do you use? And do you see the same when compiling from the kernel repo? The Makefiles should be rather close, in theory.
Just sent a patch, bpftool's in-kernel Makefile needs a bit of adjustment for boostrap version of bpftool. There is a note why we don't see it in kernel build of bpftool (re-added -Wall masks this), but I confirmed that with github libbpf Makefile and wprof setup the issue is gone. Please take a look.
Quoted 1 line
Quentin