Skip to contentSkip to conversation

add sparse support

PATCH In review Robert Schwebel 3 participants 9 messages Apr 1, 2008 – Apr 4, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add sparse support

This patch adds static analysis support with sparse to the xenomai-solo makefiles. To enable sparse checking, use

	./configure --with-sparse[=PATH]

and run 'make sparse' afterwards. I don't have a good idea right now how to avoid this extra step; it would be much nicer if every call to $(COMPILE) could be substituted by a sparse call plus the original one, but I didn't find a good method for that yet that also works with the libtool calls.

---
 Makefile.am         |   18 +++++++++++++++++-
 base/Makefile.am    |    6 ++++++
 configure.in        |   32 ++++++++++++++++++++++++++++++++
 psos/Makefile.am    |    6 ++++++
 vxworks/Makefile.am |    5 +++++
 5 files changed, 66 insertions(+), 1 deletion(-)
base/Makefile.am +6 -0
Index: xenomai-solo/base/Makefile.am
===================================================================
@@ -36,3 +36,9 @@
 	-DTLSF_USE_LOCKS=1 -DUSE_MMAP=1 -DUSE_SBRK=1
 
 EXTRA_DIST = tlsf/README
+
+sparse:
+	@for i in $(libxenomai_la_SOURCES) $(libtlsf_la_SOURCES); do \
+		$(SPARSE) $(CHECKFLAGS) $$i; \
+	done
+
configure.in +32 -0
Index: xenomai-solo/configure.in
===================================================================
@@ -70,6 +70,38 @@
 	esac])
 AC_MSG_RESULT(${debug_symbols:-no})
 
+dnl Sparse check (default: off)
+
+sparse=
+AC_MSG_CHECKING(whether to enable sparse)
+AC_ARG_WITH(sparse,
+    AC_HELP_STRING([--with-sparse@<:@=PATH@:>@], [activate static code analysis with sparse]),
+    [case "$withval" in
+    y | yes) sparse=sparse ;;
+    n | no)  sparse= ;;
+    *) sparse=$withval
+    esac],
+    [sparse=],[]
+)
+if test -n "$sparse" ; then
+    AC_MSG_RESULT(yes)
+    AC_SUBST(SPARSE, $sparse)
+    AC_MSG_CHECKING(whether sparse=$sparse is executable)
+    if test "`$sparse 2>&1 > /dev/null; echo $?`" = "0"; then
+        AC_MSG_RESULT(yes)
+        AC_SUBST(SPARSE, $sparse)
+    else
+        AC_MSG_RESULT(no)
+        AC_MSG_ERROR($sparse is not executable)
+    fi
+else
+    AC_MSG_RESULT(no)
+    AC_SUBST(SPARSE, true)
+fi
+
+checkflags="-nostdinc -isystem \$(SYSROOT)/usr/include -isystem `$CC -print-file-name=include` -Wbitwise -Wno-transparent-union -D_GNU_SOURCE -D_XOPEN_SOURCE=500 -D_REENTRANT \$(DEFS) \$(DEFAULT_INCLUDES) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS)"
+AC_SUBST(CHECKFLAGS, $checkflags)
+
 dnl Enable assertions (default: off)
 
 AC_MSG_CHECKING(whether assertions should be enabled)
Makefile.am +17 -1
Index: xenomai-solo/Makefile.am
===================================================================
@@ -1,6 +1,15 @@
 ACLOCAL_AMFLAGS=-I config
 
-SUBDIRS = base vxworks psos include config scripts
+SRC_SUBDIRS= \
+	base \
+	vxworks \
+	psos
+
+SUBDIRS = \
+	$(SRC_SUBDIRS) \
+	include \
+	config \
+	scripts
 
 EXTRA_DIST =
 
@@ -11,3 +20,10 @@
 
 install-user:
 	$(MAKE) install
+
+sparse:
+	@for i in $(SRC_SUBDIRS); do \
+		echo; \
+		make -C $$i sparse; \
+	done
+
psos/Makefile.am +6 -0
Index: xenomai-solo/psos/Makefile.am
===================================================================
@@ -22,3 +22,9 @@
 	-I$(top_srcdir)/include
 
 EXTRA_DIST =
