summaryrefslogtreecommitdiff
path: root/usr/src/tools/smatch/Makefile
blob: 4e59279962420907ca62a703764d967f91d9ed6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# Copyright 2020 Joyent, Inc.
#

#
# The src/ sub-directory is un-modified copy of
# https://github.com/illumos/smatch/tree/$SPARSE_VERSION
#
# This Makefile installs just enough for us to be able to run smatch
# locally.
#

PROG = smatch
SPARSE_VERSION = 0.6.1-rc1-il-7

include ../Makefile.tools

# We have to build smatch before we can use cw
i386_CC = $(GNUC_ROOT)/bin/gcc
sparc_CC = $(GNUC_ROOT)/bin/gcc
# sparc doesn't recognise -msave-args
i386_SMATCHFLAGS = -msave-args
sparc_SMATCHFLAGS =

# When we use builtins, then ld's -zguidance will complain that libm is
# unused on x86 because the compiler will replace ceil(3M) with its own copy.
# However, on SPARC, it doesn't. So for now we disable builtins to make it
# consistent.
CFLAGS = -O -m64 -std=gnu99 -nodefaultlibs -D__sun $($(MACH)_SMATCHFLAGS)
CFLAGS += -fno-builtin
CFLAGS += -Wall -Wno-unknown-pragmas -Wno-psabi

SMATCHDATADIR = $(ROOTONBLDSHARE)/smatch

CFLAGS += -DSMATCHDATADIR='"$(SMATCHDATADIR)"'
CFLAGS += -DGCC_BASE='"/no/such/dir"'
CFLAGS += -DMULTIARCH_TRIPLET=NULL

LDCHECKS = $(ZASSERTDEFLIB) $(ZGUIDANCE) $(ZFATALWARNINGS)
LDLIBS += $(ZLAZYLOAD) $(ZDIRECT) -lsqlite3 -lmd -lgcc -lm -lc
LDFLAGS = $(MAPFILE.NES:%=-Wl,-M%)

#
# To allow linking to $(NATIVE_ADJUNCT) libraries on both multiarch (where
# 64-bit libraries will be found in $(NATIVE_ADJUNCT)/lib/$(MACH64)) and 64-bit
# images (where 64-bit libraries will be found in $(NATIVE_ADJUNCT)/lib/), we
# set our library and run paths to both locations.
#
LDFLAGS += -L$(NATIVE_ADJUNCT)/lib -R$(NATIVE_ADJUNCT)/lib
LDFLAGS += -L$(NATIVE_ADJUNCT)/lib/$(MACH64) -R$(NATIVE_ADJUNCT)/lib/$(MACH64)

NATIVE_LIBS += libsqlite3.so libmd.so libm.so libc.so
LDFLAGS += $(NATIVE_LIBS:%=$(ZASSERTDEFLIB)=%)

CPPFLAGS += -nostdinc
CPPFLAGS += -Isrc/
CPPFLAGS += -I$(NATIVE_ADJUNCT)/include
CPPFLAGS += -I/usr/include

# no install.bin
INS.file = $(RM) $@; $(CP) $< $(@D); $(CHMOD) $(FILEMODE) $@
INS.dir = mkdir -p $@; $(CHMOD) $(DIRMODE) $@

# fine for us
OS=linux

LIB_OBJS =
LIB_OBJS += allocate.o
LIB_OBJS += builtin.o
LIB_OBJS += char.o
LIB_OBJS += compat-$(OS).o
LIB_OBJS += cse.o
LIB_OBJS += dissect.o
LIB_OBJS += dominate.o
LIB_OBJS += evaluate.o
LIB_OBJS += expand.o
LIB_OBJS += expression.o
LIB_OBJS += flow.o
LIB_OBJS += flowgraph.o
LIB_OBJS += inline.o
LIB_OBJS += ir.o
LIB_OBJS += lib.o
LIB_OBJS += linearize.o
LIB_OBJS += liveness.o
LIB_OBJS += memops.o
LIB_OBJS += opcode.o
LIB_OBJS += optimize.o
LIB_OBJS += parse.o
LIB_OBJS += pre-process.o
LIB_OBJS += ptrlist.o
LIB_OBJS += ptrmap.o
LIB_OBJS += scope.o
LIB_OBJS += show-parse.o
LIB_OBJS += simplify.o
LIB_OBJS += sort.o
LIB_OBJS += ssa.o
LIB_OBJS += sset.o
LIB_OBJS += stats.o
LIB_OBJS += storage.o
LIB_OBJS += symbol.o
LIB_OBJS += target.o
LIB_OBJS += tokenize.o
LIB_OBJS += unssa.o
LIB_OBJS += utils.o
LIB_OBJS += macro_table.o
LIB_OBJS += token_store.o
LIB_OBJS += hashtable.o

