clinew@linux.vnet.ibm.com
2012-Sep-12 23:21 UTC
[RFC][PATCH] Btrfs-progs: Fix compiler warnings on PPC64.
From: Wade Cline <clinew@linux.vnet.ibm.com> The kernel uses unsigned long long for u64, but PPC64 uses unsigned long by default. This results in print warnings such as: print-tree.c:333: warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 4 has type ‘u64’ Defining __KERNEL__ before the file <asm/types.h>, or any file that includes this file, will let PPC64 know to use unsigned long long for u64 instead. This patch adds the defines and fixes the print warnings on PPC64. Signed-off-by: Wade Cline <clinew@linux.vnet.ibm.com> --- cmds-receive.c | 1 + cmds-scrub.c | 2 ++ convert.c | 1 + kerncompat.h | 6 ++++++ mkfs.c | 1 + 5 files changed, 11 insertions(+), 0 deletions(-) diff --git a/cmds-receive.c b/cmds-receive.c index a8be6fa..6cb51fe 100644 --- a/cmds-receive.c +++ b/cmds-receive.c @@ -20,6 +20,7 @@ #define _POSIX_C_SOURCE 200809 #define _XOPEN_SOURCE 700 #define _BSD_SOURCE +#define __KERNEL__ #include <unistd.h> #include <stdint.h> diff --git a/cmds-scrub.c b/cmds-scrub.c index 24be20f..7f6aa68 100644 --- a/cmds-scrub.c +++ b/cmds-scrub.c @@ -16,6 +16,8 @@ * Boston, MA 021110-1307, USA. */ +#define __KERNEL__ + #include <sys/ioctl.h> #include <sys/wait.h> #include <sys/stat.h> diff --git a/convert.c b/convert.c index fa7bf8c..74ffceb 100644 --- a/convert.c +++ b/convert.c @@ -18,6 +18,7 @@ #define _XOPEN_SOURCE 600 #define _GNU_SOURCE 1 +#define __KERNEL__ #ifndef __CHECKER__ #include <sys/ioctl.h> #include <sys/mount.h> diff --git a/kerncompat.h b/kerncompat.h index 46236cd..2e571b8 100644 --- a/kerncompat.h +++ b/kerncompat.h @@ -57,11 +57,17 @@ #endif #ifndef __CHECKER__ +/* + * PPC64 uses unsigned long for u64 while the kernel uses unsigned long long; + * Specifying this will let PPC64 know to use unsigned long long instead. + */ +#define __KERNEL__ #include <asm/types.h> typedef __u32 u32; typedef __u64 u64; typedef __u16 u16; typedef __u8 u8; +#undef __KERNEL__ #else typedef unsigned int u32; typedef unsigned int __u32; diff --git a/mkfs.c b/mkfs.c index dff5eb8..1c88804 100644 --- a/mkfs.c +++ b/mkfs.c @@ -18,6 +18,7 @@ #define _XOPEN_SOURCE 500 #define _GNU_SOURCE +#define __KERNEL__ #ifndef __CHECKER__ #include <sys/ioctl.h> -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2012-Sep-14 13:59 UTC
Re: [RFC][PATCH] Btrfs-progs: Fix compiler warnings on PPC64.
On Wed, Sep 12, 2012 at 04:21:56PM -0700, clinew@linux.vnet.ibm.com wrote:> Defining __KERNEL__ before the file <asm/types.h>, or any file that > includes this file, will let PPC64 know to use unsigned long long > for u64 instead. This patch adds the defines and fixes the print > warnings on PPC64.Defining __KERNEL__ in random places does not seem clean, I understand it in kerncompat.h which should transparently fix any compatibility issues, and the files like cmd-receive.c should include this instead of the explicit defines. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Wade Cline
2012-Sep-14 17:13 UTC
Re: [RFC][PATCH] Btrfs-progs: Fix compiler warnings on PPC64.
On 09/14/2012 06:59 AM, David Sterba wrote:> On Wed, Sep 12, 2012 at 04:21:56PM -0700, clinew@linux.vnet.ibm.com wrote: >> Defining __KERNEL__ before the file<asm/types.h>, or any file that >> includes this file, will let PPC64 know to use unsigned long long >> for u64 instead. This patch adds the defines and fixes the print >> warnings on PPC64. > Defining __KERNEL__ in random places does not seem clean, I understand > it in kerncompat.h which should transparently fix any compatibility > issues, and the files like cmd-receive.c should include this instead of > the explicit defines. > > > david >I agree that defining __KERNEL__ does not seem clean, but the problem is that the various include files sort of "race" to include the type definition. For example, in cmds-scrub.c: #include <sys/ioctl.h> #include <sys/wait.h> #define __KERNEL__ #include <sys/stat.h> will generate compiler warnings while: #include <sys/ioctl.h> #define __KERNEL__ #include <sys/wait.h> #include <sys/stat.h> will not. By the time kerncompat.h is included, u64 is almost always defined to the non-compatible value. So either kerncompat.h needs to be defined as the -first- included header file, or __KERNEL__ needs to be defined. ...it would also be possible to do something like: #define __KERNEL__ #include <sys/wait.h> #undef __KERNEL__ but that seems a bit too hacky. I''m open to any other ideas, though. Thank you, Wade -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
David Sterba
2012-Sep-20 14:15 UTC
Re: [RFC][PATCH] Btrfs-progs: Fix compiler warnings on PPC64.
On Fri, Sep 14, 2012 at 10:13:13AM -0700, Wade Cline wrote:> By the time kerncompat.h is included, u64 is almost always defined to > the non-compatible value. So either kerncompat.h needs to be defined as the > -first-This makes most sense to me. Although the include files should go in the order 1. system 2. local, and kernecompat.h is local, it''s special in it''s own way and i don''t see any problem with that. david -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Reasonably Related Threads
- [PATCH] btrfs-progs: fix duplicate __[su]* typedefs on ppc64
- [PATCH] btrfs-progs: Check mount status of multidevice filesystems
- [RFC] btrfs-progs: fix sparse checking and warnings
- [PATCH] Btrfs-progs: add a free space cache checker to fsck
- [PATCH] btrfs-progs: fix 32bit int/pointer cast warnings