-
Notifications
You must be signed in to change notification settings - Fork 4
/
spi.target.mk
247 lines (204 loc) · 7.77 KB
/
spi.target.mk
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
INJECTOR = injector.exe
IJAGENT = libijagent.so
GETPIDFROMPORT = getpidfromport
ifeq ($(DYNLINK), false)
AGENT = libagent.a
else
AGENT = libagent.so
endif
all: test injector_exe agent_lib
spi: injector_exe agent_lib
GCC = gcc
GXX = g++
RM = rm -f
MKDIR = mkdir -p
VPATH = $(AG_DIR) \
$(AG_DIR)/inst_workers \
$(AG_DIR)/ipc \
$(AG_DIR)/ipc/ipc_workers \
$(AG_DIR)/patchapi \
$(IJ_DIR) \
$(UTILS_DIR) \
#======================================
# Utils
#======================================
UTILS_SRCS += $(UTILS_DIR)/utils.cc
UTILS_OBJS += $(addprefix $(OBJS_DIR)/, $(notdir $(UTILS_SRCS:%.cc=%.o)))
$(UTILS_OBJS): $(OBJS_DIR)/%.o : %.cc
@echo Compiling $*.o
@$(MKDIR) $(OBJS_DIR)
@$(GCC) -c -o $@ $(COMMON_IFLAGS) $(COMMON_FLAGS) $<
#======================================
# Injector
#======================================
injector_exe: $(INJECTOR) $(IJAGENT) $(GETPIDFROMPORT)
$(GETPIDFROMPORT): $(IJ_DIR)/getpidfromport.cc
g++ -o $(GETPIDFROMPORT) $(IJ_DIR)/getpidfromport.cc
#----------------
# injector objs
#----------------
IJ_SRCS += $(IJ_DIR)/injector.cc
IJ_OBJS += $(addprefix $(OBJS_DIR)/, $(notdir $(IJ_SRCS:%.cc=%.o)))
IJ_DEP = .IJ_DEPENDS
$(shell if test -f $(IJ_DEP); then true; else \
$(GXX) -MM $(IJ_IFLAGS) $(IJ_FLAGS) $(IJ_SRCS) > /tmp/t; \
perl -ane 'print "\$(OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(IJ_DEP); \
fi);
include $(IJ_DEP)
$(IJ_OBJS): $(OBJS_DIR)/%.o : %.cc
@echo Compiling $*.o
@$(MKDIR) $(OBJS_DIR)
@$(GXX) -c -o $@ $(IJ_IFLAGS) $(IJ_FLAGS) $<
#----------------
# Injector Exe
#----------------
IJMAIN_SRCS += $(IJ_DIR)/injector_main.cc
IJMAIN_OBJS +=
IJMAIN_OBJS += $(addprefix $(OBJS_DIR)/, $(notdir $(IJMAIN_SRCS:%.cc=%.o)))
IJMAIN_DEP = .IJMAIN_DEPENDS
$(shell if test -f $(IJMAIN_DEP); then true; else \
$(GXX) -MM $(IJ_IFLAGS) $(IJ_FLAGS) $(IJMAIN_SRCS) > /tmp/t; \
perl -ane 'print "\$(OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(IJMAIN_DEP); \
fi);
include $(IJMAIN_DEP)
$(IJMAIN_OBJS): $(OBJS_DIR)/%.o : %.cc
@echo Compiling $*.o
@$(MKDIR) $(OBJS_DIR)
@$(GXX) -c -o $@ $(IJ_IFLAGS) $(IJ_FLAGS) $<
$(INJECTOR): $(IJMAIN_OBJS) $(IJ_OBJS) $(UTILS_OBJS)
@echo Linking $@
@$(GXX) -o $@ $(IJMAIN_OBJS) $(IJ_OBJS) $(UTILS_OBJS) $(IJ_LDFLAGS)
@rm -f injector
@echo "export LD_LIBRARY_PATH=$(SP_DIR)/$(PLATFORM):$(SP_DIR)/$(PLATFORM)/test_mutatee:$(DYNINST_DIR)/lib:./:\$$LD_LIBRARY_PATH" > injector
@echo "export SP_DIR=$(SP_DIR)" >> injector
@echo "$(SP_DIR)/$(PLATFORM)/$(INJECTOR) \$$1 \$$2 \$$3 \$$4 \$$5" >> injector
@chmod 755 injector
#----------------
# libijagent.so
#----------------
IJA_SRCS += $(IJ_DIR)/ijagent.c
IJA_OBJS = $(addprefix $(OBJS_DIR)/, $(notdir $(IJA_SRCS:%.c=%.o)))
$(IJA_OBJS): $(OBJS_DIR)/%.o : $(IJ_DIR)/%.c
@echo Compiling $*.o
@$(MKDIR) $(OBJS_DIR)
@$(GCC) -c -o $@ $(IJA_IFLAGS) $(IJA_FLAGS) $(IJ_DIR)/$*.c
$(IJAGENT): $(IJA_OBJS)
@echo Linking $@
@$(GCC) -o $@ $(IJA_OBJS) $(IJA_LDFLAGS)
#======================================
# Agent
#======================================
AG_SRCS += $(AG_DIR)/agent.cc \
$(AG_DIR)/context.cc \
$(AG_DIR)/event.cc \
$(AG_DIR)/parser.cc \
$(AG_DIR)/payload.cc \
$(AG_DIR)/propeller.cc \
$(AG_DIR)/inst_workers/trap_worker_impl.cc \
$(AG_DIR)/inst_workers/callinsn_worker_impl.cc \
$(AG_DIR)/inst_workers/callblk_worker_impl.cc \
$(AG_DIR)/inst_workers/spring_worker_impl.cc \
$(AG_DIR)/ipc/channel.cc \
$(AG_DIR)/ipc/ipc_mgr.cc \
$(AG_DIR)/ipc/ipc_workers/ipc_worker_delegate.cc \
$(AG_DIR)/ipc/ipc_workers/pipe_worker_impl.cc \
$(AG_DIR)/ipc/ipc_workers/tcp_worker_impl.cc \
$(AG_DIR)/ipc/ipc_workers/udp_worker_impl.cc \
$(AG_DIR)/patchapi/addr_space.cc \
$(AG_DIR)/patchapi/cfg.cc \
$(AG_DIR)/patchapi/instrumenter.cc \
$(AG_DIR)/patchapi/maker.cc \
$(AG_DIR)/patchapi/point.cc \
$(AG_DIR)/snippet.cc \
$(AG_DIR)/thread_mgr.cc \
AG_OBJS = $(addprefix $(OBJS_DIR)/, $(notdir $(AG_SRCS:%.cc=%.o)))
AG_DEP = .AG_DEPENDS
$(shell if test -f $(AG_DEP); then true; else \
$(GXX) -MM $(AG_IFLAGS) $(AG_FLAGS) $(AG_SRCS) > /tmp/t;\
perl -ane 'print "\$(OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(AG_DEP);\
fi);
include $(AG_DEP)
agent_lib: $(AGENT)
$(AG_OBJS): $(OBJS_DIR)/%.o : %.cc
@echo Compiling $*.o
@$(MKDIR) $(OBJS_DIR)
@$(GXX) -c -o $@ $(AG_IFLAGS) $(AG_FLAGS) $<
$(AGENT): $(AG_OBJS) $(IJ_OBJS) $(UTILS_OBJS)
ifeq ($(DYNLINK), true)
@echo Dynamic Linking $@
@$(GXX) -o $@ $(AG_OBJS) $(IJ_OBJS) $(UTILS_OBJS) $(AG_LDFLAGS) $(IJ_LDFLAGS) -shared
else
@echo Static Linking $@
@ar rs $@ $(AG_OBJS) $(IJ_OBJS) $(UTILS_OBJS)
endif
#======================================
# Unit Tests
#======================================
include $(SP_DIR)/test.target.mk
#=================================================
# build dyninst
# XXX: Not used so far ...
#=================================================
DYN_OBJS += $(wildcard $(DYNINST_DIR)/common/$(PLATFORM)/*.o)
DYN_OBJS += $(wildcard $(DYNINST_DIR)/instructionAPI/$(PLATFORM)/*.o)
DYN_OBJS += $(wildcard $(DYNINST_DIR)/parseAPI/$(PLATFORM)/*.o)
DYN_OBJS += $(wildcard $(DYNINST_DIR)/patchAPI/$(PLATFORM)/*.o)
DYN_OBJS += $(wildcard $(DYNINST_DIR)/proccontrol/$(PLATFORM)/*.o)
DYN_OBJS += $(wildcard $(DYNINST_DIR)/stackwalk/$(PLATFORM)/*.o)
DYN_OBJS += $(wildcard $(DYNINST_DIR)/symtabAPI/$(PLATFORM)/*.o)
build_dyninst: $(DYN_OBJS)
ar rs dyninst.a $(DYN_OBJS)
#=================================================
# depend
#=================================================
depend:
@echo "Building dependency ..."
@$(GXX) -MM $(AG_IFLAGS) $(AG_FLAGS) $(AG_SRCS) > /tmp/t
@perl -ane 'print "\$(OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(AG_DEP)
@$(GXX) -MM $(IJ_IFLAGS) $(IJ_FLAGS) $(IJMAIN_SRCS) > /tmp/t
@perl -ane 'print "\$(OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(IJMAIN_DEP)
@$(GXX) -MM $(IJ_IFLAGS) $(IJ_FLAGS) $(IJ_SRCS) > /tmp/t
@perl -ane 'print "\$(OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(IJ_DEP)
@$(GXX) -MM $(TG_FLAGS) $(TG_SRCS) > /tmp/t
@perl -ane 'print "\$(TAGENT_OBJS_DIR)/" if/\w+.o: /; print;' < /tmp/t > $(TAGENT_DEP)
#=================================================
# Others
#=================================================
clean_objs:
$(RM) -r $(OBJS_DIR)
clean:
@echo "Cleaning all except for dependencies ..."
@$(RM) -r $(INJECTOR) $(AGENT) $(IJAGENT) *.o *.so *.a $(OBJS_DIR)
clean_all:
@echo "Cleaning all ..."
@$(RM) -r $(INJECTOR) $(AGENT) $(IJAGENT) *.o *.so *.a $(OBJS_DIR)
@$(RM) $(IJ_DEP) $(IJMAIN_DEP) $(AG_DEP) $(TAGENT_DEP)
@$(RM) -r $(TEST_EXES_DIR) $(UT_ONESTOP_EXE)
@$(RM) -r $(MUTATEE_EXES_DIR)
@$(RM) -r $(TAGENT_EXES_DIR)
@$(RM) -r $(TEST_DATA_DIR)
clean_test:
@echo "Cleaning tests ..."
@$(RM) -r $(TEST_EXES_DIR) $(UT_ONESTOP_EXE)
@$(RM) -r $(MUTATEE_EXES_DIR)
@$(RM) -r $(TAGENT_EXES_DIR)
@$(RM) -r $(TEST_DATA_DIR)
msg: agent_lib injector_exe
@echo ""
@echo ""
@echo " Successfully built ..."
@echo " Please set the environment variable SP_DIR to -- "
@echo " $(SP_DIR) "
@echo ""
help:
@echo "make options:"
@echo "-- make: build everything"
@echo "-- make all: build everything"
@echo "-- make test: build testsuite"
@echo "-- make spi: build injector and agent library"
@echo "-- make injector_exe: build injector"
@echo "-- make agent_lib: build agent library"
@echo "-- make depend: build dependencies"
@echo "-- make clean: clean all but dependencies and external testing mutatees"
@echo "-- make clean_objs: clean all object files"
@echo "-- make clean_all: clean all but external testing mutatees"