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