On Wed, Aug 26, 2020 at 9:08 AM Alexei Starovoitov <alexei.starovoitov@xxxxxxxxx> 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@xxxxxxxxxx> > > 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@xxxxxx> > > --- > > 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.