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