+
+sparse:
+	@for i in $(libpsos_la_SOURCES); do \
+		$(SPARSE) $(CHECKFLAGS) $$i; \
+	done
+
vxworks/Makefile.am +5 -0
Index: xenomai-solo/vxworks/Makefile.am
===================================================================
@@ -24,3 +24,8 @@
 	-I$(top_srcdir)/include
 
 EXTRA_DIST = testsuite
+
+sparse:
+	@for i in $(libvxworks_la_SOURCES); do \
+		$(SPARSE) $(CHECKFLAGS) $$i; \
+	done
Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#1 lore raw

PATCH 1/1 sparse fix: use NULL instead of 0

Sparse has found this, fixed by the patch below:

tlsf/tlsf.c:383:51: warning: Using plain integer as NULL pointer tlsf/tlsf.c:388:16: warning: Using plain integer as NULL pointer tlsf/tlsf.c:467:16: warning: Using plain integer as NULL pointer tlsf/tlsf.c:383:51: warning: Using plain integer as NULL pointer tlsf/tlsf.c:388:16: warning: Using plain integer as NULL pointer

---
 base/tlsf/tlsf.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
base/tlsf/tlsf.c +3 -3
Index: xenomai-solo/base/tlsf/tlsf.c
===================================================================
@@ -380,12 +380,12 @@
          MIN_BLOCK_SIZE) ? MIN_BLOCK_SIZE : ROUNDUP_SIZE(sizeof(area_info_t)) | USED_BLOCK | PREV_USED;
     b = (bhdr_t *) GET_NEXT_BLOCK(ib->ptr.buffer, ib->size & BLOCK_SIZE);
     b->size = ROUNDDOWN_SIZE(size - 3 * BHDR_OVERHEAD - (ib->size & BLOCK_SIZE)) | USED_BLOCK | PREV_USED;
-    b->ptr.free_ptr.prev = b->ptr.free_ptr.next = 0;
+    b->ptr.free_ptr.prev = b->ptr.free_ptr.next = NULL;
     lb = GET_NEXT_BLOCK(b->ptr.buffer, b->size & BLOCK_SIZE);
     lb->prev_hdr = b;
     lb->size = 0 | USED_BLOCK | PREV_FREE;
     ai = (area_info_t *) ib->ptr.buffer;
-    ai->next = 0;
+    ai->next = NULL;
     ai->end = lb;
     return ib;
 }
@@ -464,7 +464,7 @@
 
     memset(area, 0, area_size);
     ptr = tlsf->area_head;
-    ptr_prev = 0;
+    ptr_prev = NULL;
 
     ib0 = process_area(area, area_size);
     b0 = GET_NEXT_BLOCK(ib0->ptr.buffer, ib0->size & BLOCK_SIZE);
Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#2 lore raw

PATCH 1/1 sparse: clockobj_unmap not declared

In reply to Robert Schwebel

Sparse warns about this one:

clockobj.c:245:5: warning: symbol 'clockobj_unmap' was not declared. Should it be static?

Looks like the declaration for clockobj_unmap is missing.

---
 include/xenomai/clockobj.h |    2 ++
 1 file changed, 2 insertions(+)
include/xenomai/clockobj.h +2 -0
Index: xenomai-solo/include/xenomai/clockobj.h
===================================================================
@@ -66,6 +66,8 @@
 
 int clockobj_destroy(struct clockobj *clkobj);
 
+int clockobj_unmap(struct clockobj *clkobj);
+
 #ifdef __cplusplus
 }
 #endif
Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#3 lore raw

PATCH 1/1 sparse: threadobj_global_rr not declared

In reply to Robert Schwebel

Sparse warns about this one:

clockobj.c:245:5: warning: symbol 'clockobj_unmap' was not declared. Should it be static?

Looks like the declaration for threadobj_global_rr is missing.

---
 include/xenomai/threadobj.h |    2 ++
 1 file changed, 2 insertions(+)
include/xenomai/threadobj.h +2 -0
Index: xenomai-solo/include/xenomai/threadobj.h
===================================================================
@@ -79,6 +79,8 @@
 
 extern int threadobj_async;
 
+extern int threadobj_global_rr;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#4 lore raw

PATCH 1/1 sparse: include panic header file

In reply to Robert Schwebel

Sparse warns about this one:

