forked from apple/darwin-xnu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
181 lines (147 loc) · 7.33 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
173
174
175
176
177
178
179
180
181
export MakeInc_cmd=${SRCROOT}/makedefs/MakeInc.cmd
export MakeInc_def=${SRCROOT}/makedefs/MakeInc.def
export MakeInc_rule=${SRCROOT}/makedefs/MakeInc.rule
export MakeInc_dir=${SRCROOT}/makedefs/MakeInc.dir
include $(MakeInc_cmd)
include $(MakeInc_def)
MD_SUPPORTED_KPI_FILENAME = SupportedKPIs-${CURRENT_ARCH_CONFIG_LC}.txt
MI_SUPPORTED_KPI_FILENAME = SupportedKPIs-all-archs.txt
INSTALL_KEXT_DIR = $(DSTROOT)$(INSTALL_EXTENSIONS_DIR)
KEXT_PLIST_LIST = \
System.kext/Info.plist \
System.kext/PlugIns/Kasan.kext/Info.plist \
System.kext/PlugIns/AppleNMI.kext/Info.plist \
System.kext/PlugIns/ApplePlatformFamily.kext/Info.plist \
System.kext/PlugIns/IONVRAMFamily.kext/Info.plist \
System.kext/PlugIns/IOSystemManagement.kext/Info.plist
SYMBOL_COMPONENT_LIST = \
BSDKernel \
IOKit \
Libkern \
Mach \
MACFramework \
Unsupported \
Private
SYMBOL_SET_PLIST_COMPONENT_LIST := $(SYMBOL_COMPONENT_LIST) Kasan
# In general you want it to be possible to have a CPU sub-type's symbol exports
# alias to the parent type's exports. This is a special-case way to handle it
# for now:
ifeq ($(CURRENT_ARCH_CONFIG_LC),x86_64h)
EXPORT_SOURCE_ARCH_CONFIG_LC = x86_64
else
EXPORT_SOURCE_ARCH_CONFIG_LC = $(CURRENT_ARCH_CONFIG_LC)
endif
KEXT_MACHO_LIST = $(foreach symbolset,$(filter-out Dummy,$(SYMBOL_COMPONENT_LIST)),System.kext/PlugIns/$(symbolset).kext/$(symbolset))
KEXT_PLIST_LIST += $(foreach symbolset,$(filter-out Dummy,$(SYMBOL_COMPONENT_LIST)),System.kext/PlugIns/$(symbolset).kext/Info.plist)
SYMROOT_INSTALL_KEXT_MACHO_FILES = $(addprefix $(SYMROOT)/,$(KEXT_MACHO_LIST))
DSTROOT_INSTALL_KEXT_MACHO_FILES = $(addprefix $(INSTALL_KEXT_DIR)/,$(KEXT_MACHO_LIST))
SYMROOT_INSTALL_KEXT_PLISTS = $(addprefix $(SYMROOT)/,$(KEXT_PLIST_LIST))
DSTROOT_INSTALL_KEXT_PLISTS = $(addprefix $(INSTALL_KEXT_DIR)/,$(KEXT_PLIST_LIST))
EXPORTS_FILES = $(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(symbolset).exports $(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports $(notdir $(wildcard $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).$(PLATFORM).exports))) Unused.exports
Kasan_EXPORTS := $(SRCROOT)/san/Kasan.exports
ifeq ($(KASAN),1)
Kasan_EXPORTS := $(SRCROOT)/san/Kasan_kasan.exports
endif
SYMBOL_SET_BUILD = $(foreach symbolset, $(SYMBOL_COMPONENT_LIST), $(OBJPATH)/$(symbolset).symbolset)
SYMBOL_SET_PLIST_BUILD = $(foreach symbolset, $(SYMBOL_SET_PLIST_COMPONENT_LIST), $(OBJPATH)/$(symbolset).symbolset.plist)
define symbol_set_rule
$(1)_EXPORTS := $(addprefix $(SOURCE)/,$(filter $(1)%,$(EXPORTS_FILES)))
$(OBJPATH)/$(1).symbolset: MY_EXPORTS_ARGS := $$(foreach file,$$($(1)_EXPORTS),-export $$(file))
$(OBJPATH)/$(1).symbolset: $$($(1)_EXPORTS) $(OBJPATH)/allsymbols $(KEXT_CREATE_SYMBOL_SET)
@$$(LOG_SYMBOLSET) "$(ColorF)$(1)$(Color0) ($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))"
$(_v)$(KEXT_CREATE_SYMBOL_SET) \
$(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \
-import $(OBJPATH)/allsymbols \
$$(MY_EXPORTS_ARGS) \
-output $$@ $(_vstdout)
endef
define symbol_set_plist_rule
$(1)_KEXT_PLIST := $$(filter %/$(1).kext/Info.plist,$$(SYMROOT_INSTALL_KEXT_PLISTS))
$(OBJPATH)/$(1).symbolset.plist: $$($(1)_KEXT_PLIST) $$($(1)_EXPORTS)
@$$(LOG_SYMBOLSETPLIST) "$(ColorF)$(1)$(Color0) ($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))"
$(_v)$(SOURCE)/generate_symbolset_plist.sh $$@ $$+ $(_vstdout)
$(_v)$(PLUTIL) -lint -s $$@
endef
$(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(eval $(call symbol_set_rule,$(symbolset))))
$(foreach symbolset,$(SYMBOL_SET_PLIST_COMPONENT_LIST),$(eval $(call symbol_set_plist_rule,$(symbolset))))
$(OBJPATH)/symbolsets.plist: $(SYMBOL_SET_PLIST_BUILD)
$(_v)$(SOURCE)/generate_combined_symbolsets_plist.sh $@ $^ $(_vstdout)
$(_v)$(PLUTIL) -convert binary1 -s $@
ifneq ($(RC_ProjectName),xnu_libraries)
$(OBJPATH)/allsymbols: $(OBJPATH)/$(KERNEL_FILE_NAME)
$(_v)$(NM) -gj $< | sort -u > $@
.PHONY: check_all_exports
check_all_exports: $(OBJPATH)/allsymbols $(KEXT_CREATE_SYMBOL_SET)
$(_v)$(KEXT_CREATE_SYMBOL_SET) \
$(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \
-import $(OBJPATH)/allsymbols \
$(foreach symbolset,$(filter-out Private,$(SYMBOL_COMPONENT_LIST)), \
-export $(SOURCE)/$(symbolset).exports \
-export $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports) \
-output /dev/null $(_vstdout)
$(_v)$(KEXT_CREATE_SYMBOL_SET) \
$(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \
-import $(OBJPATH)/allsymbols \
$(foreach symbolset,$(filter-out Unsupported,$(SYMBOL_COMPONENT_LIST)), \
-export $(SOURCE)/$(symbolset).exports \
-export $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports) \
-output /dev/null $(_vstdout)
$(OBJPATH)/$(MD_SUPPORTED_KPI_FILENAME): $(EXPORTS_FILES)
@$(LOG_SUPPORTED_KPI) "$(CURRENT_ARCH_CONFIG_LC)"
$(_v)$(SRCROOT)/config/list_supported.sh $(SOURCE) $(EXPORT_SOURCE_ARCH_CONFIG_LC) $@
$(OBJPATH)/$(MI_SUPPORTED_KPI_FILENAME): $(EXPORTS_FILES)
@$(LOG_SUPPORTED_KPI) "all"
$(_v)$(SRCROOT)/config/list_supported.sh $(SOURCE) all $@
build_symbol_sets: check_all_exports $(SYMBOL_SET_BUILD) $(OBJPATH)/allsymbols \
$(OBJPATH)/$(MD_SUPPORTED_KPI_FILENAME) \
$(OBJPATH)/$(MI_SUPPORTED_KPI_FILENAME)
do_config_all:: build_symbol_sets
else
# We are building XNU as a static library - avoid creating symbol sets
endif
# There's no simple static pattern rule for these paths, so hardcode dependencies in the command list
$(SYMROOT_INSTALL_KEXT_MACHO_FILES): ALWAYS
$(_v)$(MKDIR) $(dir $@)
@$(LOG_INSTALLSYM) "symbolset $(notdir $@)$(Color0) ($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))"
$(_v)if [ $(OBJROOT)/.symbolset.timestamp -nt $@ ]; then \
$(INSTALL) $(EXEC_INSTALL_FLAGS) $(OBJPATH)/$(@F).symbolset $@; \
cmdstatus=$$?; \
else \
$(LIPO) -create $@ $(OBJPATH)/$(@F).symbolset -output $@ 2>/dev/null || true; \
cmdstatus=$$?; \
fi; \
exit $$cmdstatus
$(SYMROOT_INSTALL_KEXT_PLISTS): $(SYMROOT)/% : $(SOURCE)/%
$(_v)$(MKDIR) $(dir $@)
@$(LOG_INSTALLSYM) "kextplist$(Color0) $(ColorF)$*"
$(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
$(_v)$(NEWVERS) $@ $(_vstdout)
$(DSTROOT_INSTALL_KEXT_PLISTS): $(INSTALL_KEXT_DIR)/% : $(SYMROOT)/%
$(_v)$(MKDIR) $(dir $@)
@$(LOG_INSTALLSYM) "kextplist$(Color0) $(ColorF)$*"
$(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@
$(DSTROOT_INSTALL_KEXT_MACHO_FILES): $(INSTALL_KEXT_DIR)/% : $(SYMROOT)/% ALWAYS
$(_v)$(MKDIR) $(dir $@)
@$(LOG_INSTALL) "$(notdir $@)$(Color0) ($(ColorLF)$(CURRENT_ARCH_CONFIG_LC)$(Color0))"
$(_v)$(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@
$(DSTROOT)/$(KRESDIR)/$(MD_SUPPORTED_KPI_FILENAME) $(DSTROOT)/$(KRESDIR)/$(MI_SUPPORTED_KPI_FILENAME): $(DSTROOT)/$(KRESDIR)/% : $(OBJPATH)/%
$(_v)$(MKDIR) $(dir $@)
@$(LOG_INSTALL) "$*"
$(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@
ifneq ($(INSTALL_KASAN_ONLY),1)
ifneq ($(BUILD_XNU_LIBRARY),1)
do_config_install:: $(SYMROOT_INSTALL_KEXT_MACHO_FILES) \
$(SYMROOT_INSTALL_KEXT_PLISTS) \
$(DSTROOT_INSTALL_KEXT_MACHO_FILES) \
$(DSTROOT_INSTALL_KEXT_PLISTS) \
$(DSTROOT)/$(KRESDIR)/$(MD_SUPPORTED_KPI_FILENAME) \
$(DSTROOT)/$(KRESDIR)/$(MI_SUPPORTED_KPI_FILENAME)
endif
endif
$(OBJPATH)/all-kpi.exp: $(EXPORTS_FILES)
$(_v)$(SOURCE)/generate_linker_exports.sh $@ $+ $(Kasan_EXPORTS)
$(OBJPATH)/all-alias.exp: $(EXPORTS_FILES)
$(_v)$(SOURCE)/generate_linker_aliases.sh $@ $+ $(Kasan_EXPORTS)
do_build_all:: $(OBJPATH)/all-kpi.exp $(OBJPATH)/all-alias.exp $(OBJPATH)/symbolsets.plist
include $(MakeInc_rule)
include $(MakeInc_dir)