linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Zach Brown <zab@redhat.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 01/15] btrfs-progs: get C=1 sparse checking working again
Date: Wed, 14 Aug 2013 16:16:31 -0700	[thread overview]
Message-ID: <1376522205-16992-2-git-send-email-zab@redhat.com> (raw)
In-Reply-To: <1376522205-16992-1-git-send-email-zab@redhat.com>

There were a few problems that were breaking sparse checking:

- We were defining CHECK_ENDIAN late in the environment, after
  linux/fs.h has been included which defines __force and __bitwise in
  confusing ways that conflict with ours.  Define it up with __CHECKER__
  so that linux/fs.h and our copy are acting on the same input.

- We had manually set a few of gcc's internal defines to give to sparse.
  It's easier to just ask gcc for all the defines it sets and hand those
  to sparse.

- We weren't passing the same *FLAGS to sparse as we were to CC.

- glibc has so many errors with FORTIFY turned on that sparse gives up
  and doesn't show us any errors from our code.  It's a questionable
  hack to always turn on FORTIFY ourselves, so we'll just not do that
  when building with sparse.

And add a nice '[SP]' quiet output line for sparse checks.

Signed-off-by: Zach Brown <zab@redhat.com>
---
 Makefile     | 28 +++++++++++++++++++++-------
 kerncompat.h |  1 -
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/Makefile b/Makefile
index fa8b34f..57cf3c8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 CC = gcc
 LN = ln
 AR = ar
-AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DBTRFS_FLAT_INCLUDES -fPIC
+AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -DBTRFS_FLAT_INCLUDES -fPIC
 CFLAGS = -g -O1
 objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \
 	  root-tree.o dir-item.o file-item.o inode-item.o inode-map.o \
@@ -17,9 +17,6 @@ libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
 	       crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
 	       extent_io.h ioctl.h ctree.h btrfsck.h
 
-CHECKFLAGS= -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \
-	    -Wuninitialized -Wshadow -Wundef
-
 INSTALL = install
 prefix ?= /usr/local
 bindir = $(prefix)/bin
@@ -70,17 +67,34 @@ lib_links = libbtrfs.so.0 libbtrfs.so
 headers = $(libbtrfs_headers)
 
 # make C=1 to enable sparse
+check_defs := .cc-defines.h 
 ifdef C
-	check = sparse $(CHECKFLAGS)
+	#
+	# We're trying to use sparse against glibc headers which go wild
+	# trying to use internal compiler macros to test features.  We
+	# copy gcc's and give them to sparse.  But not __SIZE_TYPE__
+	# 'cause sparse defines that one.
+	#
+	dummy := $(shell $(CC) -dM -E -x c - < /dev/null | \
+			grep -v __SIZE_TYPE__ > $(check_defs))
+	check = sparse -include $(check_defs) -D__CHECKER__ \
+		-D__CHECK_ENDIAN__ -Wbitwise -Wuninitialized -Wshadow -Wundef
+	check_echo = echo
+	# don't use FORTIFY with sparse because glibc with FORTIFY can
+	# generate so many sparse errors that sparse stops parsing,
+	# which masks real errors that we want to see.
 else
 	check = true
+	check_echo = true
+	AM_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2
 endif
 
 %.o.d: %.c
 	$(Q)$(CC) -MM -MG -MF $@ -MT $(@:.o.d=.o) -MT $(@:.o.d=.static.o) -MT $@ $(AM_CFLAGS) $(CFLAGS) $<
 
 .c.o:
-	$(Q)$(check) $<
+	@$(check_echo) "    [SP]     $@"
+	$(Q)$(check) $(AM_CFLAGS) $(CFLAGS) $<
 	@echo "    [CC]     $@"
 	$(Q)$(CC) $(AM_CFLAGS) $(CFLAGS) -c $<
 
@@ -189,7 +203,7 @@ clean :
 	$(Q)rm -f $(progs) cscope.out *.o *.o.d btrfs-convert btrfs-image btrfs-select-super \
 	      btrfs-zero-log btrfstune dir-test ioctl-test quick-test send-test btrfsck \
 	      btrfs.static mkfs.btrfs.static btrfs-calc-size \
-	      version.h \
+	      version.h $(check_defs)\
 	      $(libs) $(lib_links)
 	$(Q)$(MAKE) $(MAKEOPTS) -C man $@
 
diff --git a/kerncompat.h b/kerncompat.h
index ebb54b1..4d78288 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -241,7 +241,6 @@ static inline long IS_ERR(const void *ptr)
         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
 	        (type *)( (char *)__mptr - offsetof(type,member) );})
 #ifdef __CHECKER__
-#define __CHECK_ENDIAN__
 #define __bitwise __bitwise__
 #else
 #define __bitwise
-- 
1.7.11.7


  reply	other threads:[~2013-08-14 23:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-14 23:16 [RFC] btrfs-progs: fix sparse checking and warnings Zach Brown
2013-08-14 23:16 ` Zach Brown [this message]
2013-08-30 16:08   ` [PATCH 01/15] btrfs-progs: get C=1 sparse checking working again David Sterba
2013-08-30 21:03     ` Zach Brown
2013-08-30 21:27       ` David Sterba
2013-08-14 23:16 ` [PATCH 02/15] btrfs-progs: remove __CHECKER__ from main code Zach Brown
2013-08-14 23:16 ` [PATCH 03/15] btrfs-progs: add ULL to u64 constant Zach Brown
2013-08-14 23:16 ` [PATCH 04/15] btrfs-progs: fix shadow symbols Zach Brown
2013-08-14 23:16 ` [PATCH 05/15] btrfs-progs: remove variable length stack arrays Zach Brown
2013-08-14 23:16 ` [PATCH 06/15] btrfs-print: define void function args Zach Brown
2013-08-14 23:16 ` [PATCH 07/15] btrfs-progs: fix endian bugs in chunk rebuilding Zach Brown
2013-08-30 16:16   ` David Sterba
2013-08-14 23:16 ` [PATCH 08/15] btrfs-progs: fix extent key endian bug in repair Zach Brown
2013-08-14 23:16 ` [PATCH 09/15] btrfs-progs: fix in-place byte swapping Zach Brown
2013-08-14 23:16 ` [PATCH 10/15] btrfs-progs: fix qgroup realloc inheritance Zach Brown
2013-08-18  8:05   ` Arne Jansen
2013-08-14 23:16 ` [PATCH 11/15] btrfs-progs: make many private symbols static Zach Brown
2013-08-14 23:16 ` [PATCH 12/15] btrfs-progs: fix unaligned compat endian warnings Zach Brown
2013-08-14 23:16 ` [PATCH 13/15] btrfs-progs: don't use <linux/fs.h> Zach Brown
2013-08-14 23:16 ` [PATCH 14/15] btrfs-progs: give raid6.c its exported prototypes Zach Brown
2013-08-14 23:16 ` [PATCH 15/15] btrfs-progs: use NULL instead of 0 Zach Brown
2013-08-30 16:25   ` David Sterba
2013-08-30 21:04     ` Zach Brown
2013-08-30 16:31 ` [RFC] btrfs-progs: fix sparse checking and warnings David Sterba

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1376522205-16992-2-git-send-email-zab@redhat.com \
    --to=zab@redhat.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).