libbpf: Fix compilation errors on ppc64le for btf dump typed data
authorAlan Maguire <alan.maguire@oracle.com>
Fri, 16 Jul 2021 22:46:56 +0000 (23:46 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Sat, 17 Jul 2021 00:25:57 +0000 (17:25 -0700)
__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 <andrii@kernel.org>
Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/1626475617-25984-3-git-send-email-alan.maguire@oracle.com
tools/lib/bpf/btf_dump.c

index bf5bb4b127edc91b0357dffba4d3dac0c4e47ee5..aa695ab9b8265c787f1aaab4e6171c1b8f348c42 100644 (file)
@@ -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;
        }