Print this page
10703 smatch unreachable code checking needs reworking
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/Makefile
+++ new/usr/src/tools/smatch/src/Makefile
1 -VERSION=0.5.1-il-4
1 +VERSION=0.5.1-il-5
2 2
3 3 # Generating file version.h if current version has changed
4 4 SPARSE_VERSION:=$(shell git describe 2>/dev/null || echo '$(VERSION)')
5 5 VERSION_H := $(shell cat version.h 2>/dev/null)
6 6 ifneq ($(lastword $(VERSION_H)),"$(SPARSE_VERSION)")
7 7 $(info $(shell echo ' GEN 'version.h))
8 8 $(shell echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h)
9 9 endif
10 10
11 11 OS = linux
12 12
13 13 ifeq ($(CC),"")
14 14 CC = gcc
15 15 endif
16 16
17 17 CFLAGS += -O2 -finline-functions -fno-strict-aliasing -g
18 18 CFLAGS += -Wall -Wwrite-strings -Wno-switch
19 19 LDFLAGS += -g -lm -lsqlite3 -lssl -lcrypto
20 20 LD = gcc
21 21 AR = ar
22 22 PKG_CONFIG = pkg-config
23 23 COMMON_CFLAGS = -O2 -finline-functions -fno-strict-aliasing -g
24 24 COMMON_CFLAGS += -Wall -Wwrite-strings
25 25
26 26 ALL_CFLAGS = $(COMMON_CFLAGS) $(PKG_CFLAGS) $(CFLAGS)
27 27 #
28 28 # For debugging, put this in local.mk:
29 29 #
30 30 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
31 31 #
32 32
33 33 HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
34 34 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
35 35 $(CC) -c -Wp,-MD,.gcc-test.d .gcc-test.c 2>/dev/null && \
36 36 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
37 37
38 38 GTK_VERSION:=3.0
39 39 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
40 40 ifneq ($(HAVE_GTK),yes)
41 41 GTK_VERSION:=2.0
42 42 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
43 43 endif
44 44
45 45 LLVM_CONFIG:=llvm-config
46 46 HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
47 47
48 48 GCC_BASE := $(shell $(CC) --print-file-name=)
49 49 COMMON_CFLAGS += -DGCC_BASE=\"$(GCC_BASE)\"
50 50
51 51 MULTIARCH_TRIPLET := $(shell $(CC) -print-multiarch 2>/dev/null)
52 52 COMMON_CFLAGS += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
53 53
54 54 ifeq ($(HAVE_GCC_DEP),yes)
55 55 COMMON_CFLAGS += -Wp,-MD,$(@D)/.$(@F).d
56 56 endif
57 57
58 58 DESTDIR=
59 59 INSTALL_PREFIX ?=$(HOME)
60 60 BINDIR=$(INSTALL_PREFIX)/bin
61 61 LIBDIR=$(INSTALL_PREFIX)/lib
62 62 MANDIR=$(INSTALL_PREFIX)/share/man
63 63 MAN1DIR=$(MANDIR)/man1
64 64 INCLUDEDIR=$(INSTALL_PREFIX)/include
65 65 PKGCONFIGDIR=$(LIBDIR)/pkgconfig
66 66 SMATCHDATADIR=$(INSTALL_PREFIX)/share/smatch
67 67
68 68 SMATCH_FILES=smatch_flow.o smatch_conditions.o smatch_slist.o smatch_states.o \
69 69 smatch_helper.o smatch_type.o smatch_hooks.o smatch_function_hooks.o \
70 70 smatch_modification_hooks.o smatch_extra.o smatch_estate.o smatch_math.o \
71 71 smatch_sval.o smatch_ranges.o smatch_implied.o smatch_ignore.o smatch_project.o \
72 72 smatch_var_sym.o smatch_tracker.o smatch_files.o smatch_expression_stacks.o \
73 73 smatch_equiv.o smatch_buf_size.o smatch_strlen.o smatch_capped.o smatch_db.o \
74 74 smatch_expressions.o smatch_returns.o smatch_parse_call_math.o \
75 75 smatch_param_limit.o smatch_param_filter.o \
76 76 smatch_param_set.o smatch_comparison.o smatch_param_compare_limit.o smatch_local_values.o \
77 77 smatch_function_ptrs.o smatch_annotate.o smatch_string_list.o \
78 78 smatch_param_cleared.o smatch_start_states.o \
79 79 smatch_recurse.o smatch_data_source.o smatch_type_val.o \
80 80 smatch_common_functions.o smatch_struct_assignment.o \
81 81 smatch_unknown_value.o smatch_stored_conditions.o avl.o \
82 82 smatch_function_info.o smatch_links.o smatch_auto_copy.o \
83 83 smatch_type_links.o smatch_untracked_param.o smatch_impossible.o \
84 84 smatch_strings.o smatch_param_used.o smatch_container_of.o smatch_address.o \
85 85 smatch_buf_comparison.o smatch_real_absolute.o smatch_scope.o \
86 86 smatch_imaginary_absolute.o smatch_parameter_names.o \
87 87 smatch_return_to_param.o smatch_passes_array_size.o \
88 88 smatch_constraints.o smatch_constraints_required.o \
89 89 smatch_fn_arg_link.o smatch_about_fn_ptr_arg.o smatch_mtag.o \
90 90 smatch_mtag_map.o smatch_mtag_data.o \
91 91 smatch_param_to_mtag_data.o smatch_mem_tracker.o smatch_array_values.o \
92 92 smatch_nul_terminator.o smatch_assigned_expr.o smatch_kernel_user_data.o \
93 93 smatch_statement_count.o smatch_integer_overflow.o smatch_bits.o
94 94
95 95 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
96 96 SMATCH_DATA=smatch_data/kernel.allocation_funcs \
97 97 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
98 98 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
99 99 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
100 100 smatch_data/kernel.no_return_funcs
101 101
102 102 SMATCH_SCRIPTS=smatch_scripts/add_gfp_to_allocations.sh \
103 103 smatch_scripts/build_kernel_data.sh \
104 104 smatch_scripts/call_tree.pl smatch_scripts/filter_kernel_deref_check.sh \
105 105 smatch_scripts/find_expanded_holes.pl smatch_scripts/find_null_params.sh \
106 106 smatch_scripts/follow_params.pl smatch_scripts/gen_allocation_list.sh \
107 107 smatch_scripts/gen_bit_shifters.sh smatch_scripts/gen_dma_funcs.sh \
108 108 smatch_scripts/generisize.pl smatch_scripts/gen_err_ptr_list.sh \
109 109 smatch_scripts/gen_expects_err_ptr.sh smatch_scripts/gen_frees_list.sh \
110 110 smatch_scripts/gen_gfp_flags.sh smatch_scripts/gen_no_return_funcs.sh \
111 111 smatch_scripts/gen_puts_list.sh smatch_scripts/gen_returns_held.sh \
112 112 smatch_scripts/gen_rosenberg_funcs.sh smatch_scripts/gen_sizeof_param.sh \
113 113 smatch_scripts/gen_unwind_functions.sh smatch_scripts/kchecker \
114 114 smatch_scripts/kpatch.sh smatch_scripts/new_bugs.sh \
115 115 smatch_scripts/show_errs.sh smatch_scripts/show_ifs.sh \
116 116 smatch_scripts/show_unreachable.sh smatch_scripts/strip_whitespace.pl \
117 117 smatch_scripts/summarize_errs.sh smatch_scripts/test_kernel.sh \
118 118 smatch_scripts/trace_params.pl smatch_scripts/unlocked_paths.pl \
119 119 smatch_scripts/whitespace_only.sh smatch_scripts/wine_checker.sh \
120 120
121 121 PROGRAMS=test-lexing test-parsing obfuscate compile graph sparse \
122 122 test-linearize example test-unssa test-dissect ctags
123 123 INST_PROGRAMS=smatch cgcc
124 124
125 125 INST_MAN1=sparse.1 cgcc.1
126 126
127 127 ifeq ($(HAVE_LIBXML),yes)
128 128 PROGRAMS+=c2xml
129 129 INST_PROGRAMS+=c2xml
130 130 c2xml_EXTRA_OBJS = `$(PKG_CONFIG) --libs libxml-2.0`
131 131 LIBXML_CFLAGS := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
132 132 else
133 133 $(warning Your system does not have libxml, disabling c2xml)
134 134 endif
135 135
136 136 ifeq ($(HAVE_GTK),yes)
137 137 GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION))
138 138 GTK_LIBS := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
139 139 PROGRAMS += test-inspect
140 140 INST_PROGRAMS += test-inspect
141 141 test-inspect_EXTRA_DEPS := ast-model.o ast-view.o ast-inspect.o
142 142 test-inspect_OBJS := test-inspect.o $(test-inspect_EXTRA_DEPS)
143 143 $(test-inspect_OBJS) $(test-inspect_OBJS:.o=.sc): PKG_CFLAGS += $(GTK_CFLAGS)
144 144 test-inspect_EXTRA_OBJS := $(GTK_LIBS)
145 145 else
146 146 $(warning Your system does not have gtk3/gtk2, disabling test-inspect)
147 147 endif
148 148
149 149 ifeq ($(HAVE_LLVM),yes)
150 150 ifeq ($(shell uname -m | grep -q '\(i386\|x86\)' && echo ok),ok)
151 151 LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
152 152 ifeq ($(shell expr "$(LLVM_VERSION)" : '[3-9]\.'),2)
153 153 LLVM_PROGS := sparse-llvm
154 154 $(LLVM_PROGS): LD := g++
155 155 LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
156 156 LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cflags | sed -e "s/-DNDEBUG//g" | sed -e "s/-pedantic//g")
157 157 LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
158 158 LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
159 159 PROGRAMS += $(LLVM_PROGS)
160 160 INST_PROGRAMS += sparse-llvm sparsec
161 161 sparse-llvm.o sparse-llvm.sc: PKG_CFLAGS += $(LLVM_CFLAGS)
162 162 sparse-llvm_EXTRA_OBJS := $(LLVM_LIBS) $(LLVM_LDFLAGS)
163 163 else
164 164 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
165 165 endif
166 166 else
167 167 $(warning sparse-llvm disabled on $(shell uname -m))
168 168 endif
169 169 else
170 170 $(warning Your system does not have llvm, disabling sparse-llvm)
171 171 endif
172 172
173 173 LIB_H= token.h parse.h lib.h symbol.h scope.h expression.h target.h \
174 174 linearize.h bitmap.h ident-list.h compat.h flow.h allocate.h \
175 175 storage.h ptrlist.h dissect.h
176 176
177 177 LIB_OBJS= target.o parse.o tokenize.o pre-process.o symbol.o lib.o scope.o \
178 178 expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
179 179 char.o sort.o allocate.o compat-$(OS).o ptrlist.o \
180 180 builtin.o \
181 181 stats.o \
182 182 flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o \
183 183 dissect.o \
184 184 macro_table.o token_store.o cwchash/hashtable.o
185 185
186 186 LIB_FILE= libsparse.a
187 187 SLIB_FILE= libsparse.so
188 188
189 189 # If you add $(SLIB_FILE) to this, you also need to add -fpic to BASIC_CFLAGS above.
190 190 # Doing so incurs a noticeable performance hit, and Sparse does not have a
191 191 # stable shared library interface, so this does not occur by default. If you
192 192 # really want a shared library, you may want to build Sparse twice: once
193 193 # without -fpic to get all the Sparse tools, and again with -fpic to get the
194 194 # shared library.
195 195 LIBS=$(LIB_FILE)
196 196
197 197 #
198 198 # Pretty print
199 199 #
200 200 V = @
201 201 Q = $(V:1=)
202 202 QUIET_CC = $(Q:@=@echo ' CC '$@;)
203 203 QUIET_CHECK = $(Q:@=@echo ' CHECK '$<;)
204 204 QUIET_AR = $(Q:@=@echo ' AR '$@;)
205 205 QUIET_GEN = $(Q:@=@echo ' GEN '$@;)
206 206 QUIET_LINK = $(Q:@=@echo ' LINK '$@;)
207 207 # We rely on the -v switch of install to print 'file -> $install_dir/file'
208 208 QUIET_INST_SH = $(Q:@=echo -n ' INSTALL ';)
209 209 QUIET_INST = $(Q:@=@echo -n ' INSTALL ';)
210 210
211 211 define INSTALL_EXEC
212 212 $(QUIET_INST)install -v $1 $(DESTDIR)$2/$1 || exit 1;
213 213
214 214 endef
215 215
216 216 define INSTALL_FILE
217 217 $(QUIET_INST)install -v -m 644 $1 $(DESTDIR)$2/$1 || exit 1;
218 218
219 219 endef
220 220
221 221 SED_PC_CMD = 's|@version@|$(VERSION)|g; \
222 222 s|@prefix@|$(INSTALL_PREFIX)|g; \
223 223 s|@libdir@|$(LIBDIR)|g; \
224 224 s|@includedir@|$(INCLUDEDIR)|g'
225 225
226 226
227 227
228 228 # Allow users to override build settings without dirtying their trees
229 229 -include local.mk
230 230
231 231
232 232 all: $(PROGRAMS) sparse.pc smatch
233 233
234 234 all-installable: $(INST_PROGRAMS) $(LIBS) $(LIB_H) sparse.pc
235 235
236 236 install: all-installable
237 237 $(Q)install -d $(DESTDIR)$(BINDIR)
238 238 $(Q)install -d $(DESTDIR)$(LIBDIR)
239 239 $(Q)install -d $(DESTDIR)$(MAN1DIR)
240 240 $(Q)install -d $(DESTDIR)$(INCLUDEDIR)/sparse
241 241 $(Q)install -d $(DESTDIR)$(PKGCONFIGDIR)
242 242 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_data
243 243 $(Q)install -d $(DESTDIR)$(SMATCHDATADIR)/smatch_scripts
244 244 $(foreach f,$(INST_PROGRAMS),$(call INSTALL_EXEC,$f,$(BINDIR)))
245 245 $(foreach f,$(INST_MAN1),$(call INSTALL_FILE,$f,$(MAN1DIR)))
246 246 $(foreach f,$(LIBS),$(call INSTALL_FILE,$f,$(LIBDIR)))
247 247 $(foreach f,$(LIB_H),$(call INSTALL_FILE,$f,$(INCLUDEDIR)/sparse))
248 248 $(call INSTALL_FILE,sparse.pc,$(PKGCONFIGDIR))
249 249 $(foreach f,$(SMATCH_DATA),$(call INSTALL_FILE,$f,$(SMATCHDATADIR)))
250 250 $(foreach f,$(SMATCH_SCRIPTS),$(call INSTALL_EXEC,$f,$(SMATCHDATADIR)))
251 251
252 252 sparse.pc: sparse.pc.in
253 253 $(QUIET_GEN)sed $(SED_PC_CMD) sparse.pc.in > sparse.pc
254 254
255 255
256 256 compile_EXTRA_DEPS = compile-i386.o
257 257
258 258 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
259 259 $(PROGRAMS): % : %.o
260 260 $(QUIET_LINK)$(LD) -o $@ $^ $($@_EXTRA_OBJS) $(LDFLAGS)
261 261
262 262 smatch: smatch.o $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS)
263 263 $(QUIET_LINK)$(LD) -o $@ $< $(SMATCH_FILES) $(SMATCH_CHECKS) $(LIBS) $(LDFLAGS)
264 264
265 265 $(LIB_FILE): $(LIB_OBJS)
266 266 $(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
267 267
268 268 $(SLIB_FILE): $(LIB_OBJS)
269 269 $(QUIET_LINK)$(CC) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS) $(LDFLAGS)
270 270
271 271 check_list_local.h:
272 272 touch check_list_local.h
273 273
274 274 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
275 275 $(CC) $(CFLAGS) -c smatch.c -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
276 276 $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h avl.h
277 277 DEP_FILES := $(wildcard .*.o.d)
278 278
279 279 ifneq ($(DEP_FILES),)
280 280 include $(DEP_FILES)
281 281 endif
282 282
283 283 c2xml.o c2xml.sc: PKG_CFLAGS += $(LIBXML_CFLAGS)
284 284
285 285 pre-process.sc: CHECKER_FLAGS += -Wno-vla
286 286
287 287 %.o: %.c $(LIB_H)
288 288 $(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $<
289 289
290 290 %.sc: %.c sparse
291 291 $(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(ALL_CFLAGS) $<
292 292
293 293 ALL_OBJS := $(LIB_OBJS) $(foreach p,$(PROGRAMS),$(p).o $($(p)_EXTRA_DEPS))
294 294 selfcheck: $(ALL_OBJS:.o=.sc)
295 295
296 296
297 297 clean: clean-check
298 298 rm -f *.[oa] .*.d *.so cwchash/*.o cwchash/.*.d cwchash/tester \
299 299 $(PROGRAMS) $(SLIB_FILE) pre-process.h sparse.pc version.h
300 300
301 301 dist:
302 302 @if test "$(SPARSE_VERSION)" != "v$(VERSION)" ; then \
303 303 echo 'Update VERSION in the Makefile before running "make dist".' ; \
304 304 exit 1 ; \
305 305 fi
306 306 git archive --format=tar --prefix=sparse-$(VERSION)/ HEAD^{tree} | gzip -9 > sparse-$(VERSION).tar.gz
307 307
308 308 check: all
309 309 $(Q)cd validation && ./test-suite
310 310
311 311 clean-check:
312 312 find validation/ \( -name "*.c.output.expected" \
313 313 -o -name "*.c.output.got" \
314 314 -o -name "*.c.output.diff" \
315 315 -o -name "*.c.error.expected" \
316 316 -o -name "*.c.error.got" \
317 317 -o -name "*.c.error.diff" \
318 318 \) -exec rm {} \;
↓ open down ↓ |
307 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX