Skip to content

Commit 679152d

Browse files
anakryikoAlexei Starovoitov
authored andcommitted
libbpf: Fix printf compilation warnings on ppc64le arch
On ppc64le __u64 and __s64 are defined as long int and unsigned long int, respectively. This causes compiler to emit warning when %lld/%llu are used to printf 64-bit numbers. Fix this by casting to size_t/ssize_t with %zu and %zd format specifiers, respectively. v1->v2: - use size_t/ssize_t instead of custom typedefs (Martin). Fixes: 1f8e2bc ("libbpf: Refactor relocation handling") Fixes: abd29c9 ("libbpf: allow specifying map definitions using BTF") Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20191212171918.638010-1-andriin@fb.com
1 parent 81c2204 commit 679152d

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,15 +1242,15 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
12421242
}
12431243
sz = btf__resolve_size(obj->btf, t->type);
12441244
if (sz < 0) {
1245-
pr_warn("map '%s': can't determine key size for type [%u]: %lld.\n",
1246-
map_name, t->type, sz);
1245+
pr_warn("map '%s': can't determine key size for type [%u]: %zd.\n",
1246+
map_name, t->type, (ssize_t)sz);
12471247
return sz;
12481248
}
1249-
pr_debug("map '%s': found key [%u], sz = %lld.\n",
1250-
map_name, t->type, sz);
1249+
pr_debug("map '%s': found key [%u], sz = %zd.\n",
1250+
map_name, t->type, (ssize_t)sz);
12511251
if (map->def.key_size && map->def.key_size != sz) {
1252-
pr_warn("map '%s': conflicting key size %u != %lld.\n",
1253-
map_name, map->def.key_size, sz);
1252+
pr_warn("map '%s': conflicting key size %u != %zd.\n",
1253+
map_name, map->def.key_size, (ssize_t)sz);
12541254
return -EINVAL;
12551255
}
12561256
map->def.key_size = sz;
@@ -1285,15 +1285,15 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj,
12851285
}
12861286
sz = btf__resolve_size(obj->btf, t->type);
12871287
if (sz < 0) {
1288-
pr_warn("map '%s': can't determine value size for type [%u]: %lld.\n",
1289-
map_name, t->type, sz);
1288+
pr_warn("map '%s': can't determine value size for type [%u]: %zd.\n",
1289+
map_name, t->type, (ssize_t)sz);
12901290
return sz;
12911291
}
1292-
pr_debug("map '%s': found value [%u], sz = %lld.\n",
1293-
map_name, t->type, sz);
1292+
pr_debug("map '%s': found value [%u], sz = %zd.\n",
1293+
map_name, t->type, (ssize_t)sz);
12941294
if (map->def.value_size && map->def.value_size != sz) {
1295-
pr_warn("map '%s': conflicting value size %u != %lld.\n",
1296-
map_name, map->def.value_size, sz);
1295+
pr_warn("map '%s': conflicting value size %u != %zd.\n",
1296+
map_name, map->def.value_size, (ssize_t)sz);
12971297
return -EINVAL;
12981298
}
12991299
map->def.value_size = sz;
@@ -1817,7 +1817,8 @@ static int bpf_program__record_reloc(struct bpf_program *prog,
18171817
return -LIBBPF_ERRNO__RELOC;
18181818
}
18191819
if (sym->st_value % 8) {
1820-
pr_warn("bad call relo offset: %llu\n", (__u64)sym->st_value);
1820+
pr_warn("bad call relo offset: %zu\n",
1821+
(size_t)sym->st_value);
18211822
return -LIBBPF_ERRNO__RELOC;
18221823
}
18231824
reloc_desc->type = RELO_CALL;
@@ -1859,8 +1860,8 @@ static int bpf_program__record_reloc(struct bpf_program *prog,
18591860
break;
18601861
}
18611862
if (map_idx >= nr_maps) {
1862-
pr_warn("map relo failed to find map for sec %u, off %llu\n",
1863-
shdr_idx, (__u64)sym->st_value);
1863+
pr_warn("map relo failed to find map for sec %u, off %zu\n",
1864+
shdr_idx, (size_t)sym->st_value);
18641865
return -LIBBPF_ERRNO__RELOC;
18651866
}
18661867
reloc_desc->type = RELO_LD64;
@@ -1941,9 +1942,9 @@ bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr,
19411942
name = elf_strptr(obj->efile.elf, obj->efile.strtabidx,
19421943
sym.st_name) ? : "<?>";
19431944

1944-
pr_debug("relo for shdr %u, symb %llu, value %llu, type %d, bind %d, name %d (\'%s\'), insn %u\n",
1945-
(__u32)sym.st_shndx, (__u64)GELF_R_SYM(rel.r_info),
1946-
(__u64)sym.st_value, GELF_ST_TYPE(sym.st_info),
1945+
pr_debug("relo for shdr %u, symb %zu, value %zu, type %d, bind %d, name %d (\'%s\'), insn %u\n",
1946+
(__u32)sym.st_shndx, (size_t)GELF_R_SYM(rel.r_info),
1947+
(size_t)sym.st_value, GELF_ST_TYPE(sym.st_info),
19471948
GELF_ST_BIND(sym.st_info), sym.st_name, name,
19481949
insn_idx);
19491950

0 commit comments

Comments
 (0)