Skip to content

Commit

Permalink
libbpf: Fix compilation errors on ppc64le for btf dump typed data
Browse files Browse the repository at this point in the history
__s64 can be defined as either long or long long, depending on the
architecture. On ppc64le it's defined as long, giving this error:

 In file included from btf_dump.c:22:
btf_dump.c: In function 'btf_dump_type_data_check_overflow':
libbpf_internal.h:111:22: error: format '%lld' expects argument of
type 'long long int', but argument 3 has type '__s64' {aka 'long int'}
[-Werror=format=]
  111 |  libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
      |                      ^~~~~~~~~~
libbpf_internal.h:114:27: note: in expansion of macro '__pr'
  114 | #define pr_warn(fmt, ...) __pr(LIBBPF_WARN, fmt, ##__VA_ARGS__)
      |                           ^~~~
btf_dump.c:1992:3: note: in expansion of macro 'pr_warn'
 1992 |   pr_warn("unexpected size [%lld] for id [%u]\n",
      |   ^~~~~~~
btf_dump.c:1992:32: note: format string is defined here
 1992 |   pr_warn("unexpected size [%lld] for id [%u]\n",
      |                             ~~~^
      |                                |
      |                                long long int
      |                             %ld

Cast to size_t and use %zu instead.

Reported-by: Andrii Nakryiko <[email protected]>
Signed-off-by: Alan Maguire <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
alan-maguire authored and anakryiko committed Jul 17, 2021
1 parent 8d44c35 commit 04eb4df
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tools/lib/bpf/btf_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2009,8 +2009,8 @@ static int btf_dump_type_data_check_overflow(struct btf_dump *d,
__s64 size = btf__resolve_size(d->btf, id);

if (size < 0 || size >= INT_MAX) {
pr_warn("unexpected size [%lld] for id [%u]\n",
size, id);
pr_warn("unexpected size [%zu] for id [%u]\n",
(size_t)size, id);
return -EINVAL;
}

Expand Down

0 comments on commit 04eb4df

Please sign in to comment.