xref: /xnu-11215.1.10/makedefs/MakeInc.def (revision 8d741a5de7ff4191bf97d57b9f54c2f6d4a15585)
1*8d741a5dSApple OSS Distributions# -*- mode: makefile;-*-
2*8d741a5dSApple OSS Distributions#
3*8d741a5dSApple OSS Distributions# Copyright (C) 1999-2023 Apple Inc. All rights reserved.
4*8d741a5dSApple OSS Distributions#
5*8d741a5dSApple OSS Distributions# MakeInc.def contains global definitions for building,
6*8d741a5dSApple OSS Distributions# linking, and installing files.
7*8d741a5dSApple OSS Distributions#
8*8d741a5dSApple OSS Distributions
9*8d741a5dSApple OSS Distributions#
10*8d741a5dSApple OSS Distributions# Architecture Configuration options
11*8d741a5dSApple OSS Distributions#
12*8d741a5dSApple OSS DistributionsSUPPORTED_ARCH_CONFIGS := X86_64 X86_64H ARM64
13*8d741a5dSApple OSS Distributions
14*8d741a5dSApple OSS Distributions#
15*8d741a5dSApple OSS Distributions# Kernel Configuration options
16*8d741a5dSApple OSS Distributions#
17*8d741a5dSApple OSS DistributionsSUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE KASAN SPTM
18*8d741a5dSApple OSS Distributions
19*8d741a5dSApple OSS Distributions
20*8d741a5dSApple OSS Distributions#
21*8d741a5dSApple OSS Distributions# Machine Configuration options
22*8d741a5dSApple OSS Distributions#
23*8d741a5dSApple OSS Distributions
24*8d741a5dSApple OSS DistributionsSUPPORTED_X86_64_MACHINE_CONFIGS = NONE
25*8d741a5dSApple OSS DistributionsSUPPORTED_X86_64H_MACHINE_CONFIGS = NONE
26*8d741a5dSApple OSS Distributions
27*8d741a5dSApple OSS Distributionsifneq ($(findstring _Sim,$(RC_ProjectName)),)
28*8d741a5dSApple OSS DistributionsSUPPORTED_ARM64_MACHINE_CONFIGS = NONE
29*8d741a5dSApple OSS Distributionselse ifneq ($(findstring _host,$(RC_ProjectName)),)
30*8d741a5dSApple OSS DistributionsSUPPORTED_ARM64_MACHINE_CONFIGS = NONE
31*8d741a5dSApple OSS Distributionselse
32*8d741a5dSApple OSS DistributionsSUPPORTED_ARM64_MACHINE_CONFIGS = T6000 T6020 T6030 T6031 T8101 T8103 T8112 T8122 T8132 VMAPPLE
33*8d741a5dSApple OSS Distributions
34*8d741a5dSApple OSS DistributionsSPTM_ENABLED_SOCS_MacOSX = t8132
35*8d741a5dSApple OSS Distributionsendif
36*8d741a5dSApple OSS Distributions
37*8d741a5dSApple OSS Distributions#
38*8d741a5dSApple OSS Distributions# Setup up *_LC variables during recursive invocations
39*8d741a5dSApple OSS Distributions#
40*8d741a5dSApple OSS Distributions
41*8d741a5dSApple OSS Distributionsifndef CURRENT_ARCH_CONFIG_LC
42*8d741a5dSApple OSS Distributions	export CURRENT_ARCH_CONFIG_LC	:= $(shell printf "%s" "$(CURRENT_ARCH_CONFIG)" | $(TR) A-Z a-z)
43*8d741a5dSApple OSS Distributionsendif
44*8d741a5dSApple OSS Distributions
45*8d741a5dSApple OSS Distributionsifndef CURRENT_KERNEL_CONFIG_LC
46*8d741a5dSApple OSS Distributions	export CURRENT_KERNEL_CONFIG_LC := $(shell printf "%s" "$(CURRENT_KERNEL_CONFIG)" | $(TR) A-Z a-z)
47*8d741a5dSApple OSS Distributionsendif
48*8d741a5dSApple OSS Distributions
49*8d741a5dSApple OSS Distributionsifndef CURRENT_MACHINE_CONFIG_LC
50*8d741a5dSApple OSS Distributions	export CURRENT_MACHINE_CONFIG_LC := $(shell printf "%s" "$(CURRENT_MACHINE_CONFIG)" | $(TR) A-Z a-z)
51*8d741a5dSApple OSS Distributionsendif
52*8d741a5dSApple OSS Distributions
53*8d741a5dSApple OSS Distributions# Enable BTI by default for all ARM64 targets
54*8d741a5dSApple OSS DistributionsBTI_BUILD = 1
55*8d741a5dSApple OSS Distributions
56*8d741a5dSApple OSS Distributions
57*8d741a5dSApple OSS Distributions# -mkernel contains BTI by default
58*8d741a5dSApple OSS Distributionsifeq ($(BTI_BUILD),1)
59*8d741a5dSApple OSS Distributions	BTI_BUILD_FLAGS = -DXNU_BUILT_WITH_BTI
60*8d741a5dSApple OSS Distributionselse
61*8d741a5dSApple OSS Distributions	BTI_BUILD_FLAGS = -fno-branch-target-identification -UXNU_BUILT_WITH_BTI
62*8d741a5dSApple OSS Distributionsendif
63*8d741a5dSApple OSS Distributions
64*8d741a5dSApple OSS Distributions#
65*8d741a5dSApple OSS Distributions# Component List
66*8d741a5dSApple OSS Distributions#
67*8d741a5dSApple OSS DistributionsCOMPONENT_LIST	= osfmk bsd libkern iokit pexpert libsa security san
68*8d741a5dSApple OSS DistributionsCOMPONENT	= $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))))
69*8d741a5dSApple OSS DistributionsCOMPONENT_IMPORT_LIST = $(filter-out $(COMPONENT),$(COMPONENT_LIST))
70*8d741a5dSApple OSS Distributions
71*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T8101 = -DARM64_BOARD_CONFIG_T8101			-mcpu=apple-a14
72*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T8103 = -DARM64_BOARD_CONFIG_T8103                  -mcpu=apple-a14
73*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T6000 = -DARM64_BOARD_CONFIG_T6000			-mcpu=apple-a14
74*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T6020 = -DARM64_BOARD_CONFIG_T6020 			-mcpu=apple-a15
75*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T8112 = -DARM64_BOARD_CONFIG_T8112 			-mcpu=apple-a15
76*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T6030 = -DARM64_BOARD_CONFIG_T6030 			-mcpu=apple-a16
77*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T6031 = -DARM64_BOARD_CONFIG_T6031 			-mcpu=apple-a16
78*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T8122 = -DARM64_BOARD_CONFIG_T8122_T8130		-mcpu=apple-a16
79*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_T8132 = -DARM64_BOARD_CONFIG_T8132			-mcpu=apple-acc7
80*8d741a5dSApple OSS DistributionsMACHINE_FLAGS_ARM64_VMAPPLE = -DARM64_BOARD_CONFIG_VMAPPLE              -march=armv8.5a+sme2
81*8d741a5dSApple OSS Distributions
82*8d741a5dSApple OSS Distributions
83*8d741a5dSApple OSS Distributions#
84*8d741a5dSApple OSS Distributions# Deployment target flag
85*8d741a5dSApple OSS Distributions#
86*8d741a5dSApple OSS Distributionsifeq ($(PLATFORM),MacOSX)
87*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION) -DXNU_TARGET_OS_OSX
88*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS = -Wl,-macosx_version_min,$(SDKVERSION)
89*8d741a5dSApple OSS Distributionselse ifeq ($(PLATFORM),DriverKit)
90*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -target apple-driverkit$(SDKVERSION) -DXNU_TARGET_OS_OSX
91*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS = -Wl,-target,apple-driverkit$(SDKVERSION)
92*8d741a5dSApple OSS Distributionselse ifeq ($(PLATFORM),WatchOS)
93*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_WATCH
94*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS =
95*8d741a5dSApple OSS Distributionselse ifeq ($(PLATFORM),tvOS)
96*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_TV
97*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS =
98*8d741a5dSApple OSS Distributionselse ifeq ($(PLATFORM),AppleTVOS)
99*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_TV
100*8d741a5dSApple OSS Distributionselse ifeq ($(PLATFORM),BridgeOS)
101*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -mbridgeos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_BRIDGE
102*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS =
103*8d741a5dSApple OSS Distributionselse ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
104*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_IOS
105*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS = -Wl,-ios_version_min,$(SDKVERSION)
106*8d741a5dSApple OSS Distributionselse ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
107*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS =
108*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS =
109*8d741a5dSApple OSS Distributionselse
110*8d741a5dSApple OSS Distributions    DEPLOYMENT_TARGET_FLAGS =
111*8d741a5dSApple OSS Distributions    DEPLOYMENT_LINKER_FLAGS =
112*8d741a5dSApple OSS Distributionsendif
113*8d741a5dSApple OSS Distributions
114*8d741a5dSApple OSS Distributions
115*8d741a5dSApple OSS DistributionsDEPLOYMENT_TARGET_DEFINES = -DXNU_PLATFORM_$(PLATFORM)
116*8d741a5dSApple OSS Distributions
117*8d741a5dSApple OSS Distributions
118*8d741a5dSApple OSS Distributions#
119*8d741a5dSApple OSS Distributions# Standard defines list
120*8d741a5dSApple OSS Distributions#
121*8d741a5dSApple OSS DistributionsDEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \
122*8d741a5dSApple OSS Distributions	-DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile -DXNU_KERN_EVENT_DATA_IS_VLA \
123*8d741a5dSApple OSS Distributions	-DCURRENT_MACHINE_CONFIG_LC=$(CURRENT_MACHINE_CONFIG_LC) \
124*8d741a5dSApple OSS Distributions	$(CONFIG_DEFINES) $(SEED_DEFINES)
125*8d741a5dSApple OSS Distributions
126*8d741a5dSApple OSS Distributions# Enable caching with `make CCACHE=ccache`
127*8d741a5dSApple OSS Distributions# This intentionally does not override $(CC) because that will confuse
128*8d741a5dSApple OSS Distributions# utilities like mig.
129*8d741a5dSApple OSS DistributionsCCACHE ?=
130*8d741a5dSApple OSS Distributions
131*8d741a5dSApple OSS Distributions#
132*8d741a5dSApple OSS Distributions# Compiler command
133*8d741a5dSApple OSS Distributions#
134*8d741a5dSApple OSS DistributionsKCC  = $(CCACHE) $(CC)
135*8d741a5dSApple OSS DistributionsKC++ = $(CCACHE) $(CXX)
136*8d741a5dSApple OSS Distributions
137*8d741a5dSApple OSS DistributionsGENASSYM_KCC = $(CCACHE) $(CC)
138*8d741a5dSApple OSS Distributions
139*8d741a5dSApple OSS Distributions#
140*8d741a5dSApple OSS Distributions# Compiler warning flags
141*8d741a5dSApple OSS Distributions#
142*8d741a5dSApple OSS Distributions
143*8d741a5dSApple OSS DistributionsUSE_WERROR := 1
144*8d741a5dSApple OSS Distributionsifneq ($(BUILD_WERROR),)
145*8d741a5dSApple OSS DistributionsUSE_WERROR := $(BUILD_WERROR)
146*8d741a5dSApple OSS Distributionsendif
147*8d741a5dSApple OSS Distributions
148*8d741a5dSApple OSS Distributionsifeq ($(USE_WERROR),1)
149*8d741a5dSApple OSS DistributionsWERROR := -Werror
150*8d741a5dSApple OSS Distributionsendif
151*8d741a5dSApple OSS Distributions
152*8d741a5dSApple OSS Distributions# Shared C/C++ warning flags
153*8d741a5dSApple OSS Distributions# NOTE: order matters here.  -Wno-xxx goes before opt-in of ones we want
154*8d741a5dSApple OSS DistributionsWARNFLAGS_STD := \
155*8d741a5dSApple OSS Distributions	-Weverything \
156*8d741a5dSApple OSS Distributions	-Wundef-prefix=TARGET_OS_ \
157*8d741a5dSApple OSS Distributions	-Wundef-prefix=LCK_GRP_USE_ARG \
158*8d741a5dSApple OSS Distributions	-Wno-pedantic \
159*8d741a5dSApple OSS Distributions	$(WERROR) \
160*8d741a5dSApple OSS Distributions	-Wno-bad-function-cast \
161*8d741a5dSApple OSS Distributions	-Wno-bitwise-instead-of-logical \
162*8d741a5dSApple OSS Distributions	-Wno-c++-compat \
163*8d741a5dSApple OSS Distributions	-Wno-c++98-compat \
164*8d741a5dSApple OSS Distributions	-Wno-conditional-uninitialized \
165*8d741a5dSApple OSS Distributions	-Wno-covered-switch-default \
166*8d741a5dSApple OSS Distributions	-Wno-disabled-macro-expansion \
167*8d741a5dSApple OSS Distributions	-Wno-documentation-unknown-command \
168*8d741a5dSApple OSS Distributions	-Wno-extra-semi-stmt \
169*8d741a5dSApple OSS Distributions	-Wno-format-non-iso \
170*8d741a5dSApple OSS Distributions	-Wno-language-extension-token \
171*8d741a5dSApple OSS Distributions	-Wno-missing-variable-declarations \
172*8d741a5dSApple OSS Distributions	-Wno-packed \
173*8d741a5dSApple OSS Distributions	-Wno-padded \
174*8d741a5dSApple OSS Distributions	-Wno-partial-availability \
175*8d741a5dSApple OSS Distributions	-Wno-reserved-id-macro \
176*8d741a5dSApple OSS Distributions	-Wno-shift-sign-overflow \
177*8d741a5dSApple OSS Distributions	-Wno-switch-enum \
178*8d741a5dSApple OSS Distributions	-Wno-unaligned-access \
179*8d741a5dSApple OSS Distributions	-Wno-undef \
180*8d741a5dSApple OSS Distributions	-Wno-invalid-offsetof \
181*8d741a5dSApple OSS Distributions	-Wno-unused-macros \
182*8d741a5dSApple OSS Distributions	-Wno-used-but-marked-unused \
183*8d741a5dSApple OSS Distributions	-Wno-variadic-macros \
184*8d741a5dSApple OSS Distributions	-Wno-zero-length-array \
185*8d741a5dSApple OSS Distributions	-Wno-packed \
186*8d741a5dSApple OSS Distributions	-Wno-cast-function-type-strict \
187*8d741a5dSApple OSS Distributions	-Wno-incompatible-function-pointer-types-strict
188*8d741a5dSApple OSS Distributions
189*8d741a5dSApple OSS Distributions# When a new clang has new warnings disable them here until the kernel is fixed.
190*8d741a5dSApple OSS DistributionsWARNFLAGS_STD := $(WARNFLAGS_STD) \
191*8d741a5dSApple OSS Distributions	-Wno-unknown-warning-option \
192*8d741a5dSApple OSS Distributions	-Wno-anon-enum-enum-conversion \
193*8d741a5dSApple OSS Distributions	-Wno-error=enum-enum-conversion \
194*8d741a5dSApple OSS Distributions	-Wno-error=c99-designator \
195*8d741a5dSApple OSS Distributions	-Wno-error=reorder-init-list \
196*8d741a5dSApple OSS Distributions	-Wno-error=switch-default \
197*8d741a5dSApple OSS Distributions	-Wno-deprecated-volatile \
198*8d741a5dSApple OSS Distributions	-Wno-error=incompatible-function-pointer-types-strict \
199*8d741a5dSApple OSS Distributions	-Wno-cast-function-type-strict
200*8d741a5dSApple OSS Distributions
201*8d741a5dSApple OSS DistributionsWARNFLAGS_STD := $(WARNFLAGS_STD) \
202*8d741a5dSApple OSS Distributions	-Wno-declaration-after-statement
203*8d741a5dSApple OSS Distributions
204*8d741a5dSApple OSS Distributions# Hand-written sign conversion diagnostics are resolved, but the
205*8d741a5dSApple OSS Distributions# auto-generated ones need mig and iig to be updated to fix.  Disable the
206*8d741a5dSApple OSS Distributions# diagnostic here until we've completed that:
207*8d741a5dSApple OSS DistributionsWARNFLAGS_STD := $(WARNFLAGS_STD) \
208*8d741a5dSApple OSS Distributions	-Wno-sign-compare \
209*8d741a5dSApple OSS Distributions	-Wno-sign-conversion
210*8d741a5dSApple OSS Distributions
211*8d741a5dSApple OSS Distributions# Opt-ins:
212*8d741a5dSApple OSS DistributionsWARNFLAGS_STD := $(WARNFLAGS_STD) \
213*8d741a5dSApple OSS Distributions	-Wpointer-arith \
214*8d741a5dSApple OSS Distributions	-Wxnu-typed-allocators
215*8d741a5dSApple OSS Distributions
216*8d741a5dSApple OSS DistributionsCWARNFLAGS_STD = \
217*8d741a5dSApple OSS Distributions	$(WARNFLAGS_STD)
218*8d741a5dSApple OSS Distributions
219*8d741a5dSApple OSS Distributions
220*8d741a5dSApple OSS Distributions
221*8d741a5dSApple OSS Distributions# Can be overridden in Makefile.template or Makefile.$arch
222*8d741a5dSApple OSS Distributionsexport CWARNFLAGS ?= $(CWARNFLAGS_STD)
223*8d741a5dSApple OSS Distributions
224*8d741a5dSApple OSS Distributionsdefine add_perfile_cflags
225*8d741a5dSApple OSS Distributions$(1)_CWARNFLAGS_ADD += $2
226*8d741a5dSApple OSS Distributionsendef
227*8d741a5dSApple OSS Distributions
228*8d741a5dSApple OSS Distributionsdefine rm_perfile_cflags
229*8d741a5dSApple OSS Distributions$(1)_CFLAGS_RM += $2
230*8d741a5dSApple OSS Distributionsendef
231*8d741a5dSApple OSS Distributions
232*8d741a5dSApple OSS DistributionsCXXWARNFLAGS_STD = \
233*8d741a5dSApple OSS Distributions	$(WARNFLAGS_STD) \
234*8d741a5dSApple OSS Distributions	-Wno-c++98-compat-pedantic \
235*8d741a5dSApple OSS Distributions	-Wno-exit-time-destructors \
236*8d741a5dSApple OSS Distributions	-Wno-global-constructors \
237*8d741a5dSApple OSS Distributions	-Wno-old-style-cast
238*8d741a5dSApple OSS Distributions
239*8d741a5dSApple OSS Distributions# Can be overridden in Makefile.template or Makefile.$arch
240*8d741a5dSApple OSS Distributionsexport CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
241*8d741a5dSApple OSS Distributions
242*8d741a5dSApple OSS Distributionsdefine add_perfile_cxxflags
243*8d741a5dSApple OSS Distributions$(1)_CXXWARNFLAGS_ADD += $2
244*8d741a5dSApple OSS Distributionsendef
245*8d741a5dSApple OSS Distributions
246*8d741a5dSApple OSS Distributions#
247*8d741a5dSApple OSS Distributions# Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
248*8d741a5dSApple OSS Distributions
249*8d741a5dSApple OSS DistributionsARCH_FLAGS_X86_64	  = -arch x86_64
250*8d741a5dSApple OSS DistributionsARCH_FLAGS_X86_64H	  = -arch x86_64h
251*8d741a5dSApple OSS Distributions
252*8d741a5dSApple OSS Distributionsifeq ($(RC_ProjectName),xnu_libraries)
253*8d741a5dSApple OSS DistributionsBUILD_STATIC_LINK := 1
254*8d741a5dSApple OSS DistributionsBUILD_XNU_LIBRARY := 1
255*8d741a5dSApple OSS DistributionsRC_NONARCH_CFLAGS += -D__BUILDING_XNU_LIBRARY__=1
256*8d741a5dSApple OSS Distributionsendif
257*8d741a5dSApple OSS Distributions
258*8d741a5dSApple OSS Distributionsifneq ($(filter ARM ARM64,$(CURRENT_ARCH_CONFIG)),)
259*8d741a5dSApple OSS Distributions
260*8d741a5dSApple OSS Distributionsifneq ($(findstring _Sim,$(RC_ProjectName)),)
261*8d741a5dSApple OSS DistributionsARCH_FLAGS_ARM64          = -arch arm64e
262*8d741a5dSApple OSS Distributionselse ifneq ($(findstring _host,$(RC_ProjectName)),)
263*8d741a5dSApple OSS DistributionsARCH_FLAGS_ARM64          = -arch arm64e
264*8d741a5dSApple OSS Distributionselse
265*8d741a5dSApple OSS Distributions
266*8d741a5dSApple OSS DistributionsARCH_STRING_FOR_CURRENT_MACHINE_CONFIG ?=
267*8d741a5dSApple OSS Distributions
268*8d741a5dSApple OSS Distributionsifeq ($(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG),)
269*8d741a5dSApple OSS Distributions
270*8d741a5dSApple OSS Distributionsifneq ($(EMBEDDED_DEVICE_MAP),)
271*8d741a5dSApple OSS Distributionsexport ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) -list -query SELECT DISTINCT KernelMachOArchitecture FROM Targets WHERE KernelPlatform IS \"$(CURRENT_MACHINE_CONFIG_LC)\" LIMIT 1 || echo UNKNOWN )
272*8d741a5dSApple OSS Distributionsifeq ($(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG),)
273*8d741a5dSApple OSS Distributionsifeq ($(filter $(EXTRA_TARGET_CONFIGS_$(CURRENT_KERNEL_CONFIG)),$(CURRENT_MACHINE_CONFIG)),)
274*8d741a5dSApple OSS Distributions$(error Machine config $(CURRENT_MACHINE_CONFIG_LC) not found in EmbeddedDeviceMap)
275*8d741a5dSApple OSS Distributionsendif
276*8d741a5dSApple OSS Distributionsendif
277*8d741a5dSApple OSS Distributionsendif
278*8d741a5dSApple OSS Distributions
279*8d741a5dSApple OSS Distributionsendif
280*8d741a5dSApple OSS Distributions
281*8d741a5dSApple OSS Distributionsifeq ($(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG),)
282*8d741a5dSApple OSS Distributions
283*8d741a5dSApple OSS Distributions# Without embdedded device map, use a default arch string
284*8d741a5dSApple OSS Distributionsexport ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell echo $(CURRENT_ARCH_CONFIG) | tr A-Z a-z)
285*8d741a5dSApple OSS Distributionsifneq ($(filter arm64,$(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG)),)
286*8d741a5dSApple OSS Distributionsexport ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := arm64e
287*8d741a5dSApple OSS Distributionsendif
288*8d741a5dSApple OSS Distributions
289*8d741a5dSApple OSS Distributionsendif
290*8d741a5dSApple OSS Distributions
291*8d741a5dSApple OSS Distributions
292*8d741a5dSApple OSS DistributionsBUILD_STATIC_LINK := 1
293*8d741a5dSApple OSS Distributions
294*8d741a5dSApple OSS DistributionsARCH_FLAGS_ARM64	  = -arch $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG)
295*8d741a5dSApple OSS Distributions
296*8d741a5dSApple OSS Distributionsendif
297*8d741a5dSApple OSS Distributions
298*8d741a5dSApple OSS Distributionselse
299*8d741a5dSApple OSS Distributions# non arm machine config string
300*8d741a5dSApple OSS Distributionsifndef ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG
301*8d741a5dSApple OSS Distributionsexport ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell echo $(CURRENT_ARCH_CONFIG) | tr A-Z a-z)
302*8d741a5dSApple OSS Distributionsendif
303*8d741a5dSApple OSS Distributions
304*8d741a5dSApple OSS Distributionsendif
305*8d741a5dSApple OSS Distributions
306*8d741a5dSApple OSS Distributions#
307*8d741a5dSApple OSS Distributions# Default CFLAGS
308*8d741a5dSApple OSS Distributions#
309*8d741a5dSApple OSS Distributionsifdef RC_NONARCH_CFLAGS
310*8d741a5dSApple OSS DistributionsOTHER_CFLAGS = $(RC_NONARCH_CFLAGS)
311*8d741a5dSApple OSS Distributionsendif
312*8d741a5dSApple OSS Distributions
313*8d741a5dSApple OSS Distributions#
314*8d741a5dSApple OSS Distributions# Debug info
315*8d741a5dSApple OSS Distributions#
316*8d741a5dSApple OSS DistributionsDSYMINFODIR	= Contents
317*8d741a5dSApple OSS DistributionsDSYMKGMACROSDIR	= Contents/Resources
318*8d741a5dSApple OSS DistributionsDSYMLLDBMACROSDIR = Contents/Resources/Python
319*8d741a5dSApple OSS DistributionsDSYMDWARFDIR	= Contents/Resources/DWARF
320*8d741a5dSApple OSS Distributions
321*8d741a5dSApple OSS DistributionsDEBUG_CFLAGS := -g
322*8d741a5dSApple OSS DistributionsBUILD_DSYM := 1
323*8d741a5dSApple OSS Distributions
324*8d741a5dSApple OSS Distributions#
325*8d741a5dSApple OSS Distributions# We must not use -fno-keep-inline-functions, or it will remove the dtrace
326*8d741a5dSApple OSS Distributions# probes from the kernel.
327*8d741a5dSApple OSS Distributions#
328*8d741a5dSApple OSS DistributionsCFLAGS_GEN = $(DEBUG_CFLAGS) -nostdlibinc \
329*8d741a5dSApple OSS Distributions	-ferror-limit=10000 \
330*8d741a5dSApple OSS Distributions	-fno-builtin \
331*8d741a5dSApple OSS Distributions	-fno-common \
332*8d741a5dSApple OSS Distributions	-ftrivial-auto-var-init=zero \
333*8d741a5dSApple OSS Distributions	-fsigned-bitfields \
334*8d741a5dSApple OSS Distributions	-fmerge-all-constants \
335*8d741a5dSApple OSS Distributions	-fno-c++-static-destructors \
336*8d741a5dSApple OSS Distributions	$(OTHER_CFLAGS)
337*8d741a5dSApple OSS Distributions
338*8d741a5dSApple OSS DistributionsCFLAGS_RELEASE	=
339*8d741a5dSApple OSS DistributionsCFLAGS_DEVELOPMENT	=
340*8d741a5dSApple OSS DistributionsCFLAGS_DEBUG	=
341*8d741a5dSApple OSS DistributionsCFLAGS_KASAN = $(CFLAGS_DEVELOPMENT)
342*8d741a5dSApple OSS DistributionsCFLAGS_PROFILE	=  -pg
343*8d741a5dSApple OSS Distributions
344*8d741a5dSApple OSS DistributionsCFLAGS_X86_64	= -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
345*8d741a5dSApple OSS Distributions				-DPAGE_SIZE_FIXED -mkernel -msoft-float
346*8d741a5dSApple OSS Distributions
347*8d741a5dSApple OSS DistributionsCFLAGS_X86_64H = $(CFLAGS_X86_64)
348*8d741a5dSApple OSS Distributions
349*8d741a5dSApple OSS DistributionsLARGE_MEMORY_DEFINE=-UARM_LARGE_MEMORY
350*8d741a5dSApple OSS DistributionsARM64_PLKSEG_ADDR  =0xfffffff004004000
351*8d741a5dSApple OSS DistributionsARM64_LINK_ADDR    =0xfffffff007004000
352*8d741a5dSApple OSS Distributions
353*8d741a5dSApple OSS Distributions# Use ARM_LARGE_MEMORY config for all MacOSX targets.
354*8d741a5dSApple OSS Distributionsifneq ($(filter $(PLATFORM),MacOSX),)
355*8d741a5dSApple OSS DistributionsLARGE_MEMORY_DEFINE=-DARM_LARGE_MEMORY=1
356*8d741a5dSApple OSS DistributionsARM64_PLKSEG_ADDR  =0xfffffe0004004000
357*8d741a5dSApple OSS DistributionsARM64_LINK_ADDR    =0xfffffe0007004000
358*8d741a5dSApple OSS Distributionsendif
359*8d741a5dSApple OSS Distributions
360*8d741a5dSApple OSS Distributions
361*8d741a5dSApple OSS DistributionsCFLAGS_ARM64	= -Darm64 -DARM64 -D__ARM64__ -DLP64 -DPAGE_SIZE_FIXED -DVM_KERNEL_LINK_ADDRESS=$(ARM64_LINK_ADDR) \
362*8d741a5dSApple OSS Distributions				$(LARGE_MEMORY_DEFINE) -momit-leaf-frame-pointer -fno-strict-aliasing -D__API__=v4 -mkernel \
363*8d741a5dSApple OSS Distributions				$(BTI_BUILD_FLAGS)
364*8d741a5dSApple OSS Distributions
365*8d741a5dSApple OSS DistributionsCXXFLAGS_ARM64  = $(BTI_BUILD_FLAGS)
366*8d741a5dSApple OSS Distributions
367*8d741a5dSApple OSS DistributionsCFLAGS_RELEASEX86_64 = -O2
368*8d741a5dSApple OSS DistributionsCFLAGS_DEVELOPMENTX86_64 = -O2
369*8d741a5dSApple OSS DistributionsCFLAGS_KASANX86_64 = $(CFLAGS_DEVELOPMENTX86_64)
370*8d741a5dSApple OSS Distributions# No space optimization for the DEBUG kernel for the benefit of gdb:
371*8d741a5dSApple OSS DistributionsCFLAGS_DEBUGX86_64 = -O0
372*8d741a5dSApple OSS DistributionsCFLAGS_PROFILEX86_64 = -O2
373*8d741a5dSApple OSS Distributions
374*8d741a5dSApple OSS DistributionsCFLAGS_RELEASEX86_64H = -O2
375*8d741a5dSApple OSS DistributionsCFLAGS_DEVELOPMENTX86_64H = -O2
376*8d741a5dSApple OSS DistributionsCFLAGS_KASANX86_64H = $(CFLAGS_DEVELOPMENTX86_64H)
377*8d741a5dSApple OSS Distributions# No space optimization for the DEBUG kernel for the benefit of gdb:
378*8d741a5dSApple OSS DistributionsCFLAGS_DEBUGX86_64H = -O0
379*8d741a5dSApple OSS DistributionsCFLAGS_PROFILEX86_64H = -O2
380*8d741a5dSApple OSS Distributions
381*8d741a5dSApple OSS DistributionsCFLAGS_RELEASEARM = -O2
382*8d741a5dSApple OSS DistributionsCFLAGS_DEVELOPMENTARM = -O2
383*8d741a5dSApple OSS DistributionsCFLAGS_DEBUGARM = -O0
384*8d741a5dSApple OSS DistributionsCFLAGS_PROFILEARM = -O2
385*8d741a5dSApple OSS Distributions
386*8d741a5dSApple OSS DistributionsCFLAGS_RELEASEARM64 = -O2
387*8d741a5dSApple OSS DistributionsCFLAGS_DEVELOPMENTARM64 = -O2
388*8d741a5dSApple OSS DistributionsCFLAGS_KASANARM64 = $(CFLAGS_DEVELOPMENTARM64)
389*8d741a5dSApple OSS DistributionsCFLAGS_DEBUGARM64 = -O0
390*8d741a5dSApple OSS DistributionsCFLAGS_SPTMARM64 = $(CFLAGS_DEVELOPMENTARM64)
391*8d741a5dSApple OSS DistributionsCFLAGS_PROFILEARM64 = -O2
392*8d741a5dSApple OSS Distributions
393*8d741a5dSApple OSS Distributions#
394*8d741a5dSApple OSS Distributions# bound-checking support
395*8d741a5dSApple OSS Distributions#
396*8d741a5dSApple OSS Distributions# BOUND_CHECKS=0 disables, else support is dynamically detected.
397*8d741a5dSApple OSS Distributions# Intel is currently disabled.
398*8d741a5dSApple OSS Distributions#
399*8d741a5dSApple OSS Distributionsifndef BOUND_CHECKS
400*8d741a5dSApple OSS Distributionsifeq ($(shell $(CC) -E -fbounds-safety /dev/null 2>/dev/null && echo 1),1)
401*8d741a5dSApple OSS Distributions	ifeq ($(CURRENT_ARCH_CONFIG_LC),x86_64)
402*8d741a5dSApple OSS Distributions	    export BOUND_CHECKS := 0
403*8d741a5dSApple OSS Distributions	    export CFLAGS_BOUND_CHECKS = -Wno-error=self-assign
404*8d741a5dSApple OSS Distributions	else
405*8d741a5dSApple OSS Distributions		export BOUND_CHECKS := 1
406*8d741a5dSApple OSS Distributions	endif
407*8d741a5dSApple OSS Distributionselse
408*8d741a5dSApple OSS Distributions    export BOUND_CHECKS := 0
409*8d741a5dSApple OSS Distributionsendif
410*8d741a5dSApple OSS Distributionsendif # ifndef BOUND_CHECKS
411*8d741a5dSApple OSS Distributionsifeq ($(BOUND_CHECKS),1)
412*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS = -fbounds-safety
413*8d741a5dSApple OSS Distributionselse
414*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS ?=
415*8d741a5dSApple OSS Distributionsendif
416*8d741a5dSApple OSS Distributions
417*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS_PENDING = -DBOUND_CHECKS_PENDING=1 -Wno-self-assign
418*8d741a5dSApple OSS Distributions
419*8d741a5dSApple OSS Distributions# Bounds-safety adoption mode
420*8d741a5dSApple OSS Distributions#
421*8d741a5dSApple OSS Distributions# * Tells Clang to run in bounds-safety adoption mode which is allowed to
422*8d741a5dSApple OSS Distributions#   produce better diagnostics but a slower build.
423*8d741a5dSApple OSS Distributions# * Doesn't try to suppress any warnings in staging (see Bounds-safety warning
424*8d741a5dSApple OSS Distributions#   staging)
425*8d741a5dSApple OSS Distributions#
426*8d741a5dSApple OSS DistributionsBOUNDS_SAFETY_ADOPTION_MODE ?= 0
427*8d741a5dSApple OSS Distributionsifeq ($(BOUNDS_SAFETY_ADOPTION_MODE),1)
428*8d741a5dSApple OSS Distributions  ifneq ($(BOUND_CHECKS),1)
429*8d741a5dSApple OSS Distributions    $(error BOUNDS_SAFETY_ADOPTION_MODE cannot be enabled when BOUND_CHECKS=0)
430*8d741a5dSApple OSS Distributions  endif
431*8d741a5dSApple OSS Distributions  ifeq ($(RC_XBS),YES)
432*8d741a5dSApple OSS Distributions    # This mode should **only** be used at engineers' desks and not in B&I
433*8d741a5dSApple OSS Distributions    # builds because it may add compile-time overhead.
434*8d741a5dSApple OSS Distributions    $(error BOUNDS_SAFETY_ADOPTION_MODE should not be enabled in B&I builds)
435*8d741a5dSApple OSS Distributions  endif
436*8d741a5dSApple OSS Distributions  CFLAGS_BOUND_CHECKS += -fbounds-safety-adoption-mode
437*8d741a5dSApple OSS Distributionsendif
438*8d741a5dSApple OSS Distributions
439*8d741a5dSApple OSS Distributions# Bounds-safety warning staging
440*8d741a5dSApple OSS Distributions#
441*8d741a5dSApple OSS Distributions# To prevent new bounds-safety warnings in a soon to be submitted Clang from
442*8d741a5dSApple OSS Distributions# breaking the build they can be explicitly be prevented from being errors by
443*8d741a5dSApple OSS Distributions# adding `-Wno-error=<new_warning_name>` to
444*8d741a5dSApple OSS Distributions# `BOUNDS_SAFETY_DOWNGRADED_UPCOMING_WARNFLAGS`.
445*8d741a5dSApple OSS Distributions#
446*8d741a5dSApple OSS Distributions# A warning in `BOUNDS_SAFETY_DOWNGRADED_UPCOMING_WARNFLAGS` should be
447*8d741a5dSApple OSS Distributions# removed once the new Clang with the warning is in the OS and the code builds
448*8d741a5dSApple OSS Distributions# without it firing.
449*8d741a5dSApple OSS Distributions#
450*8d741a5dSApple OSS DistributionsBOUNDS_SAFETY_DOWNGRADED_UPCOMING_WARNFLAGS =
451*8d741a5dSApple OSS Distributions
452*8d741a5dSApple OSS Distributionsifneq ($(words $(BOUNDS_SAFETY_DOWNGRADED_UPCOMING_WARNFLAGS)),0)
453*8d741a5dSApple OSS Distributions  ifeq ($(BOUNDS_SAFETY_ADOPTION_MODE),0)
454*8d741a5dSApple OSS Distributions    # Note this implicitly relies on `-Wno-unknown-warning-option` already being
455*8d741a5dSApple OSS Distributions    # passed to the compiler.
456*8d741a5dSApple OSS Distributions    CFLAGS_BOUND_CHECKS +=  $(BOUNDS_SAFETY_DOWNGRADED_UPCOMING_WARNFLAGS)
457*8d741a5dSApple OSS Distributions  endif
458*8d741a5dSApple OSS Distributionsendif
459*8d741a5dSApple OSS Distributions
460*8d741a5dSApple OSS Distributions# Check whether soft trap is supported
461*8d741a5dSApple OSS Distributionsifndef BOUND_CHECKS_SOFT
462*8d741a5dSApple OSS Distributionsifeq ($(shell $(CC) -E -ftrap-function-returns /dev/null 2>/dev/null && echo 1),1)
463*8d741a5dSApple OSS Distributions    export BOUND_CHECKS_SOFT := 1
464*8d741a5dSApple OSS Distributionselse
465*8d741a5dSApple OSS Distributions    export BOUND_CHECKS_SOFT := 0
466*8d741a5dSApple OSS Distributionsendif
467*8d741a5dSApple OSS Distributionsendif # ifndef BOUND_CHECKS_SOFT
468*8d741a5dSApple OSS Distributionsifeq ($(BOUND_CHECKS_SOFT),1)
469*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS_SOFT =  -fbounds-safety  -ftrap-function=ml_bound_chk_soft_trap -ftrap-function-returns
470*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS_DEBUG =	$(CFLAGS_BOUND_CHECKS_SOFT) -DBOUND_CHECKS_DEBUG=1
471*8d741a5dSApple OSS Distributionselse
472*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS_SOFT =
473*8d741a5dSApple OSS DistributionsCFLAGS_BOUND_CHECKS_DEBUG =
474*8d741a5dSApple OSS Distributionsendif
475*8d741a5dSApple OSS Distributions
476*8d741a5dSApple OSS Distributions#
477*8d741a5dSApple OSS Distributions# Sanitizers Support (KASan, UBSan)
478*8d741a5dSApple OSS Distributions#
479*8d741a5dSApple OSS Distributions
480*8d741a5dSApple OSS Distributions# Which kernel configurations are built with KCOV enabled.
481*8d741a5dSApple OSS DistributionsKCOV_RUNTIME := KASAN
482*8d741a5dSApple OSS Distributions
483*8d741a5dSApple OSS Distributionsifneq ($(filter RELEASE, $(KCOV_RUNTIME)),)
484*8d741a5dSApple OSS Distributions$(error "Sanitizer runtime should not be enabled for RELEASE kernel.")
485*8d741a5dSApple OSS Distributionsendif
486*8d741a5dSApple OSS Distributions
487*8d741a5dSApple OSS Distributions
488*8d741a5dSApple OSS DistributionsSAN=0
489*8d741a5dSApple OSS Distributions
490*8d741a5dSApple OSS Distributions# KASan support
491*8d741a5dSApple OSS Distributions#
492*8d741a5dSApple OSS Distributions
493*8d741a5dSApple OSS Distributionsifeq ($(CURRENT_KERNEL_CONFIG),KASAN)
494*8d741a5dSApple OSS Distributions# KASan kernel config implicitly enables the KASan instrumentation.
495*8d741a5dSApple OSS Distributions# Instrumentation for other sanitizers is enabled explicitly at build time.
496*8d741a5dSApple OSS DistributionsKASAN = 1
497*8d741a5dSApple OSS Distributionsendif
498*8d741a5dSApple OSS Distributions
499*8d741a5dSApple OSS Distributionsifeq ($(KASAN),1)
500*8d741a5dSApple OSS DistributionsSAN=1
501*8d741a5dSApple OSS DistributionsBUILD_LTO=0
502*8d741a5dSApple OSS Distributions
503*8d741a5dSApple OSS Distributions# KASan Light support
504*8d741a5dSApple OSS Distributions#
505*8d741a5dSApple OSS Distributions# Light mode omits the HWASAN stack instrumentation.
506*8d741a5dSApple OSS Distributions# Not supported by KASan Classic at this moment.
507*8d741a5dSApple OSS Distributions
508*8d741a5dSApple OSS DistributionsKASAN_LIGHT_PLATFORM := WatchOS
509*8d741a5dSApple OSS Distributions
510*8d741a5dSApple OSS Distributionsifneq ($(filter $(PLATFORM), $(KASAN_LIGHT_PLATFORM)),)
511*8d741a5dSApple OSS DistributionsKASAN_LIGHT=1
512*8d741a5dSApple OSS DistributionsHWASAN_INSTRUMENT_STACK=0
513*8d741a5dSApple OSS Distributionselse
514*8d741a5dSApple OSS DistributionsKASAN_LIGHT=0
515*8d741a5dSApple OSS DistributionsHWASAN_INSTRUMENT_STACK=1
516*8d741a5dSApple OSS Distributionsendif
517*8d741a5dSApple OSS Distributions
518*8d741a5dSApple OSS DistributionsKASAN_BLACKLIST=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
519*8d741a5dSApple OSS Distributions
520*8d741a5dSApple OSS Distributions# To calculate the kasan offset, subtract the lowest KVA to sanitize, shifted right by KASAN_SCALE_$INSTRUMENTATION bits,
521*8d741a5dSApple OSS Distributions# from the base address of the kasan shadow area, (e.g. for x86_64 solve the following equation:
522*8d741a5dSApple OSS Distributions# OFFSET = {VA mapped by the first KASAN PML4 [Currently #494]} - (LOWEST_KVA >> 3)
523*8d741a5dSApple OSS Distributions# OFFSET = (0ULL - (512GiB * (512 - 494))) - (LOWEST_SAN_KVA >> 3)
524*8d741a5dSApple OSS Distributions# OFFSET = FFFFF70000000000 - ((0ULL - (512GiB * (512 - 496))) >> 3) [PML4 #496 is the first possible KVA]
525*8d741a5dSApple OSS Distributions# OFFSET = FFFFF70000000000 - (FFFFF80000000000 >> 3)
526*8d741a5dSApple OSS Distributions# OFFSET = DFFFF80000000000
527*8d741a5dSApple OSS Distributions# ).
528*8d741a5dSApple OSS DistributionsKASAN_OFFSET_X86_64=0xdffff80000000000
529*8d741a5dSApple OSS DistributionsKASAN_OFFSET_X86_64H=$(KASAN_OFFSET_X86_64)
530*8d741a5dSApple OSS DistributionsKASAN_OFFSET_ARM64=0xf000000000000000
531*8d741a5dSApple OSS Distributions
532*8d741a5dSApple OSS DistributionsKASAN_OFFSET=$($(addsuffix $(CURRENT_ARCH_CONFIG),KASAN_OFFSET_))
533*8d741a5dSApple OSS Distributions
534*8d741a5dSApple OSS Distributions# CLANG HWASAN/KHWASAN instrumentation powers KASAN_TBI. HWASAN traditional prefixing
535*8d741a5dSApple OSS Distributions# is replaced by __asan_ to commonize exports across models.
536*8d741a5dSApple OSS DistributionsKASAN_SCALE_TBI=4
537*8d741a5dSApple OSS DistributionsCFLAGS_KASAN_INSTRUMENTATION_TBI = -DKASAN_TBI=1 -DKASAN_SCALE=$(KASAN_SCALE_TBI) \
538*8d741a5dSApple OSS Distributions	-fsanitize=kernel-hwaddress \
539*8d741a5dSApple OSS Distributions	-fsanitize-ignorelist=$(KASAN_BLACKLIST) \
540*8d741a5dSApple OSS Distributions	-mllvm -hwasan-recover=0 \
541*8d741a5dSApple OSS Distributions	-mllvm -hwasan-mapping-offset=$(KASAN_OFFSET) \
542*8d741a5dSApple OSS Distributions	-mllvm -hwasan-instrument-atomics=1 \
543*8d741a5dSApple OSS Distributions	-mllvm -hwasan-instrument-stack=$(HWASAN_INSTRUMENT_STACK) \
544*8d741a5dSApple OSS Distributions	-mllvm -hwasan-generate-tags-with-calls=1 \
545*8d741a5dSApple OSS Distributions	-mllvm -hwasan-instrument-with-calls=0 \
546*8d741a5dSApple OSS Distributions	-mllvm -hwasan-use-short-granules=0 \
547*8d741a5dSApple OSS Distributions	-mllvm -hwasan-memory-access-callback-prefix="__asan_"
548*8d741a5dSApple OSS Distributions
549*8d741a5dSApple OSS Distributions
550*8d741a5dSApple OSS DistributionsKASAN_SCALE_CLASSIC=3
551*8d741a5dSApple OSS DistributionsCFLAGS_KASAN_INSTRUMENTATION_CLASSIC = -DKASAN_CLASSIC=1 -DKASAN_SCALE=$(KASAN_SCALE_CLASSIC) \
552*8d741a5dSApple OSS Distributions	-fsanitize=address \
553*8d741a5dSApple OSS Distributions	-mllvm -asan-globals-live-support \
554*8d741a5dSApple OSS Distributions	-mllvm -asan-mapping-offset=$(KASAN_OFFSET) \
555*8d741a5dSApple OSS Distributions	-fsanitize-ignorelist=$(KASAN_BLACKLIST)
556*8d741a5dSApple OSS Distributions
557*8d741a5dSApple OSS DistributionsCFLAGS_KASANARM64 += $(CFLAGS_KASAN_INSTRUMENTATION_TBI)
558*8d741a5dSApple OSS DistributionsCFLAGS_KASANX86_64 += $(CFLAGS_KASAN_INSTRUMENTATION_CLASSIC)
559*8d741a5dSApple OSS DistributionsCFLAGS_KASANX86_64H += $(CFLAGS_KASAN_INSTRUMENTATION_CLASSIC)
560*8d741a5dSApple OSS DistributionsCFLAGS_GEN += -DKASAN=1 -DKASAN_OFFSET=$(KASAN_OFFSET) -DKASAN_LIGHT=$(KASAN_LIGHT)
561*8d741a5dSApple OSS Distributions
562*8d741a5dSApple OSS DistributionsSFLAGS_KASANARM64 += $(CFLAGS_KASAN_INSTRUMENTATION_TBI)
563*8d741a5dSApple OSS DistributionsSFLAGS_KASANX86_64 += $(CFLAGS_KASAN_INSTRUMENTATION_CLASSIC)
564*8d741a5dSApple OSS DistributionsSFLAGS_KASANX86_64H += $(CFLAGS_KASAN_INSTRUMENTATION_CLASSIC)
565*8d741a5dSApple OSS DistributionsSFLAGS_GEN += -DKASAN=1 -DKASAN_OFFSET=$(KASAN_OFFSET) -DKASAN_LIGHT=$(KASAN_LIGHT)
566*8d741a5dSApple OSS Distributions
567*8d741a5dSApple OSS Distributionsendif
568*8d741a5dSApple OSS Distributions
569*8d741a5dSApple OSS Distributions# UBSan
570*8d741a5dSApple OSS Distributions#
571*8d741a5dSApple OSS Distributions# The Undefined Behavior sanitizer runtime is always built as part of, and only for,
572*8d741a5dSApple OSS Distributions# KASAN variants. UBSan instrumentation is disabled by default and only enabled explicitly
573*8d741a5dSApple OSS Distributions# when building with UBSAN=1.
574*8d741a5dSApple OSS Distributions#
575*8d741a5dSApple OSS Distributions# On iOS RELEASE and DEVELOPMENT kernels, a subset of UBSan checks is enabled along with a minimal
576*8d741a5dSApple OSS Distributions# runtime that emulates trap mode (but makes it recoverable).
577*8d741a5dSApple OSS Distributions
578*8d741a5dSApple OSS Distributionsifeq ($(KASAN), 1)
579*8d741a5dSApple OSS Distributions
580*8d741a5dSApple OSS Distributionsifeq ($(UBSAN),1)
581*8d741a5dSApple OSS DistributionsSAN=1
582*8d741a5dSApple OSS Distributions
583*8d741a5dSApple OSS DistributionsUBSAN_RUNTIME =
584*8d741a5dSApple OSS DistributionsUBSAN_CHECKS += signed-integer-overflow shift pointer-overflow bounds object-size # non-fatal (calls runtime, can return)
585*8d741a5dSApple OSS Distributions# UBSAN_CHECKS = undefined nullability unsigned-integer-overflow # everything
586*8d741a5dSApple OSS DistributionsUBSAN_CHECKS_FATAL =                                           # fatal (calls runtime, must not return)
587*8d741a5dSApple OSS DistributionsUBSAN_CHECKS_TRAP = vla-bound builtin                          # emit a trap instruction (no runtime support)
588*8d741a5dSApple OSS DistributionsUBSAN_DISABLED += vptr function     # requires unsupported C++ runtime
589*8d741a5dSApple OSS Distributions
590*8d741a5dSApple OSS Distributions# UBSan alignment + KASan code size is too large
591*8d741a5dSApple OSS Distributions# UBSan unreachable doesn't play nice with ASan (40723397)
592*8d741a5dSApple OSS DistributionsUBSAN_DISABLED += alignment unreachable
593*8d741a5dSApple OSS Distributions
594*8d741a5dSApple OSS Distributionsendif
595*8d741a5dSApple OSS Distributions
596*8d741a5dSApple OSS Distributionselse
597*8d741a5dSApple OSS Distributions
598*8d741a5dSApple OSS Distributions# DEVELOPMENT and RELEASE variants
599*8d741a5dSApple OSS Distributionsifeq ($(PLATFORM),iPhoneOS)
600*8d741a5dSApple OSS Distributions
601*8d741a5dSApple OSS Distributions# Currently we have to keep alive two separated UBSAN runtimes (minimal for DEVELOPMENT,
602*8d741a5dSApple OSS Distributions# full for KASAN). This implies that we cannot use CFLAGS_$(CURRENT_KERNEL_CONFIG), because
603*8d741a5dSApple OSS Distributions# CFLAGS_DEVELOPMENT is folded into CFLAGS_KASAN. For the time being we leave this check here,
604*8d741a5dSApple OSS Distributions# as we work (independently) to both break the CFLAGS direct dependency and commonize the
605*8d741a5dSApple OSS Distributions# sanitizer runtimes.
606*8d741a5dSApple OSS DistributionsUBSAN_MINIMAL_RUNTIME := DEVELOPMENT DEBUG
607*8d741a5dSApple OSS Distributionsifneq ($(filter $(CURRENT_KERNEL_CONFIG), $(UBSAN_MINIMAL_RUNTIME)),)
608*8d741a5dSApple OSS Distributions
609*8d741a5dSApple OSS Distributions# This is (unfortunately) intentional. Currently the "kasan" blacklist, which folds both
610*8d741a5dSApple OSS Distributions# ubsan and kasan specific files, is generated for all builds during the
611*8d741a5dSApple OSS Distributions# setup phase. The blacklist file itself is divided per-sanitizer, so won't
612*8d741a5dSApple OSS Distributions# affect the UBSAN build outside of the entries that are legitimately
613*8d741a5dSApple OSS Distributions# intended for it.
614*8d741a5dSApple OSS DistributionsUBSAN_BLACKLIST=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
615*8d741a5dSApple OSS Distributions
616*8d741a5dSApple OSS DistributionsUBSAN_CHECKS = signed-integer-overflow
617*8d741a5dSApple OSS DistributionsUBSAN_RUNTIME = -fsanitize-minimal-runtime -fsanitize-ignorelist=$(UBSAN_BLACKLIST)
618*8d741a5dSApple OSS DistributionsUBSAN_CHECKS_TRAP =
619*8d741a5dSApple OSS DistributionsUBSAN_CHECKS_FATAL =
620*8d741a5dSApple OSS DistributionsUBSAN_DISABLED =
621*8d741a5dSApple OSS Distributionsendif
622*8d741a5dSApple OSS Distributionsendif
623*8d741a5dSApple OSS Distributions
624*8d741a5dSApple OSS Distributionsendif
625*8d741a5dSApple OSS Distributions
626*8d741a5dSApple OSS DistributionsCFLAGS_GEN += $(UBSAN_RUNTIME)
627*8d741a5dSApple OSS DistributionsCFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS) $(UBSAN_CHECKS_FATAL) $(UBSAN_CHECKS_TRAP),-fsanitize=$(x))
628*8d741a5dSApple OSS DistributionsCFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS_FATAL),-fno-sanitize-recover=$(x))
629*8d741a5dSApple OSS DistributionsCFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS_TRAP),-fsanitize-trap=$(x))
630*8d741a5dSApple OSS DistributionsCFLAGS_GEN += $(foreach x,$(UBSAN_DISABLED),-fno-sanitize=$(x))
631*8d741a5dSApple OSS Distributions
632*8d741a5dSApple OSS Distributionsifeq ($(KSANCOV),1)
633*8d741a5dSApple OSS Distributions# Enable SanitizerCoverage instrumentation in xnu
634*8d741a5dSApple OSS DistributionsSAN = 1
635*8d741a5dSApple OSS DistributionsKCOV_BLACKLIST := $(OBJROOT)/san/kcov-blacklist-$(CURRENT_ARCH_CONFIG_LC)
636*8d741a5dSApple OSS DistributionsKCOV_CFLAGS := -fsanitize-coverage=trace-pc-guard -fsanitize-coverage-ignorelist=$(KCOV_BLACKLIST)
637*8d741a5dSApple OSS DistributionsCFLAGS_GEN += $(KCOV_CFLAGS) -DKSANCOV=1
638*8d741a5dSApple OSS Distributionsendif
639*8d741a5dSApple OSS Distributions
640*8d741a5dSApple OSS Distributionsifeq ($(SAN),1)
641*8d741a5dSApple OSS DistributionsCFLAGS_GEN += -fsanitize-ignorelist=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
642*8d741a5dSApple OSS Distributionsendif
643*8d741a5dSApple OSS Distributions
644*8d741a5dSApple OSS Distributions# Any extra flags that get passed at the command line during build.
645*8d741a5dSApple OSS Distributionsifeq ($(CFLAGS_EXTRA),)
646*8d741a5dSApple OSS DistributionsCFLAGS_EXTRA =
647*8d741a5dSApple OSS Distributionsendif
648*8d741a5dSApple OSS Distributions
649*8d741a5dSApple OSS DistributionsCFLAGS	= $(CFLAGS_GEN) \
650*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
651*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
652*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) \
653*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_)) \
654*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_))) \
655*8d741a5dSApple OSS Distributions		  $(DEPLOYMENT_TARGET_FLAGS) \
656*8d741a5dSApple OSS Distributions		  $(DEPLOYMENT_TARGET_DEFINES) \
657*8d741a5dSApple OSS Distributions		  $(DEFINES) \
658*8d741a5dSApple OSS Distributions		  $(CFLAGS_EXTRA)
659*8d741a5dSApple OSS Distributions
660*8d741a5dSApple OSS Distributions#
661*8d741a5dSApple OSS Distributions# Default C++ flags
662*8d741a5dSApple OSS Distributions#
663*8d741a5dSApple OSS Distributions
664*8d741a5dSApple OSS DistributionsOTHER_CXXFLAGS	=
665*8d741a5dSApple OSS Distributions
666*8d741a5dSApple OSS DistributionsCXXFLAGS_GEN  = -std=gnu++2b -fsized-deallocation -fapple-kext $(OTHER_CXXFLAGS)
667*8d741a5dSApple OSS Distributions
668*8d741a5dSApple OSS DistributionsCXXFLAGS      = $(CXXFLAGS_GEN) \
669*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),CXXFLAGS_)) \
670*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_KERNEL_CONFIG),CXXFLAGS_))
671*8d741a5dSApple OSS Distributions
672*8d741a5dSApple OSS Distributions#
673*8d741a5dSApple OSS Distributions# Assembler command
674*8d741a5dSApple OSS Distributions#
675*8d741a5dSApple OSS DistributionsAS	= $(CCACHE) $(CC)
676*8d741a5dSApple OSS DistributionsS_KCC	= $(CC)
677*8d741a5dSApple OSS Distributions
678*8d741a5dSApple OSS Distributions#
679*8d741a5dSApple OSS Distributions# Default SFLAGS
680*8d741a5dSApple OSS Distributions#
681*8d741a5dSApple OSS DistributionsSFLAGS_GEN = -D__ASSEMBLER__ -DASSEMBLER $(OTHER_CFLAGS)
682*8d741a5dSApple OSS Distributions
683*8d741a5dSApple OSS DistributionsSFLAGS_RELEASE	=
684*8d741a5dSApple OSS DistributionsSFLAGS_DEVELOPMENT	=
685*8d741a5dSApple OSS Distributions
686*8d741a5dSApple OSS Distributions# When making non-compatible changes to the XNU runtime, it can be useful to build
687*8d741a5dSApple OSS Distributions# a KASAN kernel + runtime, but linked against a DEVELOPMENT kernel cache.
688*8d741a5dSApple OSS Distributions# Uncomment the lines below to be able to build development, but passing KASAN=1.
689*8d741a5dSApple OSS Distributions# #_ifeq ($(KASAN),1)
690*8d741a5dSApple OSS Distributions# SFLAGS_DEVELOPMENT += -DKASAN=1
691*8d741a5dSApple OSS Distributions# #_endif
692*8d741a5dSApple OSS Distributions
693*8d741a5dSApple OSS DistributionsSFLAGS_KASAN = $(SFLAGS_DEVELOPMENT) -DKASAN=1
694*8d741a5dSApple OSS DistributionsSFLAGS_DEBUG	=
695*8d741a5dSApple OSS DistributionsSFLAGS_PROFILE	=
696*8d741a5dSApple OSS Distributions
697*8d741a5dSApple OSS DistributionsSFLAGS_X86_64	= $(CFLAGS_X86_64)
698*8d741a5dSApple OSS DistributionsSFLAGS_X86_64H	= $(CFLAGS_X86_64H)
699*8d741a5dSApple OSS DistributionsSFLAGS_ARM64	= $(CFLAGS_ARM64)
700*8d741a5dSApple OSS Distributions
701*8d741a5dSApple OSS DistributionsSFLAGS	= $(SFLAGS_GEN) \
702*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
703*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
704*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),SFLAGS_)) \
705*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_KERNEL_CONFIG),SFLAGS_)) \
706*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),SFLAGS_))) \
707*8d741a5dSApple OSS Distributions		  $(DEPLOYMENT_TARGET_FLAGS) \
708*8d741a5dSApple OSS Distributions		  $(DEPLOYMENT_TARGET_DEFINES) \
709*8d741a5dSApple OSS Distributions		  $(DEFINES)
710*8d741a5dSApple OSS Distributions
711*8d741a5dSApple OSS Distributions#
712*8d741a5dSApple OSS Distributions# Linker command
713*8d741a5dSApple OSS Distributions#
714*8d741a5dSApple OSS DistributionsLD	= $(KC++) -nostdlib
715*8d741a5dSApple OSS Distributions
716*8d741a5dSApple OSS Distributions#
717*8d741a5dSApple OSS Distributions# Default LDFLAGS
718*8d741a5dSApple OSS Distributions#
719*8d741a5dSApple OSS Distributions# Availability of DWARF allows DTrace CTF (compressed type format) to be constructed.
720*8d741a5dSApple OSS Distributions# ctf_insert creates the CTF section.  It needs reserved padding in the
721*8d741a5dSApple OSS Distributions# headers for the load command segment and the CTF section structures.
722*8d741a5dSApple OSS Distributions#
723*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_GEN = \
724*8d741a5dSApple OSS Distributions	-nostdlib \
725*8d741a5dSApple OSS Distributions	-fapple-kext \
726*8d741a5dSApple OSS Distributions	-Wl,-e,__start \
727*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__TEXT,__text,0x1000 \
728*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__DATA,__common,0x1000 \
729*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__DATA,__bss,0x1000 \
730*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
731*8d741a5dSApple OSS Distributions	-Wl,-segprot,__PRELINK_TEXT,r-x,r-x \
732*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
733*8d741a5dSApple OSS Distributions	-Wl,-new_linker \
734*8d741a5dSApple OSS Distributions	-Wl,-pagezero_size,0x0 \
735*8d741a5dSApple OSS Distributions	-Wl,-version_load_command \
736*8d741a5dSApple OSS Distributions	-Wl,-function_starts \
737*8d741a5dSApple OSS Distributions	-Wl,-headerpad,152
738*8d741a5dSApple OSS Distributions
739*8d741a5dSApple OSS Distributions# LDFLAGS_KERNEL_SDK	= -L$(SDKROOT)/usr/local/lib/kernel -lfirehose_kernel
740*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_SDK	= -L$(SDKROOT)/usr/local/lib/kernel -L$(SDKROOT)/usr/local/lib/kernel/platform
741*8d741a5dSApple OSS Distributions
742*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_RELEASE	=
743*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEVELOPMENT =
744*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_KASAN = $(LDFLAGS_KERNEL_DEVELOPMENT)
745*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEBUG	=
746*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_PROFILE	=
747*8d741a5dSApple OSS Distributions
748*8d741a5dSApple OSS Distributions# Tightbeam finds modules in the "tightbeam" subdirectory.
749*8d741a5dSApple OSS DistributionsTIGHTBEAM_MODULE_DIR       = $(SDKROOT)/usr/local/lib/kernel/tightbeam
750*8d741a5dSApple OSS Distributions
751*8d741a5dSApple OSS Distributions# KASLR static slide config:
752*8d741a5dSApple OSS Distributionsifndef SLIDE
753*8d741a5dSApple OSS DistributionsSLIDE=0x00
754*8d741a5dSApple OSS Distributionsendif
755*8d741a5dSApple OSS DistributionsKERNEL_MIN_ADDRESS      = 0xffffff8000000000
756*8d741a5dSApple OSS DistributionsKERNEL_BASE_OFFSET      = 0x100000
757*8d741a5dSApple OSS Distributions# POSIX shells use signed long for their arithmetic expressions. However,
758*8d741a5dSApple OSS Distributions# we're dealing with uintptr_t values here, so explicitly use bash which
759*8d741a5dSApple OSS Distributions# is known to be able to handle such larger values. ksh also works; dash
760*8d741a5dSApple OSS Distributions# and zsh both fail with different results (zsh even warns you).
761*8d741a5dSApple OSS DistributionsKERNEL_STATIC_SLIDE     = $(shell $(BASH) -c 'printf "0x%016x" \
762*8d741a5dSApple OSS Distributions			  $$(( $(SLIDE) << 21 ))')
763*8d741a5dSApple OSS DistributionsKERNEL_STATIC_BASE      = $(shell $(BASH) -c 'printf "0x%016x" \
764*8d741a5dSApple OSS Distributions			  $$(( $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ))')
765*8d741a5dSApple OSS DistributionsKERNEL_HIB_SECTION_BASE = $(shell $(BASH) -c 'printf "0x%016x" \
766*8d741a5dSApple OSS Distributions			  $$(( $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ))')
767*8d741a5dSApple OSS DistributionsKERNEL_TEXT_BASE        = $(shell $(BASH) -c 'printf "0x%016x" \
768*8d741a5dSApple OSS Distributions			  $$(( $(KERNEL_HIB_SECTION_BASE) + 0x100000 ))')
769*8d741a5dSApple OSS Distributions
770*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_RELEASEX86_64 = \
771*8d741a5dSApple OSS Distributions	-Wl,-pie \
772*8d741a5dSApple OSS Distributions	-Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \
773*8d741a5dSApple OSS Distributions	-Wl,-image_base,$(KERNEL_TEXT_BASE) \
774*8d741a5dSApple OSS Distributions	-Wl,-seg_page_size,__TEXT,0x200000 \
775*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__bootPT,0x1000 \
776*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__desc,0x1000 \
777*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__data,0x1000 \
778*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__text,0x1000 \
779*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__const,0x1000 \
780*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__bss,0x1000 \
781*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__common,0x1000 \
782*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__llvm_prf_cnts,0x1000 \
783*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__llvm_prf_names,0x1000 \
784*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__llvm_prf_data,0x1000 \
785*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__textcoal_nt,0x1000 \
786*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__cstring,0x1000 \
787*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__DATA,__percpu,0x1000 \
788*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__DATA,__const,__DATA_CONST,__const \
789*8d741a5dSApple OSS Distributions	-Wl,-segprot,__DATA_CONST,r--,r-- \
790*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__KLD,__const,__KLDDATA,__const \
791*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__KLD,__cstring,__KLDDATA,__cstring \
792*8d741a5dSApple OSS Distributions	-Wl,-segprot,__KLDDATA,rw-,rw- \
793*8d741a5dSApple OSS Distributions	-Wl,-segprot,__KLD,r-x,r-x \
794*8d741a5dSApple OSS Distributions	-Wl,-no_zero_fill_sections \
795*8d741a5dSApple OSS Distributions	$(LDFLAGS_NOSTRIP_FLAG)
796*8d741a5dSApple OSS Distributions
797*8d741a5dSApple OSS Distributionsifeq ($(SAN),1)
798*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_RELEASEX86_64 += \
799*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__cstring,0x1000
800*8d741a5dSApple OSS Distributionsendif
801*8d741a5dSApple OSS Distributions
802*8d741a5dSApple OSS Distributionsifeq ($(KSANCOV),1)
803*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_RELEASEX86_64 += \
804*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__sancov_guards,0x1000 \
805*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__sancov_pcs,0x1000
806*8d741a5dSApple OSS Distributionsendif
807*8d741a5dSApple OSS Distributions
808*8d741a5dSApple OSS Distributions# Define KERNEL_BASE_OFFSET so known at compile time:
809*8d741a5dSApple OSS DistributionsCFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
810*8d741a5dSApple OSS DistributionsCFLAGS_X86_64H += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
811*8d741a5dSApple OSS Distributions
812*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
813*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
814*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_KASANX86_64 = $(LDFLAGS_KERNEL_DEVELOPMENTX86_64) \
815*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__asan_globals,0x1000 \
816*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__asan_liveness,0x1000 \
817*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__HIB,__mod_term_func,0x1000 \
818*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__mod_init_func,__NULL,__mod_init_func \
819*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__eh_frame,__NULL,__eh_frame
820*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
821*8d741a5dSApple OSS Distributions
822*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_RELEASEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64)
823*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEBUGX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
824*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEVELOPMENTX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
825*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_KASANX86_64H = $(LDFLAGS_KERNEL_KASANX86_64)
826*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_PROFILEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
827*8d741a5dSApple OSS Distributions
828*8d741a5dSApple OSS Distributions# Offset image base by page to have iBoot load kernel TEXT correctly.
829*8d741a5dSApple OSS Distributions# First page is used for various purposes : sleep token, reset vector.
830*8d741a5dSApple OSS Distributions# We also need a 32MB offset, as this is the minimum block mapping size
831*8d741a5dSApple OSS Distributions# for a 16KB page runtime, and we wish to use the first virtual block
832*8d741a5dSApple OSS Distributions# to map the low globals page.  We also need another 4MB to account for
833*8d741a5dSApple OSS Distributions# the address space reserved by L4 (because the reservation is not a
834*8d741a5dSApple OSS Distributions# multiple of the block size in alignment/length, we will implictly map
835*8d741a5dSApple OSS Distributions# it with our block mapping, and we therefore must reflect that the
836*8d741a5dSApple OSS Distributions# first 4MB of the block mapping for xnu do not belong to xnu).
837*8d741a5dSApple OSS Distributions# For the moment, kaliber has a unique memory layout (monitor at the top
838*8d741a5dSApple OSS Distributions# of memory).  Support this by breaking 16KB on other platforms and
839*8d741a5dSApple OSS Distributions# mandating 32MB alignment. Image base (i.e. __TEXT) must be 16KB
840*8d741a5dSApple OSS Distributions# aligned since ld64 will link with 16KB alignment for ARM64.
841*8d741a5dSApple OSS Distributions#
842*8d741a5dSApple OSS Distributions# We currently offset by an additional 32MB in order to reclaim memory.
843*8d741a5dSApple OSS Distributions# We need a dedicated virtual page for the low globals.  Our bootloader
844*8d741a5dSApple OSS Distributions# may have a significant chunk of memory (up to an L2 entry in size)
845*8d741a5dSApple OSS Distributions# that lies before the kernel.  The addition 32MB of virtual padding
846*8d741a5dSApple OSS Distributions# ensures that we have enough virtual address space to map all of that
847*8d741a5dSApple OSS Distributions# memory as part of the V-to-P mapping.
848*8d741a5dSApple OSS Distributions# 23355738 - put __PRELINK_TEXT first. We reserve enough room
849*8d741a5dSApple OSS Distributions# for 0x0000000003000000 = 48MB of kexts
850*8d741a5dSApple OSS Distributions#
851*8d741a5dSApple OSS Distributions# 0xfffffff000000000 (32MB range for low globals)
852*8d741a5dSApple OSS Distributions# 0xfffffff002000000 (32MB range to allow for large page physical slide)
853*8d741a5dSApple OSS Distributions# 0xfffffff004000000 (16KB range to reserve the first available page)
854*8d741a5dSApple OSS Distributions# 0xfffffff004004000 (48MB range for kexts)
855*8d741a5dSApple OSS Distributions# 0xfffffff007004000 (Start of xnu proper).
856*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_GENARM64 = \
857*8d741a5dSApple OSS Distributions	-Wl,-pie \
858*8d741a5dSApple OSS Distributions	-Wl,-static \
859*8d741a5dSApple OSS Distributions	-Wl,-segaddr,__PRELINK_TEXT,$(ARM64_PLKSEG_ADDR) \
860*8d741a5dSApple OSS Distributions	-Wl,-image_base,$(ARM64_LINK_ADDR) \
861*8d741a5dSApple OSS Distributions	\
862*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__text,__TEXT_EXEC,__hib_text \
863*8d741a5dSApple OSS Distributions	\
864*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__const,__DATA_CONST,__hib_const \
865*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__cstring,__DATA_CONST,__hib_const \
866*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__literal8,__DATA_CONST,__hib_const \
867*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__HIB,__literal16,__DATA_CONST,__hib_const \
868*8d741a5dSApple OSS Distributions	\
869*8d741a5dSApple OSS Distributions	-Wl,-rename_segment,__HIB,__HIBDATA \
870*8d741a5dSApple OSS Distributions	\
871*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__DATA,__const,0x4000 \
872*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__DATA,__percpu,0x4000 \
873*8d741a5dSApple OSS Distributions	-Wl,-sectalign,__DATA,__data,0x4000 \
874*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__DATA,__mod_init_func,__DATA_CONST,__mod_init_func \
875*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__DATA,__mod_term_func,__DATA_CONST,__mod_term_func \
876*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__DATA,__auth_ptr,__DATA_CONST,__auth_ptr \
877*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__DATA,__auth_got,__DATA_CONST,__auth_got \
878*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__DATA,__const,__DATA_CONST,__const \
879*8d741a5dSApple OSS Distributions	-Wl,-segprot,__DATA_CONST,r--,r-- \
880*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__KLD,__const,__KLDDATA,__const \
881*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__KLD,__cstring,__KLDDATA,__cstring \
882*8d741a5dSApple OSS Distributions	-Wl,-segprot,__KLDDATA,rw-,rw- \
883*8d741a5dSApple OSS Distributions	-Wl,-segprot,__KLD,r-x,r-x \
884*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text \
885*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__TEXT,__stubs,__TEXT_EXEC,__stubs \
886*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,"__PLK_TEXT_EXEC",__text,/dev/null \
887*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,__PRELINK_DATA,__data,/dev/null \
888*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,"__PLK_DATA_CONST",__data,/dev/null \
889*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,"__PLK_LLVM_COV",__llvm_covmap,/dev/null \
890*8d741a5dSApple OSS Distributions	-Wl,-sectcreate,"__PLK_LINKEDIT",__data,/dev/null
891*8d741a5dSApple OSS Distributions
892*8d741a5dSApple OSS Distributions# To support code coverage for kexts, the coverage mapping sections __llvm_covmap
893*8d741a5dSApple OSS Distributions# and __llvm_covfun are put into the __PLK_LLVM_COV segment rather than the
894*8d741a5dSApple OSS Distributions# standard __LLVM_COV segment. For later processing of the coverage data using
895*8d741a5dSApple OSS Distributions# llvm-cov, we move the coverage mapping for the kernel itself into the same
896*8d741a5dSApple OSS Distributions# segment (see also rdar://104951137)
897*8d741a5dSApple OSS Distributionsifeq ($(BUILD_CODE_COVERAGE),1)
898*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_GENARM64 += \
899*8d741a5dSApple OSS Distributions  -Wl,-rename_section,__LLVM_COV,__llvm_covmap,__PLK_LLVM_COV,__llvm_covmap \
900*8d741a5dSApple OSS Distributions  -Wl,-rename_section,__LLVM_COV,__llvm_covfun,__PLK_LLVM_COV,__llvm_covfun
901*8d741a5dSApple OSS Distributionsendif
902*8d741a5dSApple OSS Distributions
903*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_SEGARM64_SEG_ORDER = \
904*8d741a5dSApple OSS Distributions	__TEXT:__DATA_CONST:__DATA_SPTM:__LINKEDIT:__TEXT_EXEC:__TEXT_BOOT_EXEC:__KLD:__PPLTEXT:__PPLTRAMP:__PPLDATA_CONST:__LASTDATA_CONST:__LAST:__PPLDATA:__KLDDATA:__DATA:__HIBDATA:__BOOTDATA
905*8d741a5dSApple OSS Distributions
906*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_SEGARM64 = \
907*8d741a5dSApple OSS Distributions	-Wl,-rename_section,__PPLDATA,__const,__PPLDATA_CONST,__const \
908*8d741a5dSApple OSS Distributions	-Wl,-segment_order,$(LDFLAGS_KERNEL_SEGARM64_SEG_ORDER) \
909*8d741a5dSApple OSS Distributions	-Wl,-segprot,__TEXT,r--,r-- \
910*8d741a5dSApple OSS Distributions	-Wl,-segprot,__TEXT_EXEC,r-x,r-x \
911*8d741a5dSApple OSS Distributions	-Wl,-segprot,__TEXT_BOOT_EXEC,r-x,r-x \
912*8d741a5dSApple OSS Distributions	-Wl,-segprot,__PPLTEXT,r-x,r-x \
913*8d741a5dSApple OSS Distributions	-Wl,-segprot,__PPLTRAMP,r-x,r-x \
914*8d741a5dSApple OSS Distributions	-Wl,-segprot,__PPLDATA_CONST,r--,r-- \
915*8d741a5dSApple OSS Distributions	-Wl,-segprot,__LASTDATA_CONST,r--,r-- \
916*8d741a5dSApple OSS Distributions	-Wl,-segprot,__LAST,r-x,r-x \
917*8d741a5dSApple OSS Distributions
918*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_RELEASEARM64     = \
919*8d741a5dSApple OSS Distributions	$(LDFLAGS_KERNEL_GENARM64) \
920*8d741a5dSApple OSS Distributions	$(LDFLAGS_KERNEL_SEGARM64) \
921*8d741a5dSApple OSS Distributions	$(LDFLAGS_KERNEL_STRIP_LTO)
922*8d741a5dSApple OSS Distributions
923*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_CONFIG_RELEASEARM64     = \
924*8d741a5dSApple OSS Distributions	-Wl,-exported_symbols_list,$(TARGET)/all-kpi.exp
925*8d741a5dSApple OSS Distributions
926*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEVELOPMENTARM64     = \
927*8d741a5dSApple OSS Distributions	$(LDFLAGS_KERNEL_GENARM64) \
928*8d741a5dSApple OSS Distributions	$(LDFLAGS_KERNEL_SEGARM64) \
929*8d741a5dSApple OSS Distributions	$(LDFLAGS_NOSTRIP_FLAG)
930*8d741a5dSApple OSS Distributions
931*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64 =
932*8d741a5dSApple OSS Distributions
933*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_KASANARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
934*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_DEBUGARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
935*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_SPTMARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
936*8d741a5dSApple OSS Distributions
937*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_CONFIG_KASANARM64 = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64)
938*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_CONFIG_DEBUGARM64 = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64)
939*8d741a5dSApple OSS Distributions
940*8d741a5dSApple OSS Distributions#
941*8d741a5dSApple OSS Distributions# arm64e specific linker flags that should be used only when linking the kernel
942*8d741a5dSApple OSS Distributions# (and not the static kernel cache / kcgen)
943*8d741a5dSApple OSS Distributions#
944*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_SUBARCH_arm64e = \
945*8d741a5dSApple OSS Distributions	-Wl,-add_split_seg_info \
946*8d741a5dSApple OSS Distributions	-Wl,-kernel
947*8d741a5dSApple OSS Distributions
948*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_SUBARCH_x86_64 = \
949*8d741a5dSApple OSS Distributions	-Wl,-add_split_seg_info \
950*8d741a5dSApple OSS Distributions	-Wl,-kernel
951*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY_SUBARCH_x86_64h = $(LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64)
952*8d741a5dSApple OSS Distributions
953*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL	= $(LDFLAGS_KERNEL_GEN) \
954*8d741a5dSApple OSS Distributions		  $(LDFLAGS_KERNEL_SDK) \
955*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
956*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG),LDFLAGS_KERNEL_)) \
957*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
958*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
959*8d741a5dSApple OSS Distributions		  $(DEPLOYMENT_TARGET_FLAGS)
960*8d741a5dSApple OSS Distributions
961*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_ONLY  +=   \
962*8d741a5dSApple OSS Distributions		  $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_ONLY_CONFIG_))) \
963*8d741a5dSApple OSS Distributions		  $($(addsuffix $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG),LDFLAGS_KERNEL_ONLY_SUBARCH_)) \
964*8d741a5dSApple OSS Distributions		  -Wl,-alias_list,$(TARGET)/all-alias.exp \
965*8d741a5dSApple OSS Distributions		  -Wl,-sectcreate,__LINKINFO,__symbolsets,$(TARGET)/symbolsets.plist -Wl,-segprot,__LINKINFO,r--,r--
966*8d741a5dSApple OSS Distributions
967*8d741a5dSApple OSS DistributionsLDFILES_KERNEL_ONLY = $(TARGET)/all-kpi.exp $(TARGET)/all-alias.exp $(TARGET)/symbolsets.plist
968*8d741a5dSApple OSS Distributions
969*8d741a5dSApple OSS Distributions#
970*8d741a5dSApple OSS Distributions# Default runtime libraries to be linked with the kernel
971*8d741a5dSApple OSS Distributions#
972*8d741a5dSApple OSS DistributionsLD_KERNEL_LIBS	   = -lcc_kext
973*8d741a5dSApple OSS DistributionsLD_KERNEL_ARCHIVES = $(LDFLAGS_KERNEL_SDK) -lfirehose_kernel
974*8d741a5dSApple OSS Distributions
975*8d741a5dSApple OSS Distributions#
976*8d741a5dSApple OSS Distributions# SPTM TODO: This is a hack to always link the SPTM library when building the
977*8d741a5dSApple OSS Distributions#            SPTM variant. In the future, we should base whether to link the
978*8d741a5dSApple OSS Distributions#            library off of the HasSPTMTXM EDM per-target property. Note that
979*8d741a5dSApple OSS Distributions#            for standard kernels where the SPTM is enabled by default,
980*8d741a5dSApple OSS Distributions#            linkage is configured on a per-target and per-platform basis.
981*8d741a5dSApple OSS Distributions#
982*8d741a5dSApple OSS Distributionsifeq ($(CURRENT_KERNEL_CONFIG),SPTM)
983*8d741a5dSApple OSS DistributionsLD_KERNEL_ARCHIVES += -lTrustedExecutionMonitor_Kernel
984*8d741a5dSApple OSS DistributionsLD_KERNEL_ARCHIVES += -lsptm_xnu
985*8d741a5dSApple OSS Distributionselse
986*8d741a5dSApple OSS Distributions ifneq ($(CURRENT_KERNEL_CONFIG),KASAN)
987*8d741a5dSApple OSS Distributions  ifneq ($(filter $(CURRENT_MACHINE_CONFIG_LC),$(SPTM_ENABLED_SOCS_$(PLATFORM))),)
988*8d741a5dSApple OSS Distributions    LD_KERNEL_ARCHIVES += -lTrustedExecutionMonitor_Kernel
989*8d741a5dSApple OSS Distributions    LD_KERNEL_ARCHIVES += -lsptm_xnu
990*8d741a5dSApple OSS Distributions  endif
991*8d741a5dSApple OSS Distributions endif
992*8d741a5dSApple OSS Distributionsendif
993*8d741a5dSApple OSS Distributions
994*8d741a5dSApple OSS Distributions#
995*8d741a5dSApple OSS Distributions# DTrace support
996*8d741a5dSApple OSS Distributions#
997*8d741a5dSApple OSS Distributionsifndef DO_CTFMERGE
998*8d741a5dSApple OSS DistributionsDO_CTFMERGE := 1
999*8d741a5dSApple OSS Distributionsifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
1000*8d741a5dSApple OSS Distributionsifneq ($(PLATFORM),MacOSX)
1001*8d741a5dSApple OSS DistributionsDO_CTFMERGE := 0
1002*8d741a5dSApple OSS Distributionsendif
1003*8d741a5dSApple OSS Distributionsendif
1004*8d741a5dSApple OSS Distributionsendif # DO_CTFMERGE
1005*8d741a5dSApple OSS Distributions
1006*8d741a5dSApple OSS Distributions
1007*8d741a5dSApple OSS Distributions#
1008*8d741a5dSApple OSS Distributions# Default INCFLAGS
1009*8d741a5dSApple OSS Distributions#
1010*8d741a5dSApple OSS DistributionsINCFLAGS_IMPORT	= $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
1011*8d741a5dSApple OSS DistributionsINCFLAGS_EXTERN	= -I$(SRCROOT)/EXTERNAL_HEADERS
1012*8d741a5dSApple OSS DistributionsINCFLAGS_GEN	= -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
1013*8d741a5dSApple OSS DistributionsINCFLAGS_LOCAL	= -I.
1014*8d741a5dSApple OSS DistributionsINCFLAGS_SDK	= -I$(SDKROOT)/usr/local/include/kernel
1015*8d741a5dSApple OSS DistributionsINCFLAGS_PLATFORM = -I$(SDKROOT)/$(KPINCDIR)/platform
1016*8d741a5dSApple OSS Distributions
1017*8d741a5dSApple OSS DistributionsINCFLAGS	= $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) $(INCFLAGS_SDK) $(INCFLAGS_PLATFORM)
1018*8d741a5dSApple OSS Distributions
1019*8d741a5dSApple OSS Distributions#
1020*8d741a5dSApple OSS Distributions# Default MIGFLAGS
1021*8d741a5dSApple OSS Distributions#
1022*8d741a5dSApple OSS DistributionsMIGFLAGS	= $(DEFINES) $(INCFLAGS) -novouchers $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
1023*8d741a5dSApple OSS Distributions		$(DEPLOYMENT_TARGET_FLAGS)
1024*8d741a5dSApple OSS Distributions
1025*8d741a5dSApple OSS Distributions#
1026*8d741a5dSApple OSS Distributions# Default MIG Kernel Server flags
1027*8d741a5dSApple OSS Distributions#
1028*8d741a5dSApple OSS DistributionsMIGKSFLAGS = \
1029*8d741a5dSApple OSS Distributions	-DMACH_KERNEL_PRIVATE \
1030*8d741a5dSApple OSS Distributions	-DKERNEL_SERVER=1 \
1031*8d741a5dSApple OSS Distributions	-mach_msg2
1032*8d741a5dSApple OSS Distributions
1033*8d741a5dSApple OSS Distributions#
1034*8d741a5dSApple OSS Distributions# Default MIG KernelUser flags
1035*8d741a5dSApple OSS Distributions#
1036*8d741a5dSApple OSS DistributionsMIGKUFLAGS = \
1037*8d741a5dSApple OSS Distributions	-DMACH_KERNEL_PRIVATE \
1038*8d741a5dSApple OSS Distributions	-DKERNEL_USER=1 \
1039*8d741a5dSApple OSS Distributions	-maxonstack 1024
1040*8d741a5dSApple OSS Distributions
1041*8d741a5dSApple OSS Distributions# Support for LLVM Profile Guided Optimization (PGO)
1042*8d741a5dSApple OSS Distributions
1043*8d741a5dSApple OSS Distributionsifeq ($(BUILD_PROFILE),1)
1044*8d741a5dSApple OSS DistributionsCFLAGS_GEN += -fprofile-instr-generate -DPROFILE
1045*8d741a5dSApple OSS DistributionsCXXFLAGS_GEN += -fprofile-instr-generate -DPROFILE
1046*8d741a5dSApple OSS Distributionsendif
1047*8d741a5dSApple OSS Distributions
1048*8d741a5dSApple OSS Distributionsifdef USE_PROFILE
1049*8d741a5dSApple OSS DistributionsCFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
1050*8d741a5dSApple OSS DistributionsCXXFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
1051*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_GEN += -fprofile-instr-use=$(USE_PROFILE)
1052*8d741a5dSApple OSS Distributions
1053*8d741a5dSApple OSS DistributionsCFLAGS_GEN += -Wno-error=profile-instr-out-of-date
1054*8d741a5dSApple OSS Distributionsendif
1055*8d741a5dSApple OSS Distributions
1056*8d741a5dSApple OSS Distributions# Support for LLVM Source-based Code coverage. Since enabling code coverage
1057*8d741a5dSApple OSS Distributions# increases the size of __LINKEDIT, it might be necessary to set the keepsyms=1
1058*8d741a5dSApple OSS Distributions# boot-arg when building the kernel with code coverage enabled.
1059*8d741a5dSApple OSS Distributionsifeq ($(BUILD_CODE_COVERAGE),1)
1060*8d741a5dSApple OSS DistributionsCFLAGS_GEN += -fprofile-instr-generate -fcoverage-mapping
1061*8d741a5dSApple OSS DistributionsCXXFLAGS_GEN += -fprofile-instr-generate -fcoverage-mapping
1062*8d741a5dSApple OSS Distributionsendif
1063*8d741a5dSApple OSS Distributions
1064*8d741a5dSApple OSS Distributions#
1065*8d741a5dSApple OSS Distributions# Support for LLVM Link Time Optimization (LTO)
1066*8d741a5dSApple OSS Distributions#
1067*8d741a5dSApple OSS Distributions# LTO can be explicitly enabled or disabled with BUILD_LTO=1|0
1068*8d741a5dSApple OSS Distributions# and defaults to enabled except for DEBUG kernels
1069*8d741a5dSApple OSS Distributions#
1070*8d741a5dSApple OSS Distributions# CFLAGS_NOLTO_FLAG is needed on a per-file basis (for files
1071*8d741a5dSApple OSS Distributions# that deal poorly with LTO, or files that must be machine
1072*8d741a5dSApple OSS Distributions# code *.o files for xnu to build (i.e, setsegname runs on
1073*8d741a5dSApple OSS Distributions# them).
1074*8d741a5dSApple OSS Distributions#
1075*8d741a5dSApple OSS Distributions# LDFLAGS_NOSTRIP_FLAG is used to support configurations that
1076*8d741a5dSApple OSS Distributions# do not utilize an export list.  For these configs to build,
1077*8d741a5dSApple OSS Distributions# we need to prevent the LTO logic from dead stripping them.
1078*8d741a5dSApple OSS Distributions
1079*8d741a5dSApple OSS DistributionsLTO_ENABLED_RELEASE = 1
1080*8d741a5dSApple OSS DistributionsLTO_ENABLED_DEVELOPMENT = 1
1081*8d741a5dSApple OSS DistributionsLTO_ENABLED_DEBUG = 0
1082*8d741a5dSApple OSS DistributionsLTO_ENABLED_KASAN = 0
1083*8d741a5dSApple OSS DistributionsLTO_ENABLED_SPTM = $(LTO_ENABLED_DEVELOPMENT)
1084*8d741a5dSApple OSS Distributions
1085*8d741a5dSApple OSS Distributionsifneq ($(BUILD_LTO),)
1086*8d741a5dSApple OSS DistributionsUSE_LTO = $(BUILD_LTO)
1087*8d741a5dSApple OSS Distributionselse
1088*8d741a5dSApple OSS DistributionsUSE_LTO = $(LTO_ENABLED_$(CURRENT_KERNEL_CONFIG))
1089*8d741a5dSApple OSS Distributionsendif
1090*8d741a5dSApple OSS Distributions
1091*8d741a5dSApple OSS Distributionsifeq ($(USE_LTO),1)
1092*8d741a5dSApple OSS DistributionsCFLAGS_GEN	+= -flto -DBUILT_LTO=1
1093*8d741a5dSApple OSS DistributionsCXXFLAGS_GEN	+= -flto -DBUILT_LTO=1
1094*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_LTO	= -Wl,-mllvm,-inline-threshold=100
1095*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_GEN	+= $(LDFLAGS_KERNEL_LTO) -Wl,-object_path_lto,$(TARGET)/lto.o
1096*8d741a5dSApple OSS DistributionsLDFLAGS_NOSTRIP_FLAG = -rdynamic
1097*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_STRIP_LTO = -Wl,-dead_strip,-no_dead_strip_inits_and_terms
1098*8d741a5dSApple OSS Distributions
1099*8d741a5dSApple OSS DistributionsCFLAGS_NOLTO_FLAG = -fno-lto
1100*8d741a5dSApple OSS Distributionselse
1101*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_LTO =
1102*8d741a5dSApple OSS DistributionsLDFLAGS_NOSTRIP_FLAG =
1103*8d741a5dSApple OSS DistributionsLDFLAGS_KERNEL_STRIP_LTO =
1104*8d741a5dSApple OSS DistributionsCFLAGS_NOLTO_FLAG =
1105*8d741a5dSApple OSS Distributionsendif
1106*8d741a5dSApple OSS Distributions
1107*8d741a5dSApple OSS Distributions#
1108*8d741a5dSApple OSS Distributions# Default VPATH
1109*8d741a5dSApple OSS Distributions#
1110*8d741a5dSApple OSS Distributionsexport VPATH = .:$(SOURCE)
1111*8d741a5dSApple OSS Distributions
1112*8d741a5dSApple OSS Distributions
1113*8d741a5dSApple OSS Distributions
1114*8d741a5dSApple OSS Distributions#
1115*8d741a5dSApple OSS Distributions# Macros that control installation of kernel and its header files
1116*8d741a5dSApple OSS Distributions#
1117*8d741a5dSApple OSS Distributions# install flags for header files
1118*8d741a5dSApple OSS Distributions#
1119*8d741a5dSApple OSS DistributionsINSTALL_FLAGS = -c -S -m 0444
1120*8d741a5dSApple OSS DistributionsDATA_INSTALL_FLAGS = -c -S -m 0644
1121*8d741a5dSApple OSS DistributionsDATA_INSTALL_FLAGS_RO = -c -S -m 0444
1122*8d741a5dSApple OSS DistributionsEXEC_INSTALL_FLAGS = -c -S -m 0755
1123*8d741a5dSApple OSS Distributions
1124*8d741a5dSApple OSS Distributions#
1125*8d741a5dSApple OSS Distributions# Header file destinations
1126*8d741a5dSApple OSS Distributions#
1127*8d741a5dSApple OSS Distributions
1128*8d741a5dSApple OSS Distributionsifeq ($(DRIVERKIT),1)
1129*8d741a5dSApple OSS Distributions    SDKHEADERSROOT=$(DRIVERKITRUNTIMEROOT)
1130*8d741a5dSApple OSS Distributions    # only whitelisted headers install outside of the DriverKit Runtime hierarchy
1131*8d741a5dSApple OSS Distributions    DRIVERKITSDKHEADERSROOT=$(DRIVERKITROOT)
1132*8d741a5dSApple OSS Distributions    DRIVERKITFRAMEDIR = $(DRIVERKITROOT)/System/Library/Frameworks
1133*8d741a5dSApple OSS Distributionsendif
1134*8d741a5dSApple OSS Distributions
1135*8d741a5dSApple OSS Distributionsifeq ($(EXCLAVEKIT),1)
1136*8d741a5dSApple OSS Distributions    EXCLAVEKITSDKHEADERSROOT=$(EXCLAVEKITROOT)
1137*8d741a5dSApple OSS Distributions    EXCLAVEKITFRAMEDIR = $(EXCLAVEKITROOT)/System/Library/Frameworks
1138*8d741a5dSApple OSS Distributionsendif
1139*8d741a5dSApple OSS Distributions
1140*8d741a5dSApple OSS Distributionsifeq ($(EXCLAVECORE),1)
1141*8d741a5dSApple OSS Distributions    EXCLAVECORESDKHEADERSROOT=$(EXCLAVECOREROOT)
1142*8d741a5dSApple OSS Distributions    EXCLAVECOREFRAMEDIR = $(EXCLAVECOREROOT)/System/Library/Frameworks
1143*8d741a5dSApple OSS Distributionsendif
1144*8d741a5dSApple OSS Distributions
1145*8d741a5dSApple OSS DistributionsFRAMEDIR = $(SDKHEADERSROOT)/System/Library/Frameworks
1146*8d741a5dSApple OSS Distributions
1147*8d741a5dSApple OSS DistributionsIINCVERS = A
1148*8d741a5dSApple OSS DistributionsIINCFRAME = $(FRAMEDIR)/IOKit.framework
1149*8d741a5dSApple OSS DistributionsIINCDIR = $(IINCFRAME)/Versions/$(IINCVERS)/Headers
1150*8d741a5dSApple OSS DistributionsIPINCDIR = $(IINCFRAME)/Versions/$(IINCVERS)/PrivateHeaders
1151*8d741a5dSApple OSS DistributionsIRESDIR = $(IINCFRAME)/Versions/$(IINCVERS)/Resources
1152*8d741a5dSApple OSS Distributions
1153*8d741a5dSApple OSS DistributionsSINCVERS = B
1154*8d741a5dSApple OSS DistributionsSINCFRAME = $(FRAMEDIR)/System.framework
1155*8d741a5dSApple OSS DistributionsSINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers
1156*8d741a5dSApple OSS DistributionsSPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders
1157*8d741a5dSApple OSS DistributionsSRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources
1158*8d741a5dSApple OSS Distributions
1159*8d741a5dSApple OSS Distributionsifndef INCDIR
1160*8d741a5dSApple OSS Distributions    INCDIR = $(SDKHEADERSROOT)/usr/include
1161*8d741a5dSApple OSS Distributionsendif
1162*8d741a5dSApple OSS Distributionsifndef DRIVERKITINCDIR
1163*8d741a5dSApple OSS Distributions    DRIVERKITINCDIR = $(DRIVERKITSDKHEADERSROOT)/usr/include
1164*8d741a5dSApple OSS Distributionsendif
1165*8d741a5dSApple OSS Distributionsifndef EXCLAVEKITINCDIR
1166*8d741a5dSApple OSS Distributions    EXCLAVEKITINCDIR = $(EXCLAVEKITSDKHEADERSROOT)/usr/include
1167*8d741a5dSApple OSS Distributionsendif
1168*8d741a5dSApple OSS Distributionsifndef EXCLAVECOREINCDIR
1169*8d741a5dSApple OSS Distributions    EXCLAVECOREINCDIR = $(EXCLAVECORESDKHEADERSROOT)/usr/include
1170*8d741a5dSApple OSS Distributionsendif
1171*8d741a5dSApple OSS Distributionsifndef LCLDIR
1172*8d741a5dSApple OSS Distributions	LCLDIR = $(SDKHEADERSROOT)/usr/local/include
1173*8d741a5dSApple OSS Distributionsendif
1174*8d741a5dSApple OSS Distributionsifndef DRIVERKITLCLDIR
1175*8d741a5dSApple OSS Distributions    DRIVERKITLCLDIR = $(DRIVERKITSDKHEADERSROOT)/usr/local/include
1176*8d741a5dSApple OSS Distributionsendif
1177*8d741a5dSApple OSS Distributions
1178*8d741a5dSApple OSS DistributionsKINCVERS = A
1179*8d741a5dSApple OSS DistributionsKINCFRAME = $(FRAMEDIR)/Kernel.framework
1180*8d741a5dSApple OSS DistributionsKINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
1181*8d741a5dSApple OSS DistributionsKPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
1182*8d741a5dSApple OSS DistributionsKRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
1183*8d741a5dSApple OSS Distributions
1184*8d741a5dSApple OSS DistributionsKLIBCXXDIR = $(KPINCDIR)/kernel_sdkroot
1185*8d741a5dSApple OSS DistributionsKLIBCXXINCDIR = $(KLIBCXXDIR)/usr/include
1186*8d741a5dSApple OSS Distributions
1187*8d741a5dSApple OSS DistributionsDKIT_INCFRAME = DriverKit.framework
1188*8d741a5dSApple OSS Distributions
1189*8d741a5dSApple OSS Distributionsifeq ($(PLATFORM),MacOSX)
1190*8d741a5dSApple OSS DistributionsDKIT_INCVERS = A
1191*8d741a5dSApple OSS DistributionsDKIT_INCDIR = $(DKIT_INCFRAME)/Versions/$(DKIT_INCVERS)/Headers
1192*8d741a5dSApple OSS DistributionsDKIT_PINCDIR = $(DKIT_INCFRAME)/Versions/$(DKIT_INCVERS)/PrivateHeaders
1193*8d741a5dSApple OSS Distributionselse
1194*8d741a5dSApple OSS Distributions# non-macOS SDK frameworks use shallow bundle structure
1195*8d741a5dSApple OSS DistributionsDKIT_INCDIR = $(DKIT_INCFRAME)/Headers
1196*8d741a5dSApple OSS DistributionsDKIT_PINCDIR = $(DKIT_INCFRAME)/PrivateHeaders
1197*8d741a5dSApple OSS Distributionsendif
1198*8d741a5dSApple OSS Distributions
1199*8d741a5dSApple OSS Distributions# DriverKit SDK frameworks use shallow bundle structure
1200*8d741a5dSApple OSS DistributionsDRIVERKIT_DKIT_INCDIR = $(DKIT_INCFRAME)/Headers
1201*8d741a5dSApple OSS DistributionsDRIVERKIT_DKIT_PINCDIR = $(DKIT_INCFRAME)/PrivateHeaders
1202*8d741a5dSApple OSS Distributions
1203*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF ?=
1204*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -UMACH_KERNEL_PRIVATE
1205*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -UBSD_KERNEL_PRIVATE
1206*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -UIOKIT_KERNEL_PRIVATE
1207*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -ULIBKERN_KERNEL_PRIVATE
1208*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -ULIBSA_KERNEL_PRIVATE
1209*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -UPEXPERT_KERNEL_PRIVATE
1210*8d741a5dSApple OSS DistributionsXNU_PRIVATE_UNIFDEF += -UXNU_KERNEL_PRIVATE
1211*8d741a5dSApple OSS Distributions
1212*8d741a5dSApple OSS Distributions
1213*8d741a5dSApple OSS DistributionsPLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DXNU_PLATFORM_$(x) $(foreach token,$(PLATFORM_UNIFDEF_BLACKLIST_TOKENS_$(x)),-U$(token)),-UXNU_PLATFORM_$(x)))
1214*8d741a5dSApple OSS Distributions
1215*8d741a5dSApple OSS Distributions
1216*8d741a5dSApple OSS Distributions# Some header guards need to be present and checked in kernel headers but removed from userspace headers
1217*8d741a5dSApple OSS DistributionsKERNEL_ONLY_GUARDS_UNIFDEF =
1218*8d741a5dSApple OSS Distributions
1219*8d741a5dSApple OSS DistributionsSPINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -UDRIVERKIT -UEXCLAVEKIT -UEXCLAVECORE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1220*8d741a5dSApple OSS DistributionsSINCFRAME_UNIFDEF   = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -UDRIVERKIT -UEXCLAVEKIT -UEXCLAVECORE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1221*8d741a5dSApple OSS DistributionsDKPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -DDRIVERKIT -UEXCLAVEKIT -UEXCLAVECORE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1222*8d741a5dSApple OSS DistributionsDKINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -DDRIVERKIT -UEXCLAVEKIT -UEXCLAVECORE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1223*8d741a5dSApple OSS DistributionsEKPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -UDRIVERKIT -DEXCLAVEKIT -UEXCLAVECORE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1224*8d741a5dSApple OSS DistributionsEKINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -UDRIVERKIT -DEXCLAVEKIT -UEXCLAVECORE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1225*8d741a5dSApple OSS DistributionsECPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -UDRIVERKIT -UEXCLAVEKIT -DEXCLAVECORE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1226*8d741a5dSApple OSS DistributionsECINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -UDRIVERKIT -UEXCLAVEKIT -DEXCLAVECORE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__ $(KERNEL_ONLY_GUARDS_UNIFDEF)
1227*8d741a5dSApple OSS DistributionsKPINCFRAME_UNIFDEF  = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DKERNEL -DPRIVATE -UDRIVERKIT -UXNU_LIBCXX_SDKROOT -UEXCLAVEKIT -UEXCLAVECORE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
1228*8d741a5dSApple OSS DistributionsLIBCXXINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DKERNEL -DPRIVATE -UDRIVERKIT -DXNU_LIBCXX_SDKROOT -UEXCLAVEKIT -UEXCLAVECORE  -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
1229*8d741a5dSApple OSS DistributionsKINCFRAME_UNIFDEF   = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -DKERNEL -UPRIVATE -UDRIVERKIT -UEXCLAVEKIT -UEXCLAVECORE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
1230*8d741a5dSApple OSS DistributionsPDATA_UNIFDEF       = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DPRIVATE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
1231*8d741a5dSApple OSS DistributionsDATA_UNIFDEF        = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UPRIVATE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
1232*8d741a5dSApple OSS Distributions
1233*8d741a5dSApple OSS Distributions#
1234*8d741a5dSApple OSS Distributions# Compononent Header file destinations
1235*8d741a5dSApple OSS Distributions#
1236*8d741a5dSApple OSS DistributionsEXPDIR = EXPORT_HDRS/$(COMPONENT)
1237*8d741a5dSApple OSS Distributions
1238*8d741a5dSApple OSS Distributions#
1239*8d741a5dSApple OSS Distributions# Strip Flags
1240*8d741a5dSApple OSS Distributions#
1241*8d741a5dSApple OSS DistributionsSTRIP_FLAGS_RELEASE	= -S -x
1242*8d741a5dSApple OSS DistributionsSTRIP_FLAGS_DEVELOPMENT	= -S
1243*8d741a5dSApple OSS DistributionsSTRIP_FLAGS_KASAN = $(STRIP_FLAGS_DEVELOPMENT)
1244*8d741a5dSApple OSS DistributionsSTRIP_FLAGS_DEBUG	= -S
1245*8d741a5dSApple OSS DistributionsSTRIP_FLAGS_SPTM = $(STRIP_FLAGS_DEVELOPMENT)
1246*8d741a5dSApple OSS DistributionsSTRIP_FLAGS_PROFILE	= -S -x
1247*8d741a5dSApple OSS Distributions
1248*8d741a5dSApple OSS DistributionsSTRIP_FLAGS	= $($(addsuffix $(CURRENT_KERNEL_CONFIG),STRIP_FLAGS_))
1249*8d741a5dSApple OSS Distributions
1250*8d741a5dSApple OSS Distributions#
1251*8d741a5dSApple OSS Distributions# dsymutil flags
1252*8d741a5dSApple OSS Distributions#
1253*8d741a5dSApple OSS DistributionsDSYMUTIL_FLAGS_GEN	= --minimize
1254*8d741a5dSApple OSS Distributions
1255*8d741a5dSApple OSS DistributionsDSYMUTIL_FLAGS_X86_64	= --arch=x86_64
1256*8d741a5dSApple OSS DistributionsDSYMUTIL_FLAGS_X86_64H	= --arch=x86_64h
1257*8d741a5dSApple OSS DistributionsDSYMUTIL_FLAGS_ARM64	=
1258*8d741a5dSApple OSS Distributions
1259*8d741a5dSApple OSS DistributionsDSYMUTIL_FLAGS = $(DSYMUTIL_FLAGS_GEN) \
1260*8d741a5dSApple OSS Distributions	$($(addsuffix $(CURRENT_ARCH_CONFIG),DSYMUTIL_FLAGS_))
1261*8d741a5dSApple OSS Distributions
1262*8d741a5dSApple OSS Distributions
1263*8d741a5dSApple OSS Distributions
1264*8d741a5dSApple OSS Distributions
1265*8d741a5dSApple OSS Distributions#
1266*8d741a5dSApple OSS Distributions# Man Page destination
1267*8d741a5dSApple OSS Distributions#
1268*8d741a5dSApple OSS DistributionsMANDIR = /usr/share/man
1269*8d741a5dSApple OSS Distributions
1270*8d741a5dSApple OSS Distributions#
1271*8d741a5dSApple OSS Distributions# DEBUG alias location
1272*8d741a5dSApple OSS Distributions#
1273*8d741a5dSApple OSS DistributionsDEVELOPER_EXTRAS_DIR = /AppleInternal/CoreOS/xnu_$(CURRENT_KERNEL_CONFIG_LC)
1274*8d741a5dSApple OSS Distributions
1275*8d741a5dSApple OSS Distributions#
1276*8d741a5dSApple OSS Distributions# mach_kernel install location
1277*8d741a5dSApple OSS Distributions#
1278*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_DIR = /
1279*8d741a5dSApple OSS Distributions
1280*8d741a5dSApple OSS Distributions#
1281*8d741a5dSApple OSS Distributions# new OS X install location
1282*8d741a5dSApple OSS Distributions#
1283*8d741a5dSApple OSS DistributionsSYSTEM_LIBRARY_KERNELS_DIR = /System/Library/Kernels
1284*8d741a5dSApple OSS Distributions
1285*8d741a5dSApple OSS Distributions#
1286*8d741a5dSApple OSS Distributions# File names in DSTROOT
1287*8d741a5dSApple OSS Distributions#
1288*8d741a5dSApple OSS Distributions
1289*8d741a5dSApple OSS Distributionsifeq ($(PLATFORM),MacOSX)
1290*8d741a5dSApple OSS DistributionsKERNEL_FILE_NAME_PREFIX = kernel
1291*8d741a5dSApple OSS Distributionselse
1292*8d741a5dSApple OSS DistributionsKERNEL_FILE_NAME_PREFIX = mach
1293*8d741a5dSApple OSS Distributionsendif
1294*8d741a5dSApple OSS Distributions
1295*8d741a5dSApple OSS Distributionsifeq ($(CURRENT_MACHINE_CONFIG),NONE)
1296*8d741a5dSApple OSS Distributionsifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
1297*8d741a5dSApple OSS DistributionsKERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX)
1298*8d741a5dSApple OSS DistributionsKERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
1299*8d741a5dSApple OSS Distributionselse
1300*8d741a5dSApple OSS DistributionsKERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC)
1301*8d741a5dSApple OSS DistributionsKERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
1302*8d741a5dSApple OSS Distributionsendif
1303*8d741a5dSApple OSS Distributionselse
1304*8d741a5dSApple OSS DistributionsKERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_MACHINE_CONFIG_LC)
1305*8d741a5dSApple OSS DistributionsKERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX)_$(CURRENT_KERNEL_CONFIG_LC).py
1306*8d741a5dSApple OSS Distributionsendif
1307*8d741a5dSApple OSS Distributions
1308*8d741a5dSApple OSS DistributionsCURRENT_ALIAS_MACHINE_CONFIG = $(word 4,$(subst ^, ,$(CURRENT_BUILD_CONFIG)))
1309*8d741a5dSApple OSS DistributionsCURRENT_ALIAS_MACHINE_CONFIG_LC = $(shell printf "%s" "$(CURRENT_ALIAS_MACHINE_CONFIG)" | $(TR) A-Z a-z)
1310*8d741a5dSApple OSS Distributionsifneq ($(CURRENT_ALIAS_MACHINE_CONFIG),)
1311*8d741a5dSApple OSS DistributionsALIAS_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_ALIAS_MACHINE_CONFIG_LC)
1312*8d741a5dSApple OSS Distributionsendif
1313*8d741a5dSApple OSS Distributions
1314*8d741a5dSApple OSS Distributions#
1315*8d741a5dSApple OSS Distributions# System.kext pseudo-kext install location
1316*8d741a5dSApple OSS Distributions#
1317*8d741a5dSApple OSS DistributionsINSTALL_EXTENSIONS_DIR = /System/Library/Extensions
1318*8d741a5dSApple OSS DistributionsSYSTEM_KEXT_INFO_PLIST = $(addprefix $(INSTALL_EXTENSIONS_DIR),/System.kext/Info.plist)
1319*8d741a5dSApple OSS Distributions
1320*8d741a5dSApple OSS Distributions#
1321*8d741a5dSApple OSS Distributions# System.kext PlugIns install location
1322*8d741a5dSApple OSS Distributions#
1323*8d741a5dSApple OSS DistributionsDSTROOT_SYSTEM_KEXT_PATH = $(addprefix $(DSTROOT)$(INSTALL_EXTENSIONS_DIR),/System.kext/PlugIns)
1324*8d741a5dSApple OSS DistributionsSYMROOT_SYSTEM_KEXT_PATH = $(addprefix $(SYMROOT),/System.kext/PlugIns)
1325*8d741a5dSApple OSS Distributions
1326*8d741a5dSApple OSS Distributions#
1327*8d741a5dSApple OSS Distributions# KDK location
1328*8d741a5dSApple OSS Distributions#
1329*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_SYM_DIR = /System/Library/Extensions/KDK
1330*8d741a5dSApple OSS Distributions
1331*8d741a5dSApple OSS Distributions#
1332*8d741a5dSApple OSS Distributions# Misc. Etc.
1333*8d741a5dSApple OSS Distributions#
1334*8d741a5dSApple OSS DistributionsINSTALL_SHARE_MISC_DIR = /usr/share/misc
1335*8d741a5dSApple OSS DistributionsINSTALL_DTRACE_SCRIPTS_DIR = /usr/lib/dtrace
1336*8d741a5dSApple OSS DistributionsINSTALL_DTRACE_LIBEXEC_DIR = /usr/libexec/dtrace
1337*8d741a5dSApple OSS DistributionsINSTALL_ARIADNE_PLISTS_DIR = /AppleInternal/Library/Ariadne/Plists
1338*8d741a5dSApple OSS Distributions#
1339*8d741a5dSApple OSS Distributions# Generated xnu version file
1340*8d741a5dSApple OSS Distributions#
1341*8d741a5dSApple OSS DistributionsXNU_VERSION = $(OBJROOT)/xnuVersion
1342*8d741a5dSApple OSS Distributions
1343*8d741a5dSApple OSS Distributions#
1344*8d741a5dSApple OSS Distributions# Overrides for XBS build aliases
1345*8d741a5dSApple OSS Distributions#
1346*8d741a5dSApple OSS Distributionsifneq ($(filter $(RC_ProjectName),xnu_headers_driverkit),)
1347*8d741a5dSApple OSS DistributionsUSE_BINARY_PLIST = 1
1348*8d741a5dSApple OSS Distributionselse ifneq ($(filter $(RC_ProjectName),xnu_debug),)
1349*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
1350*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
1351*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_SYM_TO_KDK = 1
1352*8d741a5dSApple OSS DistributionsINSTALL_XNU_DEBUG_FILES = 1
1353*8d741a5dSApple OSS Distributionselse ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
1354*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_SYM_TO_KDK = 1
1355*8d741a5dSApple OSS DistributionsUSE_BINARY_PLIST = 1
1356*8d741a5dSApple OSS Distributionselse ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
1357*8d741a5dSApple OSS DistributionsUSE_BINARY_PLIST = 1
1358*8d741a5dSApple OSS Distributionselse ifeq ($(PLATFORM),MacOSX)
1359*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
1360*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_SYM_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
1361*8d741a5dSApple OSS DistributionsINSTALL_KERNEL_SYM_TO_KDK = $(if $(filter YES,$(DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT)),1,0)
1362*8d741a5dSApple OSS Distributionsendif
1363*8d741a5dSApple OSS Distributions
1364*8d741a5dSApple OSS Distributionsifneq ($(filter $(RC_ProjectName),xnu_kasan),)
1365*8d741a5dSApple OSS DistributionsINSTALL_KASAN_ONLY = 1
1366*8d741a5dSApple OSS Distributionsendif
1367*8d741a5dSApple OSS Distributions
1368*8d741a5dSApple OSS Distributions# vim: set ft=make:
1369