[PATCH 2/3] defs: define PRI__[uxs]64 to print __[su]64 values

Jeff Mahoney jeffm at suse.com
Thu Mar 31 02:28:35 UTC 2016


On 3/30/16 9:55 PM, Dmitry V. Levin wrote:
> On Wed, Mar 30, 2016 at 09:19:26PM -0400, Jeff Mahoney wrote:
> [...]
>> +/*
>> + * The kernel used to define 64-bit types on 64-bit systems on a per-arch
>> + * basis.  Some architectures would use unsigned long and others would u=
> se
>> + * unsigned long long.  These types were exported as part of the
>> + * kernel-userspace ABI and now must be maintained forever.  This matches
>> + * what the kernel exports for each architecture so we don't need to cast
>> + * every printing of __u64 or __s64 to stdint types.
>> + */
>> +#if BITS_PER_LONG =3D=3D 32
>> +#define PRI__64 "ll"
> 
> How portable is BITS_PER_LONG?

Both asm/int-l64.h and asm/int-ll64.h include asm/bitsperlong.h, so if
__u64 is defined, so will BITS_PER_LONG.

>> +#elif defined(__mips__) || defined(__powerpc__) || defined(__alpha__) ||=
>  defined(__ia64__)
>> +#define PRI__64 "l"
> 
> Is there any simple way to verify this?

I dug it out of the Linux kernel source.  The __[us]* types are defined
in include/uapi/asm-generic/int-ll64.h or
include/uapi/asm-generic/int-l64.h, depending on architecture.

With the kernel source, the following will demonstrate which arches use
long vs long long.  If it appears in both of the first two lists, that
architecture probably honors __SANE_USERSPACE_TYPES__ and/or covers both
32- and 64-bit CPUs.

$ grep /int-l64.h arch/*/include/{uapi/,}asm/types.h
arch/alpha/include/uapi/asm/types.h:#include <asm-generic/int-l64.h>
arch/ia64/include/uapi/asm/types.h:#include <asm-generic/int-l64.h>
arch/mips/include/uapi/asm/types.h:#  include <asm-generic/int-l64.h>
arch/powerpc/include/uapi/asm/types.h:# include <asm-generic/int-l64.h>

$ grep /int-ll64.h arch/*/include/{uapi/,}asm/types.h
arch/avr32/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/frv/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/m32r/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/mips/include/uapi/asm/types.h:#  include <asm-generic/int-ll64.h>
arch/mn10300/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/parisc/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/powerpc/include/uapi/asm/types.h:# include <asm-generic/int-ll64.h>
arch/s390/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/xtensa/include/uapi/asm/types.h:#include <asm-generic/int-ll64.h>
arch/alpha/include/asm/types.h:#include <asm-generic/int-ll64.h>
arch/arm/include/asm/types.h:#include <asm-generic/int-ll64.h>
arch/ia64/include/asm/types.h:#include <asm-generic/int-ll64.h>
arch/mips/include/asm/types.h:#include <asm-generic/int-ll64.h>

<asm-generic/types.h> includes int-ll64.h:
$ grep 'asm-generic/types.h' arch/*/include/{uapi/,}asm/types.h
arch/score/include/uapi/asm/types.h:#include <asm-generic/types.h>
arch/sh/include/uapi/asm/types.h:#include <asm-generic/types.h>
arch/x86/include/uapi/asm/types.h:#include <asm-generic/types.h>

Hopefully that's simple enough.  Since the only reason they're not ALL
long long is for compatibility, it's unlikely to change.

-Jeff

-- 
Jeff Mahoney
SUSE Labs

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 827 bytes
Desc: OpenPGP digital signature
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20160330/ff567732/attachment.bin>


More information about the Strace-devel mailing list