1*4f1223e8SApple OSS Distributionsexport MakeInc_cmd=${SRCROOT}/makedefs/MakeInc.cmd 2*4f1223e8SApple OSS Distributionsexport MakeInc_def=${SRCROOT}/makedefs/MakeInc.def 3*4f1223e8SApple OSS Distributionsexport MakeInc_rule=${SRCROOT}/makedefs/MakeInc.rule 4*4f1223e8SApple OSS Distributionsexport MakeInc_dir=${SRCROOT}/makedefs/MakeInc.dir 5*4f1223e8SApple OSS Distributions 6*4f1223e8SApple OSS Distributionsinclude $(MakeInc_cmd) 7*4f1223e8SApple OSS Distributionsinclude $(MakeInc_def) 8*4f1223e8SApple OSS Distributions 9*4f1223e8SApple OSS Distributions# config is not a COMPONENT but we still want to build most files in a TARGET subdir 10*4f1223e8SApple OSS Distributionsoverride TARGET := $(OBJPATH)/config 11*4f1223e8SApple OSS Distributions 12*4f1223e8SApple OSS DistributionsMD_SUPPORTED_KPI_FILENAME := SupportedKPIs-${CURRENT_ARCH_CONFIG_LC}.txt 13*4f1223e8SApple OSS DistributionsMI_SUPPORTED_KPI_FILENAME := SupportedKPIs-all-archs.txt 14*4f1223e8SApple OSS Distributions 15*4f1223e8SApple OSS DistributionsINSTALL_KEXT_DIR = $(DSTROOT)$(INSTALL_EXTENSIONS_DIR) 16*4f1223e8SApple OSS Distributions 17*4f1223e8SApple OSS DistributionsKEXT_PLIST_LIST := \ 18*4f1223e8SApple OSS Distributions System.kext/Info.plist \ 19*4f1223e8SApple OSS Distributions System.kext/PlugIns/Kasan.kext/Info.plist \ 20*4f1223e8SApple OSS Distributions System.kext/PlugIns/Kcov.kext/Info.plist \ 21*4f1223e8SApple OSS Distributions System.kext/PlugIns/AppleNMI.kext/Info.plist \ 22*4f1223e8SApple OSS Distributions System.kext/PlugIns/ApplePlatformFamily.kext/Info.plist \ 23*4f1223e8SApple OSS Distributions System.kext/PlugIns/IONVRAMFamily.kext/Info.plist \ 24*4f1223e8SApple OSS Distributions System.kext/PlugIns/IOSystemManagement.kext/Info.plist 25*4f1223e8SApple OSS Distributions 26*4f1223e8SApple OSS DistributionsSYMBOL_COMPONENT_LIST := \ 27*4f1223e8SApple OSS Distributions BSDKernel \ 28*4f1223e8SApple OSS Distributions IOKit \ 29*4f1223e8SApple OSS Distributions Libkern \ 30*4f1223e8SApple OSS Distributions Mach \ 31*4f1223e8SApple OSS Distributions MACFramework \ 32*4f1223e8SApple OSS Distributions Unsupported \ 33*4f1223e8SApple OSS Distributions Private 34*4f1223e8SApple OSS Distributions 35*4f1223e8SApple OSS DistributionsSYMBOL_SET_PLIST_COMPONENT_LIST := $(SYMBOL_COMPONENT_LIST) Kasan Kcov 36*4f1223e8SApple OSS Distributions 37*4f1223e8SApple OSS DistributionsKEXT_PLIST_LIST += $(foreach symbolset,$(SYMBOL_COMPONENT_LIST),System.kext/PlugIns/$(symbolset).kext/Info.plist) 38*4f1223e8SApple OSS Distributions 39*4f1223e8SApple OSS Distributions# In general you want it to be possible to have a CPU sub-type's symbol exports 40*4f1223e8SApple OSS Distributions# alias to the parent type's exports. This is a special-case way to handle it 41*4f1223e8SApple OSS Distributions# for now: 42*4f1223e8SApple OSS Distributionsifeq ($(CURRENT_ARCH_CONFIG_LC),x86_64h) 43*4f1223e8SApple OSS DistributionsEXPORT_SOURCE_ARCH_CONFIG_LC := x86_64 44*4f1223e8SApple OSS Distributionselse 45*4f1223e8SApple OSS DistributionsEXPORT_SOURCE_ARCH_CONFIG_LC := $(CURRENT_ARCH_CONFIG_LC) 46*4f1223e8SApple OSS Distributionsendif 47*4f1223e8SApple OSS Distributions 48*4f1223e8SApple OSS DistributionsEXPORTS_FILES := $(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(symbolset).exports \ 49*4f1223e8SApple OSS Distributions $(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports \ 50*4f1223e8SApple OSS Distributions $(notdir $(wildcard $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).$(PLATFORM).exports))) \ 51*4f1223e8SApple OSS Distributions Unused.exports 52*4f1223e8SApple OSS DistributionsEXPORTS_FILES += Private.Tightbeam.exports 53*4f1223e8SApple OSS Distributions 54*4f1223e8SApple OSS Distributions 55*4f1223e8SApple OSS DistributionsKasan_EXPORTS := $(SRCROOT)/config/Kasan_disabled.exports 56*4f1223e8SApple OSS DistributionsKcov_EXPORTS := $(SRCROOT)/config/Kcov_disabled.exports 57*4f1223e8SApple OSS Distributions 58*4f1223e8SApple OSS Distributionsifneq ($(filter $(CURRENT_KERNEL_CONFIG),$(KCOV_RUNTIME)),) 59*4f1223e8SApple OSS DistributionsKcov_EXPORTS := $(SRCROOT)/config/Kcov_enabled.exports 60*4f1223e8SApple OSS Distributionsendif 61*4f1223e8SApple OSS Distributions 62*4f1223e8SApple OSS Distributionsifeq ($(KASAN),1) 63*4f1223e8SApple OSS Distributionsifeq ($(CURRENT_ARCH_CONFIG_LC),x86_64h) 64*4f1223e8SApple OSS DistributionsKASAN_ARCH_SUFFIX := x86_64 65*4f1223e8SApple OSS Distributionselse 66*4f1223e8SApple OSS DistributionsKASAN_ARCH_SUFFIX := $(CURRENT_ARCH_CONFIG_LC) 67*4f1223e8SApple OSS Distributionsendif 68*4f1223e8SApple OSS DistributionsKasan_EXPORTS := $(SRCROOT)/config/Kasan_enabled.$(KASAN_ARCH_SUFFIX).exports 69*4f1223e8SApple OSS Distributionsendif 70*4f1223e8SApple OSS Distributions 71*4f1223e8SApple OSS Distributionsdefine symbol_set_template 72*4f1223e8SApple OSS Distributions$(1)_EXPORTS := $$(addprefix $$(SOURCE)/,$$(filter $(1)%,$$(EXPORTS_FILES))) 73*4f1223e8SApple OSS Distributions$$(TARGET)/$(1).symbolset: MY_EXPORTS_ARGS := $$(foreach file,$$($(1)_EXPORTS),-export $$(file)) 74*4f1223e8SApple OSS Distributions$$(TARGET)/$(1).symbolset: $$($(1)_EXPORTS) $$(TARGET)/allsymbols $$(KEXT_CREATE_SYMBOL_SET) 75*4f1223e8SApple OSS Distributions @$$(LOG_SYMBOLSET) "$(1)$$(Color0) ($$(ColorLF)$$(CURRENT_ARCH_CONFIG_LC)$$(Color0))" 76*4f1223e8SApple OSS Distributions $$(_v)$$(KEXT_CREATE_SYMBOL_SET) \ 77*4f1223e8SApple OSS Distributions $$(ARCH_FLAGS_$$(CURRENT_ARCH_CONFIG)) \ 78*4f1223e8SApple OSS Distributions -import $$(TARGET)/allsymbols \ 79*4f1223e8SApple OSS Distributions $$(MY_EXPORTS_ARGS) \ 80*4f1223e8SApple OSS Distributions -output $$@ $$(_vstdout) 81*4f1223e8SApple OSS Distributions 82*4f1223e8SApple OSS DistributionsSYMBOL_SET_BUILD += $$(TARGET)/$(1).symbolset 83*4f1223e8SApple OSS Distributionsendef 84*4f1223e8SApple OSS Distributions 85*4f1223e8SApple OSS Distributions# Each parallel invocation of this target must use a distinct location, as it is 86*4f1223e8SApple OSS Distributions# not safe to call multiple NEWVERS on the same file concurrently (rdar://66173684) 87*4f1223e8SApple OSS Distributionsdefine kext_plist_template 88*4f1223e8SApple OSS Distributions$$(TARGET)/$(1): $$(SOURCE)/$(1) $$(NEWVERS) $$(XNU_VERSION) 89*4f1223e8SApple OSS Distributions @$$(LOG_GENERATE) "$(1)" 90*4f1223e8SApple OSS Distributions $$(_v)$$(MKDIR) $$(@D) 91*4f1223e8SApple OSS Distributions $$(_v)$$(CP) $$< $$@ 92*4f1223e8SApple OSS Distributions $$(_v)$$(NEWVERS) $$@ > /dev/null 93*4f1223e8SApple OSS Distributions 94*4f1223e8SApple OSS DistributionsKEXT_PLIST_BUILD += $$(TARGET)/$(1) 95*4f1223e8SApple OSS DistributionsSYMROOT_INSTALL_KEXT_PLISTS += $$(SYMROOT)/$(1) 96*4f1223e8SApple OSS DistributionsDSTROOT_INSTALL_KEXT_PLISTS += $$(INSTALL_KEXT_DIR)/$(1) 97*4f1223e8SApple OSS Distributionsendef 98*4f1223e8SApple OSS Distributions 99*4f1223e8SApple OSS Distributionsdefine symbol_set_plist_template 100*4f1223e8SApple OSS Distributions$(1)_KEXT_PLIST := $$(filter %/$(1).kext/Info.plist,$$(KEXT_PLIST_LIST)) 101*4f1223e8SApple OSS Distributions$$(TARGET)/$(1).symbolset.plist: $$(TARGET)/$$($(1)_KEXT_PLIST) $$($(1)_EXPORTS) 102*4f1223e8SApple OSS Distributions @$$(LOG_SYMBOLSETPLIST) "$(1)$$(Color0) ($$(ColorLF)$$(CURRENT_ARCH_CONFIG_LC)$$(Color0))" 103*4f1223e8SApple OSS Distributions $$(_v)$$(SOURCE)/generate_symbolset_plist.sh $$@ $$+ $$(_vstdout) 104*4f1223e8SApple OSS Distributions $$(_v)$$(PLUTIL) -lint -s $$@ 105*4f1223e8SApple OSS Distributions 106*4f1223e8SApple OSS DistributionsSYMBOL_SET_PLIST_BUILD += $$(TARGET)/$(1).symbolset.plist 107*4f1223e8SApple OSS Distributionsendef 108*4f1223e8SApple OSS Distributions 109*4f1223e8SApple OSS Distributions$(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(eval $(call symbol_set_template,$(symbolset)))) 110*4f1223e8SApple OSS Distributions$(foreach plist,$(KEXT_PLIST_LIST),$(eval $(call kext_plist_template,$(plist)))) 111*4f1223e8SApple OSS Distributions$(foreach symbolset,$(SYMBOL_SET_PLIST_COMPONENT_LIST),$(eval $(call symbol_set_plist_template,$(symbolset)))) 112*4f1223e8SApple OSS Distributions 113*4f1223e8SApple OSS Distributions$(OBJPATH)/symbolsets.plist: $(SYMBOL_SET_PLIST_BUILD) 114*4f1223e8SApple OSS Distributions $(_v)$(SOURCE)/generate_combined_symbolsets_plist.sh $@ $^ $(_vstdout) 115*4f1223e8SApple OSS Distributions $(_v)$(PLUTIL) -convert binary1 -s $@ 116*4f1223e8SApple OSS Distributions 117*4f1223e8SApple OSS Distributionsbuild_symbol_set_plists: $(KEXT_PLIST_BUILD) $(OBJPATH)/symbolsets.plist 118*4f1223e8SApple OSS Distributions 119*4f1223e8SApple OSS Distributions$(TARGET)/allsymbols: $(OBJPATH)/$(KERNEL_FILE_NAME) 120*4f1223e8SApple OSS Distributions $(_v)$(NM) -gj $< | sort -u > $@ 121*4f1223e8SApple OSS Distributions 122*4f1223e8SApple OSS Distributionscheck_all_exports: $(TARGET)/allsymbols $(KEXT_CREATE_SYMBOL_SET) 123*4f1223e8SApple OSS Distributions $(_v)$(KEXT_CREATE_SYMBOL_SET) \ 124*4f1223e8SApple OSS Distributions $(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \ 125*4f1223e8SApple OSS Distributions -import $(TARGET)/allsymbols \ 126*4f1223e8SApple OSS Distributions $(foreach symbolset,$(filter-out Private,$(SYMBOL_COMPONENT_LIST)), \ 127*4f1223e8SApple OSS Distributions -export $(SOURCE)/$(symbolset).exports \ 128*4f1223e8SApple OSS Distributions -export $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports) \ 129*4f1223e8SApple OSS Distributions -output /dev/null $(_vstdout) 130*4f1223e8SApple OSS Distributions $(_v)$(KEXT_CREATE_SYMBOL_SET) \ 131*4f1223e8SApple OSS Distributions $(ARCH_FLAGS_$(CURRENT_ARCH_CONFIG)) \ 132*4f1223e8SApple OSS Distributions -import $(TARGET)/allsymbols \ 133*4f1223e8SApple OSS Distributions $(foreach symbolset,$(filter-out Unsupported,$(SYMBOL_COMPONENT_LIST)), \ 134*4f1223e8SApple OSS Distributions -export $(SOURCE)/$(symbolset).exports \ 135*4f1223e8SApple OSS Distributions -export $(SOURCE)/$(symbolset).$(EXPORT_SOURCE_ARCH_CONFIG_LC).exports) \ 136*4f1223e8SApple OSS Distributions -output /dev/null $(_vstdout) 137*4f1223e8SApple OSS Distributions 138*4f1223e8SApple OSS Distributions$(OBJPATH)/$(MD_SUPPORTED_KPI_FILENAME): $(EXPORTS_FILES) 139*4f1223e8SApple OSS Distributions @$(LOG_SUPPORTED_KPI) "$(CURRENT_ARCH_CONFIG_LC)" 140*4f1223e8SApple OSS Distributions $(_v)$(SRCROOT)/config/list_supported.sh $(SOURCE) $(EXPORT_SOURCE_ARCH_CONFIG_LC) $@ 141*4f1223e8SApple OSS Distributions 142*4f1223e8SApple OSS Distributions$(OBJPATH)/$(MI_SUPPORTED_KPI_FILENAME): $(EXPORTS_FILES) 143*4f1223e8SApple OSS Distributions @$(LOG_SUPPORTED_KPI) "all" 144*4f1223e8SApple OSS Distributions $(_v)$(SRCROOT)/config/list_supported.sh $(SOURCE) all $@ 145*4f1223e8SApple OSS Distributions 146*4f1223e8SApple OSS Distributionsbuild_symbol_sets: check_all_exports $(SYMBOL_SET_BUILD) $(TARGET)/allsymbols \ 147*4f1223e8SApple OSS Distributions $(OBJPATH)/$(MD_SUPPORTED_KPI_FILENAME) \ 148*4f1223e8SApple OSS Distributions $(OBJPATH)/$(MI_SUPPORTED_KPI_FILENAME) 149*4f1223e8SApple OSS Distributions 150*4f1223e8SApple OSS Distributions# Generate rules for symroot fat kexts with dependencies on every corresponding symbolset for each build config. 151*4f1223e8SApple OSS Distributions# This target must only run from do_config_install for a single build config after the do_config_all phases for 152*4f1223e8SApple OSS Distributions# all build configs have completed. This ensures every unique slice built by any config is pulled into the fat 153*4f1223e8SApple OSS Distributions# symbolset kext (note that not all slices are reflected as distinct xnu build config ARCHS!) (rdar://70703349) 154*4f1223e8SApple OSS Distributionsdefine symroot_symbol_set_template 155*4f1223e8SApple OSS Distributions$$(SYMROOT_SYSTEM_KEXT_PATH)/$(1).kext/$(1): $$(addsuffix /config/$(1).symbolset, \ 156*4f1223e8SApple OSS Distributions $$(addprefix $$(OBJROOT)/,$$(foreach bc,$(BUILD_CONFIGS),$$(call function_convert_build_config_to_objdir,$$(bc))))) 157*4f1223e8SApple OSS Distributions @$$(LOG_INSTALLSYM) "$$(Color0)symbolset $$(ColorF)$(1)" 158*4f1223e8SApple OSS Distributions $$(_v)$$(MKDIR) $$(@D) 159*4f1223e8SApple OSS Distributions $$(_v)$$(LIPO) -create `(echo $$^ | xargs -L 1 lipo -detailed_info) | \ 160*4f1223e8SApple OSS Distributions awk '/is architecture/ {s[$$$$6]=$$$$3} END {for (a in s) {print s[a]}}'` -output $$@ $$(_vstdout) 161*4f1223e8SApple OSS Distributions 162*4f1223e8SApple OSS DistributionsSYMROOT_INSTALL_KEXT_MACHO_FILES += $$(SYMROOT_SYSTEM_KEXT_PATH)/$(1).kext/$(1) 163*4f1223e8SApple OSS DistributionsDSTROOT_INSTALL_KEXT_MACHO_FILES += $$(DSTROOT_SYSTEM_KEXT_PATH)/$(1).kext/$(1) 164*4f1223e8SApple OSS Distributionsendef 165*4f1223e8SApple OSS Distributions$(foreach symbolset,$(SYMBOL_COMPONENT_LIST),$(eval $(call symroot_symbol_set_template,$(symbolset)))) 166*4f1223e8SApple OSS Distributions 167*4f1223e8SApple OSS Distributions$(SYMROOT_INSTALL_KEXT_PLISTS): $(SYMROOT)/% : $(TARGET)/% 168*4f1223e8SApple OSS Distributions $(_v)$(MKDIR) $(@D) 169*4f1223e8SApple OSS Distributions @$(LOG_INSTALLSYM) "$(Color0)kextplist $(ColorF)$*" 170*4f1223e8SApple OSS Distributions $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@ 171*4f1223e8SApple OSS Distributions 172*4f1223e8SApple OSS Distributions$(DSTROOT_INSTALL_KEXT_PLISTS): $(INSTALL_KEXT_DIR)/% : $(SYMROOT)/% 173*4f1223e8SApple OSS Distributions $(_v)$(MKDIR) $(@D) 174*4f1223e8SApple OSS Distributions @$(LOG_INSTALL) "$(Color0)kextplist $(ColorF)$*" 175*4f1223e8SApple OSS Distributions $(_v)$(INSTALL) $(DATA_INSTALL_FLAGS) $< $@ 176*4f1223e8SApple OSS Distributions 177*4f1223e8SApple OSS Distributions$(DSTROOT_INSTALL_KEXT_MACHO_FILES): $(DSTROOT_SYSTEM_KEXT_PATH)/% : $(SYMROOT_SYSTEM_KEXT_PATH)/% 178*4f1223e8SApple OSS Distributions $(_v)$(MKDIR) $(@D) 179*4f1223e8SApple OSS Distributions @$(LOG_INSTALL) "$(Color0)symbolset $(ColorF)$(@F)" 180*4f1223e8SApple OSS Distributions $(_v)$(INSTALL) $(EXEC_INSTALL_FLAGS) $< $@ 181*4f1223e8SApple OSS Distributions 182*4f1223e8SApple OSS Distributions$(DSTROOT)/$(KRESDIR)/$(MD_SUPPORTED_KPI_FILENAME) $(DSTROOT)/$(KRESDIR)/$(MI_SUPPORTED_KPI_FILENAME): $(DSTROOT)/$(KRESDIR)/% : $(OBJPATH)/% 183*4f1223e8SApple OSS Distributions $(_v)$(MKDIR) $(@D) 184*4f1223e8SApple OSS Distributions @$(LOG_INSTALL) "$*" 185*4f1223e8SApple OSS Distributions $(_v)$(INSTALL) $(INSTALL_FLAGS) $< $@ 186*4f1223e8SApple OSS Distributions 187*4f1223e8SApple OSS Distributionsifneq ($(RC_ProjectName),xnu_libraries) 188*4f1223e8SApple OSS Distributions 189*4f1223e8SApple OSS Distributionsdo_build_all:: build_symbol_set_plists 190*4f1223e8SApple OSS Distributionsdo_config_all:: build_symbol_sets 191*4f1223e8SApple OSS Distributions 192*4f1223e8SApple OSS Distributionsifneq ($(INSTALL_KASAN_ONLY),1) 193*4f1223e8SApple OSS Distributions 194*4f1223e8SApple OSS Distributionsdo_config_install_primary:: \ 195*4f1223e8SApple OSS Distributions $(DSTROOT)/$(KRESDIR)/$(MD_SUPPORTED_KPI_FILENAME) 196*4f1223e8SApple OSS Distributions 197*4f1223e8SApple OSS Distributionsdo_config_install:: \ 198*4f1223e8SApple OSS Distributions $(SYMROOT_INSTALL_KEXT_MACHO_FILES) \ 199*4f1223e8SApple OSS Distributions $(SYMROOT_INSTALL_KEXT_PLISTS) \ 200*4f1223e8SApple OSS Distributions $(DSTROOT_INSTALL_KEXT_MACHO_FILES) \ 201*4f1223e8SApple OSS Distributions $(DSTROOT_INSTALL_KEXT_PLISTS) \ 202*4f1223e8SApple OSS Distributions $(DSTROOT)/$(KRESDIR)/$(MI_SUPPORTED_KPI_FILENAME) 203*4f1223e8SApple OSS Distributionsendif 204*4f1223e8SApple OSS Distributions 205*4f1223e8SApple OSS Distributionselse 206*4f1223e8SApple OSS Distributions# We are building XNU as a static library - avoid creating symbol sets 207*4f1223e8SApple OSS Distributionsendif 208*4f1223e8SApple OSS Distributions 209*4f1223e8SApple OSS Distributions$(OBJPATH)/all-kpi.exp: $(EXPORTS_FILES) 210*4f1223e8SApple OSS Distributions $(_v)$(SOURCE)/generate_linker_exports.sh $@ $+ $(Kasan_EXPORTS) $(Kcov_EXPORTS) 211*4f1223e8SApple OSS Distributions 212*4f1223e8SApple OSS Distributions$(OBJPATH)/all-alias.exp: $(EXPORTS_FILES) 213*4f1223e8SApple OSS Distributions $(_v)$(SOURCE)/generate_linker_aliases.sh $@ $+ $(Kasan_EXPORTS) $(Kcov_EXPORTS) 214*4f1223e8SApple OSS Distributions 215*4f1223e8SApple OSS Distributionsdo_build_all:: $(OBJPATH)/all-kpi.exp $(OBJPATH)/all-alias.exp 216*4f1223e8SApple OSS Distributions 217*4f1223e8SApple OSS Distributionsinclude $(MakeInc_rule) 218*4f1223e8SApple OSS Distributionsinclude $(MakeInc_dir) 219*4f1223e8SApple OSS Distributions 220*4f1223e8SApple OSS Distributions.PHONY: build_symbol_set_plists build_symbol_sets check_all_exports 221