[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAEf4BzbLj5g8PK+fTE17v4nXKDDuZMBp9g98=oaYN59d0pVeZQ@mail.gmail.com>
Date: Wed, 26 Aug 2020 21:12:09 -0700
From: Andrii Nakryiko <andrii.nakryiko@...il.com>
To: Alexei Starovoitov <alexei.starovoitov@...il.com>
Cc: Andrii Nakryiko <andriin@...com>, bpf <bpf@...r.kernel.org>,
Networking <netdev@...r.kernel.org>,
Alexei Starovoitov <ast@...com>,
Daniel Borkmann <daniel@...earbox.net>,
Kernel Team <kernel-team@...com>,
Naresh Kamboju <naresh.kamboju@...aro.org>
Subject: Re: [PATCH bpf-next] libbpf: fix compilation warnings for 64-bit
printf args
On Wed, Aug 26, 2020 at 9:08 AM Alexei Starovoitov
<alexei.starovoitov@...il.com> wrote:
>
> On Tue, Aug 25, 2020 at 08:09:21PM -0700, Andrii Nakryiko wrote:
> > Add __pu64 and __ps64 (sort of like "printf u64 and s64") for libbpf-internal
> > use only in printf-like situations to avoid compilation warnings due to
> > %lld/%llu mismatch with a __u64/__s64 due to some architecture defining the
> > latter as either `long` or `long long`. Use that on all %lld/%llu cases in
> > libbpf.c.
> >
> > Reported-by: Naresh Kamboju <naresh.kamboju@...aro.org>
> > Fixes: eacaaed784e2 ("libbpf: Implement enum value-based CO-RE relocations")
> > Fixes: 50e09460d9f8 ("libbpf: Skip well-known ELF sections when iterating ELF")
> > Signed-off-by: Andrii Nakryiko <andriin@...com>
> > ---
> > tools/lib/bpf/libbpf.c | 15 ++++++++-------
> > tools/lib/bpf/libbpf_internal.h | 11 +++++++++++
> > 2 files changed, 19 insertions(+), 7 deletions(-)
> >
[...]
> >
> > +/* These types are for casting 64-bit arguments of printf-like functions to
> > + * avoid compiler warnings on various architectures that define size_t, __u64,
> > + * uint64_t, etc as either unsigned long or unsigned long long (similarly for
> > + * signed variants). Use these typedefs only for these purposes. Alternative
> > + * is PRIu64 (and similar) macros, requiring stitching printf format strings
> > + * which are extremely ugly and should be avoided in libbpf code base. With
> > + * arguments casted to __pu64/__ps64, always use %llu/%lld in format string.
> > + */
> > +typedef unsigned long long __pu64;
> > +typedef long long __ps64;
>
> I think these extra typedefs will cause confusion. Original approach
> of open coding type casts to long long and unsigned long long is imo cleaner.
Fair enough. Sent v2 with just direct "unsigned long long" casts.
Powered by blists - more mailing lists