SMATCH_OBJS =
SMATCH_OBJS += avl.o
SMATCH_OBJS += smatch_about_fn_ptr_arg.o
SMATCH_OBJS += smatch_address.o
SMATCH_OBJS += smatch_annotate.o
SMATCH_OBJS += smatch_array_values.o
SMATCH_OBJS += smatch_assigned_expr.o
SMATCH_OBJS += smatch_bits.o
SMATCH_OBJS += smatch_buf_comparison.o
SMATCH_OBJS += smatch_buf_size.o
SMATCH_OBJS += smatch_capped.o
SMATCH_OBJS += smatch_common_functions.o
SMATCH_OBJS += smatch_comparison.o
SMATCH_OBJS += smatch_conditions.o
SMATCH_OBJS += smatch_constraints.o
SMATCH_OBJS += smatch_constraints_required.o
SMATCH_OBJS += smatch_container_of.o
SMATCH_OBJS += smatch_data_source.o
SMATCH_OBJS += smatch_db.o
SMATCH_OBJS += smatch_equiv.o
SMATCH_OBJS += smatch_estate.o
SMATCH_OBJS += smatch_expressions.o
SMATCH_OBJS += smatch_expression_stacks.o
SMATCH_OBJS += smatch_extra.o
SMATCH_OBJS += smatch_files.o
SMATCH_OBJS += smatch_flow.o
SMATCH_OBJS += smatch_fresh_alloc.o
SMATCH_OBJS += smatch_fn_arg_link.o
SMATCH_OBJS += smatch_function_hooks.o
SMATCH_OBJS += smatch_function_info.o
SMATCH_OBJS += smatch_function_ptrs.o
SMATCH_OBJS += smatch_helper.o
SMATCH_OBJS += smatch_hooks.o
SMATCH_OBJS += smatch_ignore.o
SMATCH_OBJS += smatch_imaginary_absolute.o
SMATCH_OBJS += smatch_implied.o
SMATCH_OBJS += smatch_impossible.o
SMATCH_OBJS += smatch_integer_overflow.o
SMATCH_OBJS += smatch_kernel_user_data.o
SMATCH_OBJS += smatch_links.o
SMATCH_OBJS += smatch_math.o
SMATCH_OBJS += smatch_mem_tracker.o
SMATCH_OBJS += smatch_modification_hooks.o
SMATCH_OBJS += smatch_mtag_data.o
SMATCH_OBJS += smatch_mtag_map.o
SMATCH_OBJS += smatch_mtag.o
SMATCH_OBJS += smatch_nul_terminator.o
SMATCH_OBJS += smatch_param_cleared.o
SMATCH_OBJS += smatch_param_compare_limit.o
SMATCH_OBJS += smatch_parameter_names.o
SMATCH_OBJS += smatch_param_filter.o
SMATCH_OBJS += smatch_param_limit.o
SMATCH_OBJS += smatch_param_set.o
SMATCH_OBJS += smatch_param_to_mtag_data.o
SMATCH_OBJS += smatch_param_used.o
SMATCH_OBJS += smatch_parse_call_math.o
SMATCH_OBJS += smatch_passes_array_size.o
SMATCH_OBJS += smatch_project.o
SMATCH_OBJS += smatch_ranges.o
SMATCH_OBJS += smatch_real_absolute.o
SMATCH_OBJS += smatch_recurse.o
SMATCH_OBJS += smatch_returns.o
SMATCH_OBJS += smatch_return_to_param.o
SMATCH_OBJS += smatch_scope.o
SMATCH_OBJS += smatch_slist.o
SMATCH_OBJS += smatch_start_states.o
SMATCH_OBJS += smatch_statement_count.o
SMATCH_OBJS += smatch_states.o
SMATCH_OBJS += smatch_stored_conditions.o
SMATCH_OBJS += smatch_string_list.o
SMATCH_OBJS += smatch_strings.o
SMATCH_OBJS += smatch_strlen.o
SMATCH_OBJS += smatch_struct_assignment.o
SMATCH_OBJS += smatch_sval.o
SMATCH_OBJS += smatch_tracker.o
SMATCH_OBJS += smatch_type_links.o
SMATCH_OBJS += smatch_type.o
SMATCH_OBJS += smatch_type_val.o
SMATCH_OBJS += smatch_unknown_value.o
SMATCH_OBJS += smatch_untracked_param.o
SMATCH_OBJS += smatch_var_sym.o
SMATCH_OBJS += smatch_parsed_conditions.o