panic.c:31:6: warning: symbol 'warning' was not declared. Should it be static? panic.c:40:6: warning: symbol 'panic' was not declared. Should it be static?

Include the declarations.

---
 base/panic.c |    1 +
 1 file changed, 1 insertion(+)
base/panic.c +1 -0
Index: xenomai-solo/base/panic.c
===================================================================
@@ -19,6 +19,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <xenomai/panic.h>
 
 static void __warning(const char *fmt, va_list ap)
 {
Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#5 lore raw

PATCH 1/1 sparse: include sysClkRateGet declaration

In reply to Robert Schwebel

Sparse warns about this one:

sysLib.c:22:5: warning: symbol 'sysClkRateGet' was not declared. Should it be static? sysLib.c:28:8: warning: symbol 'sysClkRateSet' was not declared. Should it be static?

---
 vxworks/sysLib.c |    1 +
 1 file changed, 1 insertion(+)
vxworks/sysLib.c +1 -0
Index: xenomai-solo/vxworks/sysLib.c
===================================================================
@@ -18,6 +18,7 @@
 
 #include "tickLib.h"
 #include <vxworks/errnoLib.h>
+#include <vxworks/sysLib.h>
 
 int sysClkRateGet(void)
 {
Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9
#6 lore raw
In reply to Robert Schwebel

Hello,

Quoted 10 lines · Robert Schwebel

This patch adds static analysis support with sparse to the xenomai-solo makefiles. To enable sparse checking, use

	./configure --with-sparse[=PATH]

and run 'make sparse' afterwards. I don't have a good idea right now how to avoid this extra step; it would be much nicer if every call to $(COMPILE) could be substituted by a sparse call plus the original one, but I didn't find a good method for that yet that also works with the libtool calls.

I haven't looked at it, but cgcc might help you. I don't know how it interacts with libtool, but maybe simply:

make CC=cgcc

works?

Best regards
Uwe

Signature · 3 lines
Uwe Kleine-König, Software Engineer
Digi International GmbH Branch Breisach, Küferstrasse 8, 79206 Breisach, Germany
Tax: 315/5781/0242 / VAT: DE153662976 / Reg. Amtsgericht Dortmund HRB 13962
#7 lore raw
In reply to Robert Schwebel
Quoted 11 lines · Robert Schwebel

This patch adds static analysis support with sparse to the xenomai-solo makefiles. To enable sparse checking, use

	./configure --with-sparse[=PATH]

and run 'make sparse' afterwards. I don't have a good idea right now how to avoid this extra step; it would be much nicer if every call to $(COMPILE) could be substituted by a sparse call plus the original one, but I didn't find a good method for that yet that also works with the libtool calls.

I have merged this patch series, adapting the Makefiles so that we don't need any support from configure.in to run sparse.

Normally, you should be able to run "make [SPARSE=/path/to/sparse] sparse" to start the analysis. Default path is "sparse".

Additionally, this now works with out of tree builds and supports mixed 32/64bit environments.

Thanks,

Quoted 127 lines
---
 Makefile.am         |   18 +++++++++++++++++-
 base/Makefile.am    |    6 ++++++
 configure.in        |   32 ++++++++++++++++++++++++++++++++
 psos/Makefile.am    |    6 ++++++
 vxworks/Makefile.am |    5 +++++
 5 files changed, 66 insertions(+), 1 deletion(-)

Index: xenomai-solo/base/Makefile.am
===================================================================

base/Makefile.am +6 -0
@@ -36,3 +36,9 @@
 	-DTLSF_USE_LOCKS=1 -DUSE_MMAP=1 -DUSE_SBRK=1
 
 EXTRA_DIST = tlsf/README
+
+sparse:
+	@for i in $(libxenomai_la_SOURCES) $(libtlsf_la_SOURCES); do \
+		$(SPARSE) $(CHECKFLAGS) $$i; \
+	done
+

Index: xenomai-solo/configure.in
===================================================================

configure.in +32 -0
@@ -70,6 +70,38 @@
 	esac])
 AC_MSG_RESULT(${debug_symbols:-no})
 
