-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathMakefile
More file actions
206 lines (165 loc) · 6.3 KB
/
Copy pathMakefile
File metadata and controls
206 lines (165 loc) · 6.3 KB
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
VERSION="2026.05"
DESTDIR ?=
PREFIX ?= /usr/local
NR_CPUS := $(shell grep -c ^processor /proc/cpuinfo)
ifeq ($(CC),)
CC := gcc
endif
CC := $(CROSS_COMPILE)$(CC)
CFLAGS ?= -g -O2 -D_FORTIFY_SOURCE=2
CFLAGS += -Wall -Wextra -I. -Iinclude/ -include config.h -Wimplicit -D_GNU_SOURCE -D__linux__
CCSTD := $(shell if $(CC) -std=gnu11 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-std=gnu11"; else echo "-std=gnu99"; fi)
CFLAGS += $(CCSTD)
ifneq ($(SYSROOT),)
CFLAGS += --sysroot=$(SYSROOT)
endif
#CFLAGS += $(shell if $(CC) -m32 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then echo "-m32"; fi)
CFLAGS += -Wformat=2
CFLAGS += -Winit-self
CFLAGS += -Wnested-externs
CFLAGS += -Wpacked
CFLAGS += -Wshadow
CFLAGS += -Wundef
CFLAGS += -Wwrite-strings
CFLAGS += -Wno-format-nonliteral
CFLAGS += -Wstrict-prototypes -Wmissing-prototypes
CFLAGS += -fsigned-char
# Suppress noisy missing-field-initializer warnings from generated
# BPF/UAPI-style initializers.
CFLAGS += -Wno-missing-field-initializers
# needed for show_backtrace() to work correctly.
LDFLAGS += -rdynamic
# Force eager symbol resolution at exec time (LD_BIND_NOW behaviour).
# Lazy binding walks ld.so's writable link_map. Fuzzed writes can corrupt
# that state, and later _dl_runtime_resolve/dladdr paths may fault before
# child_fault_handler can preserve a useful crash record.
LDFLAGS += -Wl,-z,now
# Runtime tripwire for libc rand(). scripts/check-static/no-libc-rand.sh
# is a build-time grep and can't see rand() that arrives via a macro
# expansion from a system / third-party header. --wrap=rand redirects
# every link-time call to rand() into __wrap_rand in rand/rand-warn.c,
# which prints one warning per process on first hit and forwards to
# __real_rand. srand() is not wrapped -- rand/seed.c uses it
# intentionally for the seed-reproduction path.
LDFLAGS += -Wl,--wrap=rand
# barrier_racer uses process-shared pthread barriers
LDLIBS += -lpthread
# pc_format.c uses dladdr() to resolve PIE-relative offsets
LDLIBS += -ldl
# strategy.c uses sqrt()/log() for the UCB1 bandit picker
LDLIBS += -lm
# gcc only.
ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang"), 0)
CFLAGS += -Wlogical-op
CFLAGS += -Wstrict-aliasing=3
endif
# `make asan` (also `make debug` for backwards-compat) enables
# AddressSanitizer with -Og/-ggdb3 debuginfo. AddressSanitizer catches
# shared-slab freelist overflows at the write site instead of letting
# them surface later as unrelated wild writes. Frame pointers stay
# omitted because the 32-on-64 DO_32_SYSCALL inline asm in
# include/arch-x86-64.h clobbers %rbp; ASAN still produces good
# backtraces from the DWARF info -ggdb3 emits. The trailing -Og
# overrides the earlier -O2; _FORTIFY_SOURCE is undefined because it
# requires optimization.
ifneq ($(filter asan debug,$(MAKECMDGOALS)),)
CFLAGS += -U_FORTIFY_SOURCE -fsanitize=address -Og -ggdb3
LDFLAGS += -fsanitize=address
endif
V = @
Q = $(V:1=)
QUIET_CC = $(Q:@=@echo ' CC '$@;)
all: trinity
asan: trinity
debug: trinity
test:
@if [ ! -f config.h ]; then echo "[1;31mRun ./configure first.[0m" ; exit; fi
MACHINE := $(shell $(CC) -dumpmachine)
SYSCALLS_ARCH := $(shell case "$(MACHINE)" in \
(sh*) echo syscalls/sh/*.c ;; \
(ppc*|powerpc*) echo syscalls/ppc/*.c ;; \
(sparc*) echo syscalls/sparc/*.c ;; \
(x86_64*) echo syscalls/x86/*.c \
syscalls/x86/i386/*.c \
syscalls/x86/x86_64/*.c;; \
(i?86*) echo syscalls/x86/*.c \
syscalls/x86/i386/*.c;; \
(s390x*) echo syscalls/s390x/*.c ;; \
esac)
VERSION_H := include/version.h
HEADERS := $(wildcard *.h) $(wildcard syscalls/*.h) $(wildcard ioctls/*.h)
SRCS := $(wildcard *.c) \
$(wildcard childops/*.c) \
$(wildcard fds/*.c) \
$(wildcard ioctls/*.c) \
$(wildcard lib/*.c) \
$(wildcard mm/*.c) \
$(wildcard net/*.c) \
$(wildcard rand/*.c) \
$(wildcard syscalls/*.c) \
$(SYSCALLS_ARCH)
OBJS := $(sort $(patsubst %.c,%.o,$(wildcard *.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard childops/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard fds/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard ioctls/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard lib/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard mm/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard net/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard rand/*.c))) \
$(sort $(patsubst %.c,%.o,$(wildcard syscalls/*.c))) \
$(sort $(patsubst %.c,%.o,$(SYSCALLS_ARCH)))
DEPDIR= .deps
-include $(SRCS:%.c=$(DEPDIR)/%.d)
$(VERSION_H): scripts/gen-versionh.sh Makefile $(wildcard .git)
@scripts/gen-versionh.sh
trinity: test $(OBJS) $(HEADERS)
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o trinity $(OBJS) $(LDLIBS)
@mkdir -p tmp
df = $(DEPDIR)/$(*D)/$(*F)
%.o : %.c | $(VERSION_H)
$(QUIET_CC)$(CC) $(CFLAGS) -o $@ -c $<
@mkdir -p $(DEPDIR)/$(*D)
@$(CC) -MM $(CFLAGS) $*.c > $(df).d
@mv -f $(df).d $(df).d.tmp
@sed -e 's|.*:|$*.o:|' <$(df).d.tmp > $(df).d
@sed -e 's/.*://' -e 's/\\$$//' < $(df).d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $(df).d
@rm -f $(df).d.tmp
clean:
@rm -f $(OBJS)
@rm -f *.o lib/*.o net/*.o
@rm -f core.*
@rm -f trinity
@rm -f tags
@rm -rf $(DEPDIR)/*
@rm -rf trinity-coverity.tar.xz cov-int
@rm -f $(VERSION_H)
tag:
@git tag -a v$(VERSION) -m "$(VERSION) release."
tarball:
@git archive --format=tar --prefix=trinity-$(VERSION)/ HEAD > trinity-$(VERSION).tar
@xz -9 trinity-$(VERSION).tar
install: trinity
install -d -m 755 $(DESTDIR)$(PREFIX)/bin
install trinity $(DESTDIR)$(PREFIX)/bin
tags: $(SRCS)
@ctags -R --exclude=tmp
scan:
@scan-build --use-analyzer=/usr/bin/clang make -j $(NR_CPUS)
check-static:
@./scripts/check-static.sh
coverity:
@rm -rf cov-int trinity-coverity.tar.xz
@cov-build --dir cov-int make -j $(NR_CPUS)
@tar cJvf trinity-coverity.tar.xz cov-int
# Grant the file capability the parent watchdog needs to read
# /proc/<pid>/stack for the D-state diagnostic snapshot. setcap needs
# root (CAP_SETFCAP), so this is a standalone target:
# make && sudo make setcap
# Re-run after every rebuild -- the security.capability xattr is stripped
# on recompile. Needs an xattr-capable, non-nosuid fs (ext4/xfs/btrfs/
# recent tmpfs; not nfs/overlayfs).
# Depends on the child capability-drop in child.c: forked fuzz children
# must shed CAP_SYS_ADMIN before the fuzz loop, or they run privileged.
setcap:
setcap cap_sys_admin+ep ./trinity