forked from lifting-bits/grr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
172 lines (143 loc) · 6.15 KB
/
Makefile
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
# Copyright 2015 Peter Goodman, all rights reserved.
.PHONY: all clean
GRANARY_CC ?= clang
GRANARY_CXX ?= clang++
# Where is Granary's source code located?
GRANARY_SRC_DIR ?= $(shell pwd)
GRANARY_LIB_DIR := $(GRANARY_SRC_DIR)/third_party
GRANARY_GEN_DIR := $(GRANARY_SRC_DIR)/gen
# What OS are we compiling for?
GRANARY_OS ?= decree
# Where will Granary run? Specify `kernel` for kernel space, and `user` for
# user space.
GRANARY_WHERE ?= user
# What type of build should be perform?
GRANARY_TARGET ?= debug
# Useful for distinguishing different kinds of builds.
GRANARY_TRIPLE := $(GRANARY_TARGET)_$(GRANARY_OS)_$(GRANARY_WHERE)
# Where should we emit object files and the executable?
GRANARY_BIN_DIR ?= $(GRANARY_SRC_DIR)/bin/$(GRANARY_TRIPLE)
# Should we assume that Granary will be executed with Valgrind?
GRANARY_WITH_VALGRIND ?= 0
# Compiler warnings that are explicitly disabled.
GRANARY_DISABLED_WARNINGS := -Wno-gnu-anonymous-struct
GRANARY_DISABLED_WARNINGS += -Wno-gnu-conditional-omitted-operand
GRANARY_DISABLED_WARNINGS += -Wno-long-long
GRANARY_DISABLED_WARNINGS += -Wno-gnu-statement-expression
GRANARY_DISABLED_WARNINGS += -Wno-nested-anon-types
GRANARY_DISABLED_WARNINGS += -Wno-extended-offsetof
GRANARY_DISABLED_WARNINGS += -Wno-c++98-compat-pedantic -Wno-c++98-compat
GRANARY_DISABLED_WARNINGS += -Wno-padded
GRANARY_DISABLED_WARNINGS += -Wno-unused-macros
GRANARY_DISABLED_WARNINGS += -Wno-missing-variable-declarations
GRANARY_DISABLED_WARNINGS += -Wno-missing-prototypes
GRANARY_DISABLED_WARNINGS += -Wno-packed
GRANARY_DISABLED_WARNINGS += -Wno-global-constructors
GRANARY_DISABLED_WARNINGS += -Wno-exit-time-destructors
GRANARY_DISABLED_WARNINGS += -Wno-disabled-macro-expansion
GRANARY_DISABLED_WARNINGS += -Wno-date-time
GRANARY_DISABLED_WARNINGS += -Wno-reserved-id-macro
# Arch-specific flags.
GRANARY_ARCH_FLAGS := -m64 -mtune=generic -fPIC -ffreestanding
GRANARY_ARCH_FLAGS += -ftls-model=initial-exec -mno-red-zone
GRANARY_ARCH_FLAGS += -fno-common -fno-builtin
GRANARY_ARCH_FLAGS += -fno-stack-protector -minline-all-stringops
# Flags that are common to both C and C++ compilers.
GRANARY_COMMON_FLAGS :=
GRANARY_COMMON_FLAGS += -I$(GRANARY_SRC_DIR)
GRANARY_COMMON_FLAGS += -Wall -Werror -Wpedantic
GRANARY_COMMON_FLAGS += $(GRANARY_DISABLED_WARNINGS)
GRANARY_COMMON_FLAGS += -DGRANARY_WHERE_$(GRANARY_WHERE)
GRANARY_COMMON_FLAGS += -DGRANARY_OS_$(GRANARY_OS)
GRANARY_COMMON_FLAGS += -DGRANARY_TARGET_$(GRANARY_TARGET)
GRANARY_COMMON_FLAGS += -DGOOGLE_PROTOBUF_NO_RTTI
GRANARY_SANITIZER ?=
# Optimization and debug information level.
ifeq (debug,$(GRANARY_TARGET))
GRANARY_COMMON_FLAGS += -O0 -g3 -fno-inline
ifneq (,$(GRANARY_SANITIZER))
GRANARY_COMMON_FLAGS += -fsanitize=$(GRANARY_SANITIZER)
endif
else
GRANARY_COMMON_FLAGS += -Oz -g3
endif
# Flags to pass to the various compilers.
GRANARY_CC_FLAGS := -std=c11 $(GRANARY_COMMON_FLAGS) $(GRANARY_ARCH_FLAGS)
GRANARY_CXX_FLAGS := -std=c++11
GRANARY_CXX_FLAGS += $(GRANARY_COMMON_FLAGS) $(GRANARY_ARCH_FLAGS)
GRANARY_CXX_FLAGS += -fno-exceptions -fno-asynchronous-unwind-tables -fno-rtti
GRANARY_CXX_FLAGS += -isystem $(GRANARY_LIB_DIR)/gflags/include
# C, C++, and assembly files in Granary.
GRANARY_SRC_FILES := $(shell find $(GRANARY_SRC_DIR)/granary/ -name '*.cc' -or -name '*.c' -or -name '*.S' -type f)
GRANARY_SRC_FILES += $(shell find $(GRANARY_SRC_DIR)/third_party/ -name '*.cc' -or -name '*.c' -or -name '*.S' -type f)
DUMP_SRC_FILES = $(GRANARY_SRC_DIR)/coverage.cc
DUMP_SRC_FILES += $(GRANARY_SRC_DIR)/granary/code/index.cc
DUMP_SRC_FILES += $(GRANARY_SRC_DIR)/granary/base/breakpoint.cc
DUMP_SRC_FILES += $(GRANARY_SRC_DIR)/granary/base/interrupt.cc
DUMP_SRC_FILES += $(GRANARY_LIB_DIR)/xxhash/xxhash.c
DUMP_OBJECT_FILES := $(addsuffix .o, $(subst $(GRANARY_SRC_DIR),$(GRANARY_BIN_DIR),$(DUMP_SRC_FILES)))
PLAY_SRC_FILES = $(GRANARY_SRC_DIR)/play.cc $(GRANARY_SRC_DIR)/play.cc $(GRANARY_SRC_FILES)
PLAY_OBJECT_FILES := $(addsuffix .o, $(subst $(GRANARY_SRC_DIR),$(GRANARY_BIN_DIR),$(PLAY_SRC_FILES)))
SNAPSHOT_SRC_FILES := $(GRANARY_SRC_DIR)/snapshot.cc
SNAPSHOT_SRC_FILES += $(GRANARY_SRC_DIR)/granary/os/snapshot.cc
SNAPSHOT_SRC_FILES += $(GRANARY_SRC_DIR)/granary/os/decree_user/snapshot.cc
SNAPSHOT_SRC_FILES += $(GRANARY_SRC_DIR)/granary/base/breakpoint.cc
SNAPSHOT_SRC_FILES += $(GRANARY_SRC_DIR)/granary/base/interrupt.cc
SNAPSHOT_OBJ_FILES := $(addsuffix .o, $(subst $(GRANARY_SRC_DIR),$(GRANARY_BIN_DIR),$(SNAPSHOT_SRC_FILES)))
# Compile C++ files to object files.
$(GRANARY_BIN_DIR)/%.pb.cc.o :: $(GRANARY_SRC_DIR)/%.pb.cc
@echo "Building CXX object $@"
@mkdir -p $(@D)
@$(GRANARY_CXX) -Weverything -Wno-sign-conversion -Wno-shorten-64-to-32 $(GRANARY_CXX_FLAGS) -c $< -o $@
# Compile C++ files to object files.
$(GRANARY_BIN_DIR)/%.cc.o :: $(GRANARY_SRC_DIR)/%.cc
@echo "Building CXX object $@"
@mkdir -p $(@D)
@$(GRANARY_CXX) -Weverything $(GRANARY_CXX_FLAGS) -c $< -o $@
# Compile C files to object files.
$(GRANARY_BIN_DIR)/%.c.o :: $(GRANARY_SRC_DIR)/%.c
@echo "Building C object $@"
@mkdir -p $(@D)
@$(GRANARY_CC) $(GRANARY_CC_FLAGS) -c $< -o $@
# Compile assembly files to object files.
$(GRANARY_BIN_DIR)/%.S.o :: $(GRANARY_SRC_DIR)/%.S
@echo "Building ASM object $@"
@mkdir -p $(@D)
@$(GRANARY_CC) $(GRANARY_COMMON_FLAGS) $(GRANARY_ARCH_FLAGS) -c $< -o $@
# Build the Granary executable.
$(GRANARY_BIN_DIR)/grrplay: $(PLAY_OBJECT_FILES)
@echo "Linking $@"
@$(GRANARY_CXX) \
$(GRANARY_CXX_FLAGS) \
-o $@ \
$^ \
$(GRANARY_LIB_DIR)/xed-intel64/lib/libxed.a \
-lgflags \
-lpthread \
# Build the Granary executable.
$(GRANARY_BIN_DIR)/grrshot: $(SNAPSHOT_OBJ_FILES)
@echo "Linking $@"
@$(GRANARY_CXX) \
$(GRANARY_CXX_FLAGS) \
-o $@ \
$^ \
-lpthread \
-lgflags
# Build the program to print out a code cache.
$(GRANARY_BIN_DIR)/grrcov: $(DUMP_OBJECT_FILES)
@echo "Linking $@"
@$(GRANARY_CXX) \
$(GRANARY_CXX_FLAGS) \
-o $@ \
$^ \
-lpthread \
-lgflags
clean:
@rm -rf $(GRANARY_BIN_DIR)
all: $(GRANARY_BIN_DIR)/grrplay $(GRANARY_BIN_DIR)/grrshot $(GRANARY_BIN_DIR)/grrcov
@echo "Done."
install:
mkdir -p $(GRANARY_PREFIX_DIR)/bin
cp $(GRANARY_BIN_DIR)/grrplay $(GRANARY_PREFIX_DIR)/bin
cp $(GRANARY_BIN_DIR)/grrshot $(GRANARY_PREFIX_DIR)/bin
cp $(GRANARY_BIN_DIR)/grrcov $(GRANARY_PREFIX_DIR)/bin