+dnl Sparse check (default: off)
+
+sparse=
+AC_MSG_CHECKING(whether to enable sparse)
+AC_ARG_WITH(sparse,
+    AC_HELP_STRING([--with-sparse@<:@=PATH@:>@], [activate static code analysis with sparse]),
+    [case "$withval" in
+    y | yes) sparse=sparse ;;
+    n | no)  sparse= ;;
+    *) sparse=$withval
+    esac],
+    [sparse=],[]
+)
+if test -n "$sparse" ; then
+    AC_MSG_RESULT(yes)
+    AC_SUBST(SPARSE, $sparse)
+    AC_MSG_CHECKING(whether sparse=$sparse is executable)
+    if test "`$sparse 2>&1 > /dev/null; echo $?`" = "0"; then
+        AC_MSG_RESULT(yes)
+        AC_SUBST(SPARSE, $sparse)
+    else
+        AC_MSG_RESULT(no)
+        AC_MSG_ERROR($sparse is not executable)
+    fi
+else
+    AC_MSG_RESULT(no)
+    AC_SUBST(SPARSE, true)
+fi
+
+checkflags="-nostdinc -isystem \$(SYSROOT)/usr/include -isystem `$CC -print-file-name=include` -Wbitwise -Wno-transparent-union -D_GNU_SOURCE -D_XOPEN_SOURCE=500 -D_REENTRANT \$(DEFS) \$(DEFAULT_INCLUDES) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS)"
+AC_SUBST(CHECKFLAGS, $checkflags)
+
 dnl Enable assertions (default: off)
 
 AC_MSG_CHECKING(whether assertions should be enabled)

Index: xenomai-solo/Makefile.am
===================================================================

Makefile.am +17 -1
@@ -1,6 +1,15 @@
 ACLOCAL_AMFLAGS=-I config
 
-SUBDIRS = base vxworks psos include config scripts
+SRC_SUBDIRS= \
+	base \
+	vxworks \
+	psos
+
+SUBDIRS = \
+	$(SRC_SUBDIRS) \
+	include \
+	config \
+	scripts
 
 EXTRA_DIST =
 
@@ -11,3 +20,10 @@
 
 install-user:
 	$(MAKE) install
+
+sparse:
+	@for i in $(SRC_SUBDIRS); do \
+		echo; \
+		make -C $$i sparse; \
+	done
+

Index: xenomai-solo/psos/Makefile.am
===================================================================

psos/Makefile.am +6 -0
@@ -22,3 +22,9 @@
 	-I$(top_srcdir)/include
 
 EXTRA_DIST =
+
+sparse:
+	@for i in $(libpsos_la_SOURCES); do \
+		$(SPARSE) $(CHECKFLAGS) $$i; \
+	done
+

Index: xenomai-solo/vxworks/Makefile.am
===================================================================

vxworks/Makefile.am +5 -0
@@ -24,3 +24,8 @@
 	-I$(top_srcdir)/include
 
 EXTRA_DIST = testsuite
+
+sparse:
+	@for i in $(libvxworks_la_SOURCES); do \
+		$(SPARSE) $(CHECKFLAGS) $$i; \
+	done
Signature · 1 line
Philippe.
#8 lore raw
Quoted 13 lines · Philippe Gerum
Quoted 11 lines · Robert Schwebel

This patch adds static analysis support with sparse to the xenomai-solo makefiles. To enable sparse checking, use

	./configure --with-sparse[=PATH]

and run 'make sparse' afterwards. I don't have a good idea right now how to avoid this extra step; it would be much nicer if every call to $(COMPILE) could be substituted by a sparse call plus the original one, but I didn't find a good method for that yet that also works with the libtool calls.

Quoted 8 lines

I have merged this patch series, adapting the Makefiles so that we don't need any support from configure.in to run sparse.

Normally, you should be able to run "make [SPARSE=/path/to/sparse] sparse" to start the analysis. Default path is "sparse".

Additionally, this now works with out of tree builds and supports mixed 32/64bit environments.

Great! Thanks.

Robert

Signature · 5 lines
 Dipl.-Ing. Robert Schwebel | http://www.pengutronix.de
 Pengutronix - Linux Solutions for Science and Industry
   Handelsregister:  Amtsgericht Hildesheim, HRA 2686
     Hannoversche Str. 2, 31134 Hildesheim, Germany
   Phone: +49-5121-206917-0 |  Fax: +49-5121-206917-9