Messages in this thread | | | Subject | Re: [PATCH mm] kfence: fix printk format for ptrdiff_t | From | Christophe Leroy <> | Date | Thu, 18 Mar 2021 10:38:43 +0100 |
| |
Le 18/03/2021 à 10:14, David Laight a écrit : > From: Christophe Leroy >> Sent: 17 March 2021 17:35 >> >> Le 17/03/2021 à 13:51, David Laight a écrit : >>> From: Christophe Leroy >>>> Sent: 16 March 2021 15:41 >>> ... >>>>>> include/linux/types.h:typedef __kernel_ptrdiff_t ptrdiff_t; >>>>>> >>>>>> And get: >>>>>> >>>>>> CC mm/kfence/report.o >>>>>> In file included from ./include/linux/printk.h:7, >>>>>> from ./include/linux/kernel.h:16, >>>>>> from mm/kfence/report.c:10: >>>>>> mm/kfence/report.c: In function 'kfence_report_error': >>>>>> ./include/linux/kern_levels.h:5:18: warning: format '%td' expects argument >>>>>> of type 'ptrdiff_t', but argument 6 has type 'long int' [-Wformat=] >>>>> >>>>> This is declared as >>>>> const ptrdiff_t object_index = meta ? meta - kfence_metadata : -1; >>>>> so maybe something with that goes wrong? What happens if you delete the >>>>> (useless) "const" here? >>> >>> The obvious thing to try is changing it to 'int'. >>> That will break 64bit builds, but if it fixes the 32bit one >>> it will tell you what type gcc is expecting. >>> >> >> Yes, if defining 'object_index' as int, gcc is happy. >> If removing the powerpc re-definition of ptrdiff_t typedef in >> https://elixir.bootlin.com/linux/v5.12-rc3/source/arch/powerpc/include/uapi/asm/posix_types.h , it >> works great as well. >> >> So seems like gcc doesn't take into account the typedef behind ptrdiff_t, it just expects it to be >> int on 32 bits ? > > gcc never cares how ptrdiff_t (or any of the related types) is defined > it requires int or long for the format depending on the architecture. > The error message will say ptrdiff_t or size_t (etc) - but that is just > in the error message. > > So the ppc32 uapi definition of __kernel_ptrdiff_t is wrong. > However it is probably set in stone. >
Yes it seems to be wrong. It was changed by commit d27dfd3887 ("Import pre2.0.8"), so that's long time ago. Before that it was an 'int' for ppc32.
gcc provides ptrdiff_t in stddef.h via __PTRDIFF_TYPE__ gcc defined __PTRDIFF_TYPE__ as 'int' at build time.
Should we fix it in arch/powerpc/include/uapi/asm/posix_types.h ? Anyway 'long' and 'int' makes no functionnal difference on 32 bits so there should be no impact for users if any.
Christophe
| |