xfsprogs: sparse support
PATCH 1/1 xfsprogs: sparse support
Allow to compile xfsprogs using the sparse gcc wrapper cgcc and check for endianess warnings. First this patch adds explicit --tag=CC arguments to the libtool invocations because it can't auto-detect cgcc as a C compiler. Second add endianess annotations to the __be* types and the macros operating on them. And last but not least add a new doc/sparse.txt describing how to invoke sparse on xfsprogs.
Signed-off-by Christoph Hellwig <[email protected]>
include/platform_defs.h.in +11 -3
@@ -45,9 +45,17 @@ typedef unsigned long long int __u64; typedef signed long long int __s64; #endif -typedef __u16 __be16; -typedef __u32 __be32; -typedef __u64 __be64; +#ifdef __CHECKER__ +#define __bitwise __attribute__((bitwise)) +#define __force __attribute__((force)) +#else +#define __bitwise +#define __force +#endif + +typedef __u16 __bitwise __be16; +typedef __u32 __bitwise __be32; +typedef __u64 __bitwise __be64; #if defined(__linux__) #include <xfs/linux.h>
include/xfs_arch.h +12 -12
@@ -41,19 +41,19 @@#endif #ifdef XFS_NATIVE_HOST -#define cpu_to_be16 (val) ((__be16)(val)) -#define cpu_to_be32 (val) ((__be32)(val)) -#define cpu_to_be64 (val) ((__be64)(val)) -#define be16_to_cpu (val) ((__uint16_t)(val)) -#define be32_to_cpu (val) ((__uint32_t)(val)) -#define be64_to_cpu (val) ((__uint64_t)(val)) +#define cpu_to_be16 (val) ((__force __be16)(__u16)(val)) +#define cpu_to_be32 (val) ((__force __be32)(__u32)(val)) +#define cpu_to_be64 (val) ((__force __be64)(__u64)(val)) +#define be16_to_cpu (val) ((__force __u16)(__be16)(val)) +#define be32_to_cpu (val) ((__force __u32)(__be32)(val)) +#define be64_to_cpu (val) ((__force __u64)(__be64)(val))#else -#define cpu_to_be16 (val) (__swab16((__uint16_t)(val))) -#define cpu_to_be32 (val) (__swab32((__uint32_t)(val))) -#define cpu_to_be64 (val) (__swab64((__uint64_t)(val))) -#define be16_to_cpu (val) (__swab16((__be16)(val))) -#define be32_to_cpu (val) (__swab32((__be32)(val))) -#define be64_to_cpu (val) (__swab64((__be64)(val))) +#define cpu_to_be16 (val) ((__force __be16)__swab16((__u16)(val))) +#define cpu_to_be32 (val) ((__force __be32)__swab32((__u32)(val))) +#define cpu_to_be64 (val) ((__force __be64)__swab64((__u64)(val))) +#define be16_to_cpu (val) (__swab16((__force __u16)(__be16)(val))) +#define be32_to_cpu (val) (__swab32((__force __u32)(__be32)(val))) +#define be64_to_cpu (val) (__swab64((__force __u64)(__be64)(val)))#endif #endif /* __KERNEL__ */
include/buildmacros +2 -2
@@ -42,10 +42,10 @@ LIBNAME = $(basename $(LTLIBRARY)) LTOBJECTS = $(OBJECTS:.o=.lo) LTVERSION = $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -LTLINK = $(LIBTOOL) --mode=link $(CC) +LTLINK = $(LIBTOOL) --tag=CC --mode=link $(CC) LTEXEC = $(LIBTOOL) --mode=execute LTINSTALL = $(LIBTOOL) --mode=install $(INSTALL) -LTCOMPILE = $(LIBTOOL) --mode=compile $(CCF) +LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CCF) ifeq ($(ENABLE_SHARED),yes) LTLDFLAGS += -rpath $(PKG_LIB_DIR)
doc/sparse.txt new file +24 -0
@@ -0,0 +1,24 @@ +This document describes how to use the sparse source code checking tool +to check the source code of the open source XFS commands and utilites +("xfsprogs"). + +First you need to install sparse, either from your distribution or from +source as provided at http://www.kernel.org/pub/software/devel/sparse/. + +To simply build the xfsprogs source code while checking the source using +sparse just set the compiler to cgcc, which is a wrapper that calls both +sparse and gcc using: + + CC=cgcc ./configure + +Now that default warnings from sparse are a little bit verbose checking +for various not that important things and also complaining about the +glibc system headers. It does however not check for bitwise annotation +which are very important for xfsprogs to verify the endianess handling +of the on-disk structures is correct. To get a more reasonable set +of warnings build xfsprogs using: + + LCFLAGS="-Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl" make + +You are of course free to experiment with the warnings flags documented +in the sparse manpage to check xfsprogs for other issues.