SMATCH_CHECK_OBJS:sh=ls src/check_*.c | sed -e 's+\.c+.o+;s+src/++;'

OBJS = smatch.o $(LIB_OBJS) $(SMATCH_OBJS) $(SMATCH_CHECK_OBJS)

SMATCH_DATA = \
	illumos_kernel.skipped_functions \
	illumos_user.skipped_functions

SMATCH_DB_DATA =
SMATCH_DB_DATA += call_implies.schema
SMATCH_DB_DATA += function_ptr.schema
SMATCH_DB_DATA += mtag_map.schema
SMATCH_DB_DATA += caller_info.schema
SMATCH_DB_DATA += function_type.schema
SMATCH_DB_DATA += param_map.schema
SMATCH_DB_DATA += common_caller_info.schema
SMATCH_DB_DATA += function_type_info.schema
SMATCH_DB_DATA += parameter_name.schema
SMATCH_DB_DATA += constraints.schema
SMATCH_DB_DATA += function_type_size.schema
SMATCH_DB_DATA += return_implies.schema
SMATCH_DB_DATA += constraints_required.schema
SMATCH_DB_DATA += function_type_value.schema
SMATCH_DB_DATA += return_states.schema
SMATCH_DB_DATA += data_info.schema
SMATCH_DB_DATA += local_values.schema
SMATCH_DB_DATA += sink_info.schema
SMATCH_DB_DATA += db.schema
SMATCH_DB_DATA += mtag_about.schema
SMATCH_DB_DATA += type_info.schema
SMATCH_DB_DATA += fn_data_link.schema
SMATCH_DB_DATA += mtag_alias.schema
SMATCH_DB_DATA += type_size.schema
SMATCH_DB_DATA += fn_ptr_data_link.schema
SMATCH_DB_DATA += mtag_data.schema
SMATCH_DB_DATA += mtag_info.schema
SMATCH_DB_DATA += type_value.schema

ROOTONBLDDATAFILES = $(SMATCH_DATA:%=$(SMATCHDATADIR)/smatch_data/%)
ROOTONBLDDATAFILES += $(SMATCH_DB_DATA:%=$(SMATCHDATADIR)/smatch_data/db/%)

BUILT_HEADERS = src/version.h src/check_list_local.h

.KEEP_STATE:

.PARALLEL: $(OBJS)

all: $(PROG)

install: all .WAIT $(ROOTONBLDMACHPROG) $(ROOTONBLDDATAFILES)

clean:
	rm -f $(OBJS) $(BUILT_HEADERS)

$(ROOTONBLDDATAFILES): $(SMATCHDATADIR)/smatch_data/db

$(SMATCHDATADIR)/smatch_data/%: src/smatch_data/%
	$(INS.file)

$(SMATCHDATADIR)/smatch_data/db:
	$(INS.dir)

$(SMATCHDATADIR)/smatch_data:
	$(INS.dir)

$(PROG): $(OBJS)
	$(LINK.c) $(OBJS) -o $@ $(LDLIBS)
	$(POST_PROCESS)

%.o: src/%.c $(BUILT_HEADERS)
	$(COMPILE.c) -o $@ $<

%.o: src/cwchash/%.c
	$(COMPILE.c) -o $@ $<

src/check_list_local.h:
	touch src/check_list_local.h

src/version.h:
	echo '#define SPARSE_VERSION "$(SPARSE_VERSION)"' > src/version.h

include ../Makefile.targ