db/fixup_kernel.sh: fix clear_user() handling
[smatch.git] / Makefile
blobedd00f7027c9b474365fcaaa575dc5a6863bb0d3
1 VERSION=0.6.4
3 ########################################################################
4 # The following variables can be overwritten from the command line
5 OS = linux
8 CC ?= gcc
9 CXX = g++
10 LD = $(CC)
11 AR = ar
13 CFLAGS ?= -g
15 DESTDIR ?=
16 PREFIX ?= $(HOME)
17 BINDIR ?= $(PREFIX)/bin
18 SHAREDIR ?= $(PREFIX)/share
19 MANDIR ?= $(SHAREDIR)/man
21 PKG_CONFIG ?= pkg-config
23 CHECKER_FLAGS ?= -Wno-vla
25 # Allow users to override build settings without dirtying their trees
26 # For debugging, put this in local.mk:
28 # CFLAGS += -O0 -DDEBUG -g3 -gdwarf-2
30 SPARSE_LOCAL_CONFIG ?= local.mk
31 -include ${SPARSE_LOCAL_CONFIG}
32 ########################################################################
35 LIB_OBJS :=
36 LIB_OBJS += allocate.o
37 LIB_OBJS += builtin.o
38 LIB_OBJS += char.o
39 LIB_OBJS += compat-$(OS).o
40 LIB_OBJS += cse.o
41 LIB_OBJS += dissect.o
42 LIB_OBJS += dominate.o
43 LIB_OBJS += evaluate.o
44 LIB_OBJS += expand.o
45 LIB_OBJS += expression.o
46 LIB_OBJS += flow.o
47 LIB_OBJS += flowgraph.o
48 LIB_OBJS += inline.o
49 LIB_OBJS += ir.o
50 LIB_OBJS += lib.o
51 LIB_OBJS += linearize.o
52 LIB_OBJS += liveness.o
53 LIB_OBJS += memops.o
54 LIB_OBJS += opcode.o
55 LIB_OBJS += optimize.o
56 LIB_OBJS += options.o
57 LIB_OBJS += parse.o
58 LIB_OBJS += predefine.o
59 LIB_OBJS += pre-process.o
60 LIB_OBJS += ptrlist.o
61 LIB_OBJS += ptrmap.o
62 LIB_OBJS += scope.o
63 LIB_OBJS += show-parse.o
64 LIB_OBJS += simplify.o
65 LIB_OBJS += sort.o
66 LIB_OBJS += ssa.o
67 LIB_OBJS += stats.o
68 LIB_OBJS += storage.o
69 LIB_OBJS += symbol.o
70 LIB_OBJS += target.o
71 LIB_OBJS += target-alpha.o
72 LIB_OBJS += target-arm.o
73 LIB_OBJS += target-arm64.o
74 LIB_OBJS += target-bfin.o
75 LIB_OBJS += target-default.o
76 LIB_OBJS += target-h8300.o
77 LIB_OBJS += target-m68k.o
78 LIB_OBJS += target-microblaze.o
79 LIB_OBJS += target-mips.o
80 LIB_OBJS += target-nds32.o
81 LIB_OBJS += target-nios2.o
82 LIB_OBJS += target-openrisc.o
83 LIB_OBJS += target-ppc.o
84 LIB_OBJS += target-riscv.o
85 LIB_OBJS += target-s390.o
86 LIB_OBJS += target-sh.o
87 LIB_OBJS += target-sparc.o
88 LIB_OBJS += target-x86.o
89 LIB_OBJS += target-xtensa.o
90 LIB_OBJS += tokenize.o
91 LIB_OBJS += unssa.o
92 LIB_OBJS += utils.o
93 LIB_OBJS += macro_table.o
94 LIB_OBJS += token_store.o
95 LIB_OBJS += cwchash/hashtable.o
96 LIB_OBJS += version.o
98 PROGRAMS :=
99 PROGRAMS += compile
100 PROGRAMS += ctags
101 PROGRAMS += example
102 PROGRAMS += graph
103 PROGRAMS += obfuscate
104 PROGRAMS += sparse
105 PROGRAMS += test-dissect
106 PROGRAMS += test-lexing
107 PROGRAMS += test-linearize
108 PROGRAMS += test-parsing
109 PROGRAMS += test-show-type
110 PROGRAMS += test-unssa
112 INST_PROGRAMS = smatch sparse cgcc
113 INST_MAN1 = sparse.1 cgcc.1
114 INST_ASSETS = $(wildcard smatch_data/db/*.schema)
115 INST_ASSETS += $(wildcard smatch_data/*)
116 INST_ASSETS += $(wildcard smatch_data/db/kernel.*)
118 all:
120 ########################################################################
121 # common flags/options/...
123 cflags = -fno-strict-aliasing
124 cflags += -Wall -Wwrite-strings -Wno-switch -Wno-psabi
126 GCC_BASE := $(shell $(CC) --print-file-name=)
127 cflags += -DGCC_BASE=\"$(GCC_BASE)\"
129 MULTIARCH_TRIPLET := $(shell $(CC) -print-multiarch 2>/dev/null)
130 cflags += -DMULTIARCH_TRIPLET=\"$(MULTIARCH_TRIPLET)\"
133 bindir := $(DESTDIR)$(BINDIR)
134 man1dir := $(DESTDIR)$(MANDIR)/man1
135 smatch_datadir := $(DESTDIR)$(SHAREDIR)/smatch
137 ########################################################################
138 # target specificities
140 compile: compile-i386.o
141 EXTRA_OBJS += compile-i386.o
143 # Can we use GCC's generated dependencies?
144 HAVE_GCC_DEP:=$(shell touch .gcc-test.c && \
145 $(CC) -c -Wp,-MP,-MMD,.gcc-test.d .gcc-test.c 2>/dev/null && \
146 echo 'yes'; rm -f .gcc-test.d .gcc-test.o .gcc-test.c)
147 ifeq ($(HAVE_GCC_DEP),yes)
148 cflags += -Wp,-MP,-MMD,$(@D)/.$(@F).d
149 endif
151 # Can we use libxml (needed for c2xml)?
152 HAVE_LIBXML:=$(shell $(PKG_CONFIG) --exists libxml-2.0 2>/dev/null && echo 'yes')
153 ifeq ($(HAVE_LIBXML),yes)
154 PROGRAMS+=c2xml
155 INST_PROGRAMS+=c2xml
156 c2xml-ldlibs := $(shell $(PKG_CONFIG) --libs libxml-2.0)
157 c2xml-cflags := $(shell $(PKG_CONFIG) --cflags libxml-2.0)
158 else
159 $(warning Your system does not have libxml, disabling c2xml)
160 endif
162 HAVE_SQLITE := $(shell $(PKG_CONFIG) --exists sqlite3 2>/dev/null && echo 'yes')
163 ifeq ($(HAVE_SQLITE),yes)
164 SQLITE_VERSION:=$(shell $(PKG_CONFIG) --modversion sqlite3)
165 SQLITE_VNUMBER:=$(shell printf '%d%02d%02d' $(subst ., ,$(SQLITE_VERSION)))
166 ifeq ($(shell expr "$(SQLITE_VNUMBER)" '>=' 32400),1)
167 PROGRAMS += semind
168 INST_PROGRAMS += semind
169 INST_MAN1 += semind.1
170 semind-ldlibs := $(shell $(PKG_CONFIG) --libs sqlite3)
171 semind-cflags := $(shell $(PKG_CONFIG) --cflags sqlite3)
172 semind-cflags += -std=gnu99
173 else
174 $(warning Your SQLite3 version ($(SQLITE_VERSION)) is too old, 3.24.0 or later is required.)
175 endif
176 else
177 $(warning Your system does not have sqlite3, disabling semind)
178 endif
180 # Can we use gtk (needed for test-inspect)
181 GTK_VERSION:=3.0
182 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
183 ifneq ($(HAVE_GTK),yes)
184 GTK_VERSION:=2.0
185 HAVE_GTK:=$(shell $(PKG_CONFIG) --exists gtk+-$(GTK_VERSION) 2>/dev/null && echo 'yes')
186 endif
187 ifeq ($(HAVE_GTK),yes)
188 GTK_CFLAGS := $(shell $(PKG_CONFIG) --cflags gtk+-$(GTK_VERSION))
189 ast-view-cflags := $(GTK_CFLAGS)
190 ast-model-cflags := $(GTK_CFLAGS)
191 ast-inspect-cflags := $(GTK_CFLAGS)
192 test-inspect-cflags := $(GTK_CFLAGS)
193 test-inspect-ldlibs := $(shell $(PKG_CONFIG) --libs gtk+-$(GTK_VERSION))
194 test-inspect: ast-model.o ast-view.o ast-inspect.o
195 EXTRA_OBJS += ast-model.o ast-view.o ast-inspect.o
196 PROGRAMS += test-inspect
197 INST_PROGRAMS += test-inspect
198 else
199 $(warning Your system does not have gtk3/gtk2, disabling test-inspect)
200 endif
202 # Can we use LLVM (needed for ... sparse-llvm)?
203 LLVM_CONFIG:=llvm-config
204 HAVE_LLVM:=$(shell $(LLVM_CONFIG) --version >/dev/null 2>&1 && echo 'yes')
205 ifeq ($(HAVE_LLVM),yes)
206 arch := $(shell uname -m)
207 ifeq (${MULTIARCH_TRIPLET},x86_64-linux-gnux32)
208 arch := x32
209 endif
210 ifneq ($(filter ${arch},i386 i486 i586 i686 x86_64 amd64),)
211 LLVM_VERSION:=$(shell $(LLVM_CONFIG) --version)
212 LLVM_VERSION_MAJOR:=$(firstword $(subst ., ,$(LLVM_VERSION)))
213 ifeq ($(shell expr "$(LLVM_VERSION_MAJOR)" '>=' 3),1)
214 LLVM_PROGS := sparse-llvm
215 $(LLVM_PROGS): LD := $(CXX)
216 LLVM_LDFLAGS := $(shell $(LLVM_CONFIG) --ldflags)
217 LLVM_CFLAGS := $(shell $(LLVM_CONFIG) --cppflags)
218 LLVM_LIBS := $(shell $(LLVM_CONFIG) --libs)
219 LLVM_LIBS += $(shell $(LLVM_CONFIG) --system-libs 2>/dev/null)
220 LLVM_LIBS += $(shell $(LLVM_CONFIG) --cxxflags | grep -F -q -e '-stdlib=libc++' && echo -lc++)
221 PROGRAMS += $(LLVM_PROGS)
222 INST_PROGRAMS += sparse-llvm sparsec
223 sparse-llvm-cflags := $(LLVM_CFLAGS) -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
224 sparse-llvm-ldflags := $(LLVM_LDFLAGS)
225 sparse-llvm-ldlibs := $(LLVM_LIBS)
226 ifeq ($(LLVM_VERSION_MAJOR),14)
227 sparse-llvm-cflags += -Wno-deprecated-declarations
228 endif
229 else
230 $(warning LLVM 3.0 or later required. Your system has version $(LLVM_VERSION) installed.)
231 endif
232 else
233 $(warning sparse-llvm disabled on ${arch})
234 endif
235 else
236 $(warning Your system does not have llvm, disabling sparse-llvm)
237 endif
239 ifeq ($(HAVE_BOOLECTOR),yes)
240 PROGRAMS += scheck
241 scheck-cflags := -I${BOOLECTORDIR}/include/boolector
242 scheck-ldflags := -L${BOOLECTORDIR}/lib
243 scheck-ldlibs := -lboolector -llgl -lbtor2parser
244 endif
246 ########################################################################
247 LIBS := libsparse.a
248 OBJS := $(LIB_OBJS) $(EXTRA_OBJS) $(PROGRAMS:%=%.o)
250 # Pretty print
251 V := @
252 Q := $(V:1=)
254 ########################################################################
256 SMATCH_OBJS :=
257 SMATCH_OBJS += avl.o
258 SMATCH_OBJS += smatch_about_fn_ptr_arg.o
259 SMATCH_OBJS += smatch_address.o
260 SMATCH_OBJS += smatch_allocations.o
261 SMATCH_OBJS += smatch_annotate.o
262 SMATCH_OBJS += smatch_array_values.o
263 SMATCH_OBJS += smatch_assigned_expr.o
264 SMATCH_OBJS += smatch_bits.o
265 SMATCH_OBJS += smatch_buf_comparison.o
266 SMATCH_OBJS += smatch_buf_comparison2.o
267 SMATCH_OBJS += smatch_buf_size.o
268 SMATCH_OBJS += smatch_capped.o
269 SMATCH_OBJS += smatch_common_functions.o
270 SMATCH_OBJS += smatch_comparison.o
271 SMATCH_OBJS += smatch_conditions.o
272 SMATCH_OBJS += smatch_constraints.o
273 SMATCH_OBJS += smatch_constraints_required.o
274 SMATCH_OBJS += smatch_container_of.o
275 SMATCH_OBJS += smatch_data_source.o
276 SMATCH_OBJS += smatch_db.o
277 SMATCH_OBJS += smatch_dereference.o
278 SMATCH_OBJS += smatch_equiv.o
279 SMATCH_OBJS += smatch_estate.o
280 SMATCH_OBJS += smatch_expressions.o
281 SMATCH_OBJS += smatch_expression_stacks.o
282 SMATCH_OBJS += smatch_extra.o
283 SMATCH_OBJS += smatch_files.o
284 SMATCH_OBJS += smatch_flow.o
285 SMATCH_OBJS += smatch_fn_arg_link.o
286 SMATCH_OBJS += smatch_fresh_alloc.o
287 SMATCH_OBJS += smatch_function_hooks.o
288 SMATCH_OBJS += smatch_function_info.o
289 SMATCH_OBJS += smatch_function_ptrs.o
290 SMATCH_OBJS += smatch_goto_tracker.o
291 SMATCH_OBJS += smatch_hash.o
292 SMATCH_OBJS += smatch_helper.o
293 SMATCH_OBJS += smatch_hooks.o
294 SMATCH_OBJS += smatch_ignore.o
295 SMATCH_OBJS += smatch_imaginary_absolute.o
296 SMATCH_OBJS += smatch_implied.o
297 SMATCH_OBJS += smatch_impossible.o
298 SMATCH_OBJS += smatch_integer_overflow.o
299 SMATCH_OBJS += smatch_kernel_atomic_dec_test_path.o
300 SMATCH_OBJS += smatch_kernel_err_ptr.o
301 SMATCH_OBJS += smatch_kernel_has_devm_cleanup.o
302 SMATCH_OBJS += smatch_kernel_irq_context.o
303 SMATCH_OBJS += smatch_kernel_kref_put.o
304 SMATCH_OBJS += smatch_kernel_netdev_priv.o
305 SMATCH_OBJS += smatch_kernel_task_state.o
306 SMATCH_OBJS += smatch_kernel_task_state_info.o
307 SMATCH_OBJS += smatch_kernel_user_data.o
308 SMATCH_OBJS += smatch_kernel_host_data.o
309 SMATCH_OBJS += smatch_kernel_xa_err.o
310 SMATCH_OBJS += smatch_links.o
311 SMATCH_OBJS += smatch_math.o
312 SMATCH_OBJS += smatch_mem_tracker.o
313 SMATCH_OBJS += smatch_modification_hooks.o
314 SMATCH_OBJS += smatch_mtag_data.o
315 SMATCH_OBJS += smatch_mtag_map.o
316 SMATCH_OBJS += smatch_mtag.o
317 SMATCH_OBJS += smatch_nul_terminator.o
318 SMATCH_OBJS += smatch_param_bits_set.o
319 SMATCH_OBJS += smatch_param_bits_clear.o
320 SMATCH_OBJS += smatch_param_cleared.o
321 SMATCH_OBJS += smatch_param_compare_limit.o
322 SMATCH_OBJS += smatch_parameter_names.o
323 SMATCH_OBJS += smatch_param_filter.o
324 SMATCH_OBJS += smatch_param_key.o
325 SMATCH_OBJS += smatch_param_limit.o
326 SMATCH_OBJS += smatch_param_set.o
327 SMATCH_OBJS += smatch_param_to_mtag_data.o
328 SMATCH_OBJS += smatch_param_used.o
329 SMATCH_OBJS += smatch_parse_call_math.o
330 SMATCH_OBJS += smatch_parsed_conditions.o
331 SMATCH_OBJS += smatch_passes_array_size.o
332 SMATCH_OBJS += smatch_points_to_container.o
333 SMATCH_OBJS += smatch_points_to_user_data.o
334 SMATCH_OBJS += smatch_points_to_host_data.o
335 SMATCH_OBJS += smatch_power_of_two.o
336 SMATCH_OBJS += smatch_project.o
337 SMATCH_OBJS += smatch_ranges.o
338 SMATCH_OBJS += smatch_real_absolute.o
339 SMATCH_OBJS += smatch_recurse.o
340 SMATCH_OBJS += smatch_refcount.o
341 SMATCH_OBJS += smatch_refcount_info.o
342 SMATCH_OBJS += smatch_returns.o
343 SMATCH_OBJS += smatch_return_to_param.o
344 SMATCH_OBJS += smatch_ssa.o
345 SMATCH_OBJS += smatch_scope.o
346 SMATCH_OBJS += smatch_slist.o
347 SMATCH_OBJS += smatch_start_states.o
348 SMATCH_OBJS += smatch_statement_count.o
349 SMATCH_OBJS += smatch_states.o
350 SMATCH_OBJS += smatch_state_assigned.o
351 SMATCH_OBJS += smatch_stored_conditions.o
352 SMATCH_OBJS += smatch_string_list.o
353 SMATCH_OBJS += smatch_strings.o
354 SMATCH_OBJS += smatch_strlen.o
355 SMATCH_OBJS += smatch_struct_assignment.o
356 SMATCH_OBJS += smatch_sval.o
357 SMATCH_OBJS += smatch_tracker.o
358 SMATCH_OBJS += smatch_type_links.o
359 SMATCH_OBJS += smatch_type.o
360 SMATCH_OBJS += smatch_type_val.o
361 SMATCH_OBJS += smatch_unconstant_macros.o
362 SMATCH_OBJS += smatch_units.o
363 SMATCH_OBJS += smatch_unknown_value.o
364 SMATCH_OBJS += smatch_untracked_param.o
365 SMATCH_OBJS += smatch_untracked_var.o
366 SMATCH_OBJS += smatch_var_sym.o
368 CFLAGS+=-D__CHECKNAME__='"$(subst .c,,$(notdir $<))"'
370 SMATCH_CHECKS=$(shell ls check_*.c | sed -e 's/\.c/.o/')
371 SMATCH_DATA=smatch_data/kernel.allocation_funcs \
372 smatch_data/kernel.frees_argument smatch_data/kernel.puts_argument \
373 smatch_data/kernel.dev_queue_xmit smatch_data/kernel.returns_err_ptr \
374 smatch_data/kernel.dma_funcs smatch_data/kernel.returns_held_funcs \
375 smatch_data/kernel.no_return_funcs
377 SMATCH_SCRIPTS=smatch_scripts/add_gfp_to_allocations.sh \
378 smatch_scripts/build_kernel_data.sh \
379 smatch_scripts/call_tree.pl smatch_scripts/filter_kernel_deref_check.sh \
380 smatch_scripts/find_expanded_holes.pl smatch_scripts/find_null_params.sh \
381 smatch_scripts/follow_params.pl smatch_scripts/gen_allocation_list.sh \
382 smatch_scripts/gen_bit_shifters.sh smatch_scripts/gen_dma_funcs.sh \
383 smatch_scripts/generisize.pl smatch_scripts/gen_err_ptr_list.sh \
384 smatch_scripts/gen_expects_err_ptr.sh smatch_scripts/gen_frees_list.sh \
385 smatch_scripts/gen_gfp_flags.sh smatch_scripts/gen_no_return_funcs.sh \
386 smatch_scripts/gen_puts_list.sh smatch_scripts/gen_returns_held.sh \
387 smatch_scripts/gen_rosenberg_funcs.sh smatch_scripts/gen_sizeof_param.sh \
388 smatch_scripts/gen_unwind_functions.sh smatch_scripts/kchecker \
389 smatch_scripts/kpatch.sh smatch_scripts/new_bugs.sh \
390 smatch_scripts/show_errs.sh smatch_scripts/show_ifs.sh \
391 smatch_scripts/show_unreachable.sh smatch_scripts/strip_whitespace.pl \
392 smatch_scripts/summarize_errs.sh smatch_scripts/test_kernel.sh \
393 smatch_scripts/trace_params.pl smatch_scripts/unlocked_paths.pl \
394 smatch_scripts/whitespace_only.sh smatch_scripts/wine_checker.sh \
396 SMATCH_LDFLAGS := -lsqlite3 -lssl -lcrypto -lm
398 smatch: smatch.o $(SMATCH_OBJS) $(SMATCH_CHECKS) $(LIBS)
399 $(Q)$(LD) -o $@ $< $(SMATCH_OBJS) $(SMATCH_CHECKS) $(LIBS) $(SMATCH_LDFLAGS)
401 smatch_data/db/sm_hash: sm_hash.o $(SMATCH_OBJS)
402 $(Q)$(LD) -o smatch_data/db/sm_hash sm_hash.o smatch_hash.o $(SMATCH_LDFLAGS)
404 sm_hash.o: sm_hash.c smatch.h
405 $(CC) $(CFLAGS) -c sm_hash.c
407 check_list_local.h:
408 touch check_list_local.h
410 smatch.o: smatch.c $(LIB_H) smatch.h check_list.h check_list_local.h
411 $(CC) $(CFLAGS) -c smatch.c -DSMATCHDATADIR='"$(smatch_datadir)"'
413 $(SMATCH_OBJS) $(SMATCH_CHECKS): smatch.h smatch_slist.h smatch_extra.h \
414 smatch_constants.h avl.h
416 ########################################################################
417 all: $(PROGRAMS) smatch smatch_data/db/sm_hash
419 ldflags += $($(@)-ldflags) $(LDFLAGS)
420 ldlibs += $($(@)-ldlibs) $(LDLIBS) -lm
421 $(PROGRAMS): % : %.o $(LIBS)
422 @echo " LD $@"
423 $(Q)$(LD) $(ldflags) $^ $(ldlibs) -o $@
425 libsparse.a: $(LIB_OBJS)
426 @echo " AR $@"
427 $(Q)$(AR) rcs $@ $^
430 cflags += $($(*)-cflags) $(CPPFLAGS) $(CFLAGS)
431 %.o: %.c
432 @echo " CC $@"
433 $(Q)$(CC) $(cflags) -c -o $@ $<
435 %.sc: %.c sparse
436 @echo " CHECK $<"
437 $(Q)CHECK=./sparse ./cgcc -no-compile $(CHECKER_FLAGS) $(cflags) -c $<
439 selfcheck: $(OBJS:.o=.sc)
441 SPARSE_VERSION:=$(shell git describe --dirty 2>/dev/null || echo '$(VERSION)')
442 version.o: version.h
443 version.h: FORCE
444 @echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > version.h.tmp
445 @if cmp -s version.h version.h.tmp; then \
446 rm version.h.tmp; \
447 else \
448 echo " GEN $@"; \
449 mv version.h.tmp version.h; \
453 check: all
454 $(Q)cd validation && ./test-suite
455 validation/%: $(PROGRAMS) FORCE
456 $(Q)validation/test-suite $*
459 clean: clean-check
460 @rm -f *.[oa] .*.d cwchash/hashtable.o cwchash/.hashtable.o.d $(PROGRAMS) version.h smatch
461 clean-check:
462 @echo " CLEAN"
463 @find validation/ \( -name "*.c.output.*" \
464 -o -name "*.c.error.*" \
465 -o -name "*.o" \
466 \) -exec rm {} \;
469 install: install-bin install-man install-assets
470 install-bin: $(INST_PROGRAMS:%=$(bindir)/%)
471 install-man: $(INST_MAN1:%=$(man1dir)/%)
472 install-assets: $(INST_ASSETS:%=$(smatch_datadir)/%)
474 $(bindir)/%: %
475 @echo " INSTALL $@"
476 $(Q)install -D $< $@ || exit 1;
477 $(man1dir)/% $(smatch_datadir)/%: %
478 @echo " INSTALL $@"
479 $(Q)install -D -m 644 $< $@ || exit 1;
481 .PHONY: FORCE
483 # GCC's dependencies
484 -include $(OBJS:%.o=.%.o.d)