]> git.saurik.com Git - apple/xnu.git/blame - makedefs/MakeInc.def
xnu-7195.101.1.tar.gz
[apple/xnu.git] / makedefs / MakeInc.def
CommitLineData
39236c6e 1# -*- mode: makefile;-*-
1c79356b 2#
f427ee49 3# Copyright (C) 1999-2020 Apple Inc. All rights reserved.
1c79356b 4#
39236c6e
A
5# MakeInc.def contains global definitions for building,
6# linking, and installing files.
1c79356b 7#
1c79356b 8
6d2010ae 9#
39236c6e 10# Architecture Configuration options
6d2010ae 11#
d9a64523 12SUPPORTED_ARCH_CONFIGS := X86_64 X86_64H ARM ARM64
6d2010ae 13
2d21ac55 14#
39037602 15# Kernel Configuration options
1c79356b 16#
5ba3f43e 17SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE KASAN
2d21ac55 18
cb323159 19
316670eb 20#
39037602 21# Machine Configuration options
316670eb 22#
39236c6e
A
23
24SUPPORTED_X86_64_MACHINE_CONFIGS = NONE
fe8ab488 25SUPPORTED_X86_64H_MACHINE_CONFIGS = NONE
6d2010ae 26
f427ee49
A
27ifneq ($(findstring _Sim,$(RC_ProjectName)),)
28SUPPORTED_ARM_MACHINE_CONFIGS = NONE
29SUPPORTED_ARM64_MACHINE_CONFIGS = NONE
30else ifneq ($(findstring _host,$(RC_ProjectName)),)
31SUPPORTED_ARM_MACHINE_CONFIGS = NONE
32SUPPORTED_ARM64_MACHINE_CONFIGS = NONE
33else
34SUPPORTED_ARM_MACHINE_CONFIGS = T8002 T8004
2a1bd2d3 35SUPPORTED_ARM64_MACHINE_CONFIGS = T7000 T7001 S8000 S8001 T8010 T8011 BCM2837 T8020 T8101 T8103
d9a64523 36
f427ee49 37endif
6d2010ae 38
6d2010ae 39#
39236c6e 40# Setup up *_LC variables during recursive invocations
6d2010ae 41#
6d2010ae 42
39236c6e 43ifndef CURRENT_ARCH_CONFIG_LC
39037602 44 export CURRENT_ARCH_CONFIG_LC := $(shell printf "%s" "$(CURRENT_ARCH_CONFIG)" | $(TR) A-Z a-z)
6d2010ae
A
45endif
46
39236c6e
A
47ifndef CURRENT_KERNEL_CONFIG_LC
48 export CURRENT_KERNEL_CONFIG_LC := $(shell printf "%s" "$(CURRENT_KERNEL_CONFIG)" | $(TR) A-Z a-z)
316670eb 49endif
6d2010ae 50
39236c6e
A
51ifndef CURRENT_MACHINE_CONFIG_LC
52 export CURRENT_MACHINE_CONFIG_LC := $(shell printf "%s" "$(CURRENT_MACHINE_CONFIG)" | $(TR) A-Z a-z)
6d2010ae
A
53endif
54
2d21ac55 55#
39236c6e 56# Component List
2d21ac55 57#
5ba3f43e 58COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security san
39037602
A
59COMPONENT = $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))))
60COMPONENT_IMPORT_LIST = $(filter-out $(COMPONENT),$(COMPONENT_LIST))
1c79356b 61
c3c9b80d
A
62MACHINE_FLAGS_ARM64_T7000 = -DARM64_BOARD_CONFIG_T7000 -mcpu=apple-h7
63MACHINE_FLAGS_ARM64_T7001 = -DARM64_BOARD_CONFIG_T7001 -mcpu=apple-h7
64MACHINE_FLAGS_ARM64_S8000 = -DARM64_BOARD_CONFIG_S8000 -mcpu=apple-h8
65MACHINE_FLAGS_ARM64_S8001 = -DARM64_BOARD_CONFIG_S8001 -mcpu=apple-h8
d9a64523
A
66MACHINE_FLAGS_ARM_T8002 = -DARM_BOARD_CONFIG_T8002
67MACHINE_FLAGS_ARM_T8004 = -DARM_BOARD_CONFIG_T8004
68MACHINE_FLAGS_ARM64_T8010 = -DARM64_BOARD_CONFIG_T8010 -mcpu=hurricane
69MACHINE_FLAGS_ARM64_T8011 = -DARM64_BOARD_CONFIG_T8011 -mcpu=hurricane
70MACHINE_FLAGS_ARM64_BCM2837 = -DARM64_BOARD_CONFIG_BCM2837
2a1bd2d3 71MACHINE_FLAGS_ARM64_T8020 = -DARM64_BOARD_CONFIG_T8020 -mcpu=vortex
c3c9b80d
A
72MACHINE_FLAGS_ARM64_T8101 = -DARM64_BOARD_CONFIG_T8101 -mcpu=apple-a14
73MACHINE_FLAGS_ARM64_T8103 = -DARM64_BOARD_CONFIG_T8103 -mcpu=apple-a14
d9a64523 74
1c79356b 75
316670eb
A
76#
77# Deployment target flag
78#
316670eb 79ifeq ($(PLATFORM),MacOSX)
cb323159 80 DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION) -DXNU_TARGET_OS_OSX
d9a64523 81 DEPLOYMENT_LINKER_FLAGS = -Wl,-macosx_version_min,$(SDKVERSION)
cb323159
A
82else ifeq ($(PLATFORM),DriverKit)
83 DEPLOYMENT_TARGET_FLAGS = -target x86_64-apple-driverkit$(SDKVERSION) -DXNU_TARGET_OS_OSX
84 DEPLOYMENT_LINKER_FLAGS = -Wl,-target,x86_64-apple-driverkit$(SDKVERSION)
3e170ce0 85else ifeq ($(PLATFORM),WatchOS)
d9a64523
A
86 DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_WATCH
87 DEPLOYMENT_LINKER_FLAGS =
3e170ce0 88else ifeq ($(PLATFORM),tvOS)
cb323159 89 DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_TV
d9a64523 90 DEPLOYMENT_LINKER_FLAGS =
3e170ce0 91else ifeq ($(PLATFORM),AppleTVOS)
cb323159 92 DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_TV
5ba3f43e 93else ifeq ($(PLATFORM),BridgeOS)
5c9f4661 94 DEPLOYMENT_TARGET_FLAGS = -mbridgeos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_BRIDGE
d9a64523 95 DEPLOYMENT_LINKER_FLAGS =
3e170ce0 96else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
cb323159 97 DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_IOS
d9a64523 98 DEPLOYMENT_LINKER_FLAGS = -Wl,-ios_version_min,$(SDKVERSION)
3e170ce0 99else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
39236c6e 100 DEPLOYMENT_TARGET_FLAGS =
d9a64523 101 DEPLOYMENT_LINKER_FLAGS =
316670eb 102else
39236c6e 103 DEPLOYMENT_TARGET_FLAGS =
d9a64523 104 DEPLOYMENT_LINKER_FLAGS =
316670eb
A
105endif
106
3e170ce0
A
107DEPLOYMENT_TARGET_DEFINES = -DPLATFORM_$(PLATFORM)
108
39236c6e 109
f427ee49
A
110ifneq ($(RC_ENABLE_PRODUCT_INFO_FILTER),)
111SEED_DEFINES += -DRC_ENABLE_XNU_PRODUCT_INFO_FILTER
112else
113SEED_DEFINES += -URC_ENABLE_XNU_PRODUCT_INFO_FILTER
114endif
115
1c79356b
A
116#
117# Standard defines list
118#
39236c6e 119DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \
f427ee49
A
120 -DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile -DXNU_KERN_EVENT_DATA_IS_VLA \
121 $(CONFIG_DEFINES) $(SEED_DEFINES)
122
123# Enable caching with `make CCACHE=ccache`
124# This intentionally does not override $(CC) because that will confuse
125# utilities like mig.
126CCACHE ?=
1c79356b
A
127
128#
129# Compiler command
130#
f427ee49
A
131KCC = $(CCACHE) $(CC)
132KC++ = $(CCACHE) $(CXX)
9bccf70c 133
f427ee49 134GENASSYM_KCC = $(CCACHE) $(CC)
3e170ce0 135
91447636
A
136#
137# Compiler warning flags
138#
139
5ba3f43e
A
140USE_WERROR := 1
141ifneq ($(BUILD_WERROR),)
142USE_WERROR := $(BUILD_WERROR)
143endif
144
145ifeq ($(USE_WERROR),1)
146WERROR := -Werror
147endif
148
149# Shared C/C++ warning flags
cb323159 150# NOTE: order matters here. -Wno-xxx goes before opt-in of ones we want
5ba3f43e
A
151WARNFLAGS_STD := \
152 -Weverything \
a39ff7e2 153 -Wno-pedantic \
5ba3f43e 154 $(WERROR) \
39037602 155 -Wno-bad-function-cast \
39037602 156 -Wno-c++-compat \
cb323159 157 -Wno-c++98-compat \
39037602 158 -Wno-conditional-uninitialized \
39037602
A
159 -Wno-covered-switch-default \
160 -Wno-disabled-macro-expansion \
161 -Wno-documentation-unknown-command \
cb323159 162 -Wno-extra-semi-stmt \
39037602
A
163 -Wno-format-non-iso \
164 -Wno-format-nonliteral \
39037602
A
165 -Wno-language-extension-token \
166 -Wno-missing-variable-declarations \
167 -Wno-packed \
168 -Wno-padded \
169 -Wno-partial-availability \
cb323159 170 -Wno-reserved-id-macro \
39037602
A
171 -Wno-shift-sign-overflow \
172 -Wno-switch-enum \
173 -Wno-undef \
174 -Wno-unused-macros \
175 -Wno-used-but-marked-unused \
176 -Wno-variadic-macros \
177 -Wno-vla \
178 -Wno-zero-length-array
6d2010ae 179
f427ee49 180# When a new clang has new warnings disable them here until the kernel is fixed.
a39ff7e2
A
181WARNFLAGS_STD := $(WARNFLAGS_STD) \
182 -Wno-unknown-warning-option \
f427ee49
A
183 -Wno-anon-enum-enum-conversion \
184 -Wno-error=enum-enum-conversion \
185 -Wno-error=c99-designator \
186 -Wno-error=reorder-init-list
187
188# Hand-written sign conversion diagnostics are resolved, but the
189# auto-generated ones need mig and iig to be updated to fix. Disable the
190# diagnostic here until we've completed that:
191WARNFLAGS_STD := $(WARNFLAGS_STD) \
192 -Wno-sign-compare \
193 -Wno-sign-conversion
a39ff7e2 194
5ba3f43e 195CWARNFLAGS_STD = \
a39ff7e2 196 $(WARNFLAGS_STD)
5ba3f43e 197
cb323159
A
198
199
6d2010ae 200# Can be overridden in Makefile.template or Makefile.$arch
91447636
A
201export CWARNFLAGS ?= $(CWARNFLAGS_STD)
202
6d2010ae
A
203define add_perfile_cflags
204$(1)_CWARNFLAGS_ADD += $2
205endef
206
cb323159
A
207define rm_perfile_cflags
208$(1)_CFLAGS_RM += $2
209endef
210
91447636 211CXXWARNFLAGS_STD = \
5ba3f43e 212 $(WARNFLAGS_STD) \
39037602 213 -Wno-c++98-compat-pedantic \
39037602 214 -Wno-exit-time-destructors \
39037602 215 -Wno-global-constructors \
cb323159 216 -Wno-old-style-cast
91447636 217
6d2010ae 218# Can be overridden in Makefile.template or Makefile.$arch
91447636
A
219export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
220
6d2010ae
A
221define add_perfile_cxxflags
222$(1)_CXXWARNFLAGS_ADD += $2
223endef
9bccf70c 224
2d21ac55
A
225#
226# Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
227
b0d623f7 228ARCH_FLAGS_X86_64 = -arch x86_64
fe8ab488 229ARCH_FLAGS_X86_64H = -arch x86_64h
c910b4d9 230
a991bd8d
A
231ifeq ($(RC_ProjectName),xnu_libraries)
232WILL_BUILD_STATIC_KC := 1
233BUILD_STATIC_LINK := 1
234BUILD_XNU_LIBRARY := 1
235RC_NONARCH_CFLAGS += -D__BUILDING_XNU_LIBRARY__=1
236endif
237
d9a64523
A
238ifneq ($(filter ARM ARM64,$(CURRENT_ARCH_CONFIG)),)
239
f427ee49
A
240ifneq ($(findstring _Sim,$(RC_ProjectName)),)
241ARCH_FLAGS_ARM64 = -arch arm64e
242else ifneq ($(findstring _host,$(RC_ProjectName)),)
243ARCH_FLAGS_ARM64 = -arch arm64e
244else
245
d9a64523 246ifndef ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG
f427ee49
A
247
248ifneq ($(EMBEDDED_DEVICE_MAP),)
d9a64523 249export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) -query SELECT DISTINCT KernelMachOArchitecture FROM Targets WHERE KernelPlatform IS \"$(CURRENT_MACHINE_CONFIG_LC)\" LIMIT 1 || echo UNKNOWN )
f427ee49
A
250else
251# Without embdedded device map, use a default arch string
252export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell echo $(CURRENT_ARCH_CONFIG) | tr A-Z a-z)
2a1bd2d3
A
253ifneq ($(filter ARM64,$(CURRENT_ARCH_CONFIG)),)
254export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := arm64e
255endif
f427ee49 256endif
d9a64523
A
257endif
258
cb323159
A
259#
260# This can have false negatives, and is used to avoid calling CTF when we'll build a static KC
261#
262ifndef WILL_BUILD_STATIC_KC
f427ee49 263ifneq ($(EMBEDDED_DEVICE_MAP),)
cb323159
A
264export WILL_BUILD_STATIC_KC := $(shell $(EMBEDDED_DEVICE_MAP) -db $(EDM_DBPATH) \
265 -query 'SELECT COUNT(*) != 0 FROM Targets WHERE KernelPlatform IS "$(CURRENT_MACHINE_CONFIG_LC)" \
266 AND (KernelMachOArchitecture LIKE "arm64e" OR ProductType LIKE "iphone10,%")')
f427ee49
A
267else
268export WILL_BUILD_STATIC_KC := 0
269endif
cb323159
A
270endif
271
d9a64523 272BUILD_STATIC_LINK := 1
2d21ac55 273
d9a64523
A
274ARCH_FLAGS_ARM = -arch $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG)
275ARCH_FLAGS_ARM64 = -arch $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG)
276
f427ee49
A
277endif
278
d9a64523 279else
f427ee49
A
280# non arm machine config string
281ifndef ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG
282export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell echo $(CURRENT_ARCH_CONFIG) | tr A-Z a-z)
d9a64523 283endif
f427ee49 284
d9a64523 285endif
39037602 286
1c79356b
A
287#
288# Default CFLAGS
289#
5ba3f43e 290ifdef RC_NONARCH_CFLAGS
2a1bd2d3 291OTHER_CFLAGS = $(RC_NONARCH_CFLAGS)
1c79356b
A
292endif
293
39236c6e
A
294#
295# Debug info
296#
39236c6e
A
297DSYMINFODIR = Contents
298DSYMKGMACROSDIR = Contents/Resources
299DSYMLLDBMACROSDIR = Contents/Resources/Python
300DSYMDWARFDIR = Contents/Resources/DWARF
301
5ba3f43e 302DEBUG_CFLAGS := -g
39236c6e 303BUILD_DSYM := 1
2d21ac55
A
304
305#
306# We must not use -fno-keep-inline-functions, or it will remove the dtrace
307# probes from the kernel.
308#
39236c6e 309CFLAGS_GEN = $(DEBUG_CFLAGS) -nostdinc \
cb323159
A
310 -ferror-limit=10000 \
311 -fno-builtin \
312 -fno-common \
313 -ftrivial-auto-var-init=zero \
314 -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang \
315 -fsigned-bitfields \
316 -fmerge-all-constants \
317 -fno-c++-static-destructors \
318 $(OTHER_CFLAGS)
1c79356b 319
39037602
A
320CFLAGS_RELEASE =
321CFLAGS_DEVELOPMENT =
322CFLAGS_DEBUG =
5ba3f43e 323CFLAGS_KASAN = $(CFLAGS_DEVELOPMENT)
39037602 324CFLAGS_PROFILE = -pg
1c79356b 325
39236c6e 326CFLAGS_X86_64 = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
39037602 327 -DPAGE_SIZE_FIXED -mkernel -msoft-float
fe8ab488
A
328
329CFLAGS_X86_64H = $(CFLAGS_X86_64)
316670eb 330
d9a64523 331CFLAGS_ARM = -Darm -DARM -D__ARM__ -DPAGE_SIZE_FIXED \
cb323159 332 -momit-leaf-frame-pointer -fno-strict-aliasing -D__API__=v4
d9a64523 333
f427ee49
A
334LARGE_MEMORY_DEFINE=-UARM_LARGE_MEMORY
335ARM64_PLKSEG_ADDR =0xfffffff004004000
336ARM64_LINK_ADDR =0xfffffff007004000
337
338# Use ARM_LARGE_MEMORY config for all MacOSX targets.
339ifneq ($(filter $(PLATFORM),MacOSX),)
340LARGE_MEMORY_DEFINE=-DARM_LARGE_MEMORY=1
341ARM64_PLKSEG_ADDR =0xfffffe0004004000
342ARM64_LINK_ADDR =0xfffffe0007004000
343endif
344
345
346CFLAGS_ARM64 = -Darm64 -DARM64 -D__ARM64__ -DLP64 -DPAGE_SIZE_FIXED -DVM_KERNEL_LINK_ADDRESS=$(ARM64_LINK_ADDR) \
347 $(LARGE_MEMORY_DEFINE) -momit-leaf-frame-pointer -fno-strict-aliasing -D__API__=v4 -mkernel
2d21ac55 348
39236c6e
A
349CFLAGS_RELEASEX86_64 = -O2
350CFLAGS_DEVELOPMENTX86_64 = -O2
5ba3f43e 351CFLAGS_KASANX86_64 = $(CFLAGS_DEVELOPMENTX86_64)
b0d623f7 352# No space optimization for the DEBUG kernel for the benefit of gdb:
39236c6e
A
353CFLAGS_DEBUGX86_64 = -O0
354CFLAGS_PROFILEX86_64 = -O2
355
fe8ab488
A
356CFLAGS_RELEASEX86_64H = -O2
357CFLAGS_DEVELOPMENTX86_64H = -O2
5ba3f43e 358CFLAGS_KASANX86_64H = $(CFLAGS_DEVELOPMENTX86_64H)
fe8ab488
A
359# No space optimization for the DEBUG kernel for the benefit of gdb:
360CFLAGS_DEBUGX86_64H = -O0
361CFLAGS_PROFILEX86_64H = -O2
362
39236c6e
A
363CFLAGS_RELEASEARM = -O2
364CFLAGS_DEVELOPMENTARM = -O2
365CFLAGS_DEBUGARM = -O0
366CFLAGS_PROFILEARM = -O2
367
d9a64523
A
368CFLAGS_RELEASEARM64 = -O2
369CFLAGS_DEVELOPMENTARM64 = -O2
370CFLAGS_KASANARM64 = $(CFLAGS_DEVELOPMENTARM64)
371CFLAGS_DEBUGARM64 = -O0
372CFLAGS_PROFILEARM64 = -O2
5ba3f43e
A
373
374#
d9a64523 375# Sanitizers Support (KASan, UBSan)
5ba3f43e
A
376#
377
378
d9a64523
A
379SAN=0
380
f427ee49
A
381# KASan support
382#
383
5ba3f43e 384ifeq ($(CURRENT_KERNEL_CONFIG),KASAN)
cb323159
A
385# KASan kernel config implicitly enables the KASan instrumentation.
386# Instrumentation for other sanitizers is enabled explicitly at build time.
5ba3f43e
A
387KASAN = 1
388endif
389
390ifeq ($(KASAN),1)
d9a64523 391SAN=1
f427ee49
A
392BUILD_LTO=0
393
394# Shadow map scale size. With KASAN_SCALE=N, the shadow memory consumes 1/2^N of
395# the virtual address space.
396KASAN_SCALE=3
397
398KASAN_OFFSET_ARM64=0xe000000000000000
0a7de745 399#
f427ee49 400# To calculate the kasan offset, subtract the lowest KVA to sanitize, shifted right by 3 bits,
0a7de745 401# from the base address of the kasan shadow area, (e.g. solve the following equation:
f427ee49
A
402# OFFSET = {VA mapped by the first KASAN PML4 [Currently #494]} - (LOWEST_KVA >> 3)
403# OFFSET = (0ULL - (512GiB * (512 - 494))) - (LOWEST_SAN_KVA >> 3)
404# OFFSET = FFFFF70000000000 - ((0ULL - (512GiB * (512 - 496))) >> 3) [PML4 #496 is the first possible KVA]
405# OFFSET = FFFFF70000000000 - (FFFFF80000000000 >> 3)
406# OFFSET = DFFFF80000000000
0a7de745 407# ).
f427ee49
A
408KASAN_OFFSET_X86_64=0xdffff80000000000
409KASAN_OFFSET_X86_64H=$(KASAN_OFFSET_X86_64)
410KASAN_OFFSET=$($(addsuffix $(CURRENT_ARCH_CONFIG),KASAN_OFFSET_))
411KASAN_BLACKLIST=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
412CFLAGS_GEN += -DKASAN=1 -DKASAN_OFFSET=$(KASAN_OFFSET) -DKASAN_SCALE=$(KASAN_SCALE) -fsanitize=address \
5ba3f43e 413 -mllvm -asan-globals-live-support \
f427ee49
A
414 -mllvm -asan-mapping-offset=$(KASAN_OFFSET) \
415 -fsanitize-blacklist=$(KASAN_BLACKLIST)
5ba3f43e
A
416
417endif
418
d9a64523
A
419ifeq ($(UBSAN),1)
420SAN=1
cb323159
A
421UBSAN_CHECKS = signed-integer-overflow shift pointer-overflow bounds object-size # non-fatal (calls runtime, can return)
422# UBSAN_CHECKS = undefined nullability unsigned-integer-overflow # everything
d9a64523
A
423UBSAN_CHECKS_FATAL = # fatal (calls runtime, must not return)
424UBSAN_CHECKS_TRAP = vla-bound builtin # emit a trap instruction (no runtime support)
cb323159 425UBSAN_DISABLED =
d9a64523 426
cb323159
A
427UBSAN_DISABLED += vptr function # requires unsupported C++ runtime
428ifeq ($(KASAN),1)
429# UBSan alignment + KASan code size is too large
430# UBSan unreachable doesn't play nice with ASan (40723397)
431UBSAN_DISABLED += alignment unreachable
d9a64523
A
432endif
433
434CFLAGS_GEN += -DUBSAN=1
435CFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS) $(UBSAN_CHECKS_FATAL) $(UBSAN_CHECKS_TRAP),-fsanitize=$(x))
436CFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS_FATAL),-fno-sanitize-recover=$(x))
437CFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS_TRAP),-fsanitize-trap=$(x))
cb323159
A
438CFLAGS_GEN += $(foreach x,$(UBSAN_DISABLED),-fno-sanitize=$(x))
439endif
440
441ifeq ($(KSANCOV),1)
442# Enable SanitizerCoverage instrumentation in xnu
443SAN = 1
444KSANCOV_CFLAGS := -fsanitize-coverage=trace-pc-guard
445CFLAGS_GEN += $(KSANCOV_CFLAGS) -DKSANCOV=1
d9a64523
A
446endif
447
448ifeq ($(SAN),1)
449CFLAGS_GEN += -fsanitize-blacklist=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
450endif
451
cb323159 452
39037602 453CFLAGS = $(CFLAGS_GEN) \
39236c6e
A
454 $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
455 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
456 $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) \
457 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_)) \
458 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_))) \
316670eb 459 $(DEPLOYMENT_TARGET_FLAGS) \
3e170ce0 460 $(DEPLOYMENT_TARGET_DEFINES) \
1c79356b
A
461 $(DEFINES)
462
6d2010ae 463#
55e303ae 464# Default C++ flags
1c79356b 465#
6d2010ae
A
466
467OTHER_CXXFLAGS =
316670eb 468
cb323159 469CXXFLAGS_GEN = -std=gnu++1z -fsized-deallocation -fapple-kext $(OTHER_CXXFLAGS)
fe8ab488 470
55e303ae 471CXXFLAGS = $(CXXFLAGS_GEN) \
39236c6e
A
472 $($(addsuffix $(CURRENT_ARCH_CONFIG),CXXFLAGS_)) \
473 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CXXFLAGS_))
474
1c79356b
A
475#
476# Assembler command
477#
f427ee49 478AS = $(CCACHE) $(CC)
0c530ab8 479S_KCC = $(CC)
1c79356b
A
480
481#
482# Default SFLAGS
483#
fe8ab488 484SFLAGS_GEN = -D__ASSEMBLER__ -DASSEMBLER $(OTHER_CFLAGS)
1c79356b 485
39037602
A
486SFLAGS_RELEASE =
487SFLAGS_DEVELOPMENT =
5ba3f43e 488SFLAGS_KASAN = $(SFLAGS_DEVELOPMENT) -DKASAN=1
39037602
A
489SFLAGS_DEBUG =
490SFLAGS_PROFILE =
1c79356b 491
39037602
A
492SFLAGS_X86_64 = $(CFLAGS_X86_64)
493SFLAGS_X86_64H = $(CFLAGS_X86_64H)
d9a64523
A
494SFLAGS_ARM = $(CFLAGS_ARM)
495SFLAGS_ARM64 = $(CFLAGS_ARM64)
1c79356b 496
39037602 497SFLAGS = $(SFLAGS_GEN) \
39236c6e
A
498 $($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
499 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
500 $($(addsuffix $(CURRENT_ARCH_CONFIG),SFLAGS_)) \
501 $($(addsuffix $(CURRENT_KERNEL_CONFIG),SFLAGS_)) \
316670eb 502 $(DEPLOYMENT_TARGET_FLAGS) \
3e170ce0 503 $(DEPLOYMENT_TARGET_DEFINES) \
1c79356b
A
504 $(DEFINES)
505
506#
507# Linker command
508#
0c530ab8 509LD = $(KC++) -nostdlib
1c79356b
A
510
511#
512# Default LDFLAGS
513#
39236c6e
A
514# Availability of DWARF allows DTrace CTF (compressed type format) to be constructed.
515# ctf_insert creates the CTF section. It needs reserved padding in the
516# headers for the load command segment and the CTF section structures.
517#
518LDFLAGS_KERNEL_GEN = \
6d2010ae 519 -nostdlib \
0c530ab8 520 -fapple-kext \
0c530ab8 521 -Wl,-e,__start \
0c530ab8 522 -Wl,-sectalign,__TEXT,__text,0x1000 \
f427ee49 523 -Wl,-sectalign,__DATA,__percpu,0x80 \
0c530ab8
A
524 -Wl,-sectalign,__DATA,__common,0x1000 \
525 -Wl,-sectalign,__DATA,__bss,0x1000 \
d9a64523 526 -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
f427ee49 527 -Wl,-segprot,__PRELINK_TEXT,r-x,r-x \
316670eb
A
528 -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
529 -Wl,-new_linker \
530 -Wl,-pagezero_size,0x0 \
531 -Wl,-version_load_command \
39236c6e
A
532 -Wl,-function_starts \
533 -Wl,-headerpad,152
b0d623f7 534
d9a64523
A
535# LDFLAGS_KERNEL_SDK = -L$(SDKROOT)/usr/local/lib/kernel -lfirehose_kernel
536LDFLAGS_KERNEL_SDK = -L$(SDKROOT)/usr/local/lib/kernel
39037602
A
537
538LDFLAGS_KERNEL_RELEASE =
5ba3f43e
A
539LDFLAGS_KERNEL_DEVELOPMENT =
540LDFLAGS_KERNEL_KASAN = $(LDFLAGS_KERNEL_DEVELOPMENT)
39037602
A
541LDFLAGS_KERNEL_DEBUG =
542LDFLAGS_KERNEL_PROFILE =
b0d623f7 543
316670eb
A
544# KASLR static slide config:
545ifndef SLIDE
546SLIDE=0x00
547endif
39236c6e
A
548KERNEL_MIN_ADDRESS = 0xffffff8000000000
549KERNEL_BASE_OFFSET = 0x100000
550KERNEL_STATIC_SLIDE = $(shell printf "0x%016x" \
551 $$[ $(SLIDE) << 21 ])
552KERNEL_STATIC_BASE = $(shell printf "0x%016x" \
553 $$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ])
554KERNEL_HIB_SECTION_BASE = $(shell printf "0x%016x" \
555 $$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ])
556KERNEL_TEXT_BASE = $(shell printf "0x%016x" \
557 $$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ])
558
559LDFLAGS_KERNEL_RELEASEX86_64 = \
316670eb
A
560 -Wl,-pie \
561 -Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \
562 -Wl,-image_base,$(KERNEL_TEXT_BASE) \
563 -Wl,-seg_page_size,__TEXT,0x200000 \
316670eb
A
564 -Wl,-sectalign,__HIB,__bootPT,0x1000 \
565 -Wl,-sectalign,__HIB,__desc,0x1000 \
566 -Wl,-sectalign,__HIB,__data,0x1000 \
567 -Wl,-sectalign,__HIB,__text,0x1000 \
568 -Wl,-sectalign,__HIB,__const,0x1000 \
569 -Wl,-sectalign,__HIB,__bss,0x1000 \
570 -Wl,-sectalign,__HIB,__common,0x1000 \
3e170ce0
A
571 -Wl,-sectalign,__HIB,__llvm_prf_cnts,0x1000 \
572 -Wl,-sectalign,__HIB,__llvm_prf_names,0x1000 \
573 -Wl,-sectalign,__HIB,__llvm_prf_data,0x1000 \
574 -Wl,-sectalign,__HIB,__textcoal_nt,0x1000 \
f427ee49 575 -Wl,-sectalign,__HIB,__cstring,0x1000 \
cb323159 576 -Wl,-rename_section,__DATA,__const,__DATA_CONST,__const \
f427ee49 577 -Wl,-segprot,__DATA_CONST,r--,r-- \
c3c9b80d
A
578 -Wl,-rename_section,__KLD,__const,__KLDDATA,__const \
579 -Wl,-rename_section,__KLD,__cstring,__KLDDATA,__cstring \
580 -Wl,-segprot,__KLDDATA,rw-,rw- \
581 -Wl,-segprot,__KLD,r-x,r-x \
39037602 582 -Wl,-no_zero_fill_sections \
39236c6e 583 $(LDFLAGS_NOSTRIP_FLAG)
316670eb 584
d9a64523
A
585ifeq ($(SAN),1)
586LDFLAGS_KERNEL_RELEASEX86_64 += \
587 -Wl,-sectalign,__HIB,__cstring,0x1000
588endif
589
cb323159 590ifeq ($(KSANCOV),1)
5ba3f43e 591LDFLAGS_KERNEL_RELEASEX86_64 += \
cb323159
A
592 -Wl,-sectalign,__HIB,__sancov_guards,0x1000 \
593 -Wl,-sectalign,__HIB,__sancov_pcs,0x1000
5ba3f43e
A
594endif
595
316670eb 596# Define KERNEL_BASE_OFFSET so known at compile time:
39236c6e 597CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
fe8ab488 598CFLAGS_X86_64H += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
2d21ac55 599
39236c6e
A
600LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
601LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
cb323159
A
602LDFLAGS_KERNEL_KASANX86_64 = $(LDFLAGS_KERNEL_DEVELOPMENTX86_64) \
603 -Wl,-sectalign,__HIB,__asan_globals,0x1000 \
604 -Wl,-sectalign,__HIB,__asan_liveness,0x1000 \
605 -Wl,-sectalign,__HIB,__mod_term_func,0x1000 \
606 -Wl,-rename_section,__HIB,__mod_init_func,__NULL,__mod_init_func \
607 -Wl,-rename_section,__HIB,__eh_frame,__NULL,__eh_frame
39236c6e 608LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
d1ecb069 609
fe8ab488
A
610LDFLAGS_KERNEL_RELEASEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64)
611LDFLAGS_KERNEL_DEBUGX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
612LDFLAGS_KERNEL_DEVELOPMENTX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
cb323159 613LDFLAGS_KERNEL_KASANX86_64H = $(LDFLAGS_KERNEL_KASANX86_64)
fe8ab488
A
614LDFLAGS_KERNEL_PROFILEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
615
d9a64523
A
616# We preload ___udivmoddi4 in order to work around an issue with building
617# LTO on armv7.
618LDFLAGS_KERNEL_GENARM = \
619 -Wl,-pie \
620 -Wl,-static \
621 -Wl,-image_base,0x80001000 \
622 -Wl,-sectalign,__DATA,__const,0x1000 \
c3c9b80d
A
623 -Wl,-u,___udivmoddi4 \
624 -Wl,-rename_section,__KLD,__const,__KLDDATA,__const \
625 -Wl,-rename_section,__KLD,__cstring,__KLDDATA,__cstring \
626 -Wl,-segprot,__KLDDATA,rw-,rw- \
627 -Wl,-segprot,__KLD,r-x,r-x
d9a64523
A
628
629LDFLAGS_KERNEL_RELEASEARM = \
cb323159
A
630 $(LDFLAGS_KERNEL_GENARM) \
631 $(LDFLAGS_KERNEL_STRIP_LTO)
d9a64523 632
f427ee49 633LDFLAGS_KERNEL_ONLY_CONFIG_RELEASEARM = \
d9a64523
A
634 -Wl,-exported_symbols_list,$(TARGET)/all-kpi.exp
635
636LDFLAGS_KERNEL_DEVELOPMENTARM = \
637 $(LDFLAGS_KERNEL_GENARM) \
638 $(LDFLAGS_NOSTRIP_FLAG)
639
f427ee49 640LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM =
d9a64523
A
641
642LDFLAGS_KERNEL_DEBUGARM = $(LDFLAGS_KERNEL_DEVELOPMENTARM)
f427ee49 643LDFLAGS_KERNEL_ONLY_CONFIG_DEBUGARM = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM)
d9a64523
A
644
645# Offset image base by page to have iBoot load kernel TEXT correctly.
646# First page is used for various purposes : sleep token, reset vector.
647# We also need a 32MB offset, as this is the minimum block mapping size
648# for a 16KB page runtime, and we wish to use the first virtual block
649# to map the low globals page. We also need another 4MB to account for
650# the address space reserved by L4 (because the reservation is not a
651# multiple of the block size in alignment/length, we will implictly map
652# it with our block mapping, and we therefore must reflect that the
653# first 4MB of the block mapping for xnu do not belong to xnu).
654# For the moment, kaliber has a unique memory layout (monitor at the top
655# of memory). Support this by breaking 16KB on other platforms and
656# mandating 32MB alignment. Image base (i.e. __TEXT) must be 16KB
657# aligned since ld64 will link with 16KB alignment for ARM64.
658#
659# We currently offset by an additional 32MB in order to reclaim memory.
660# We need a dedicated virtual page for the low globals. Our bootloader
661# may have a significant chunk of memory (up to an L2 entry in size)
662# that lies before the kernel. The addition 32MB of virtual padding
663# ensures that we have enough virtual address space to map all of that
664# memory as part of the V-to-P mapping.
665# 23355738 - put __PRELINK_TEXT first. We reserve enough room
666# for 0x0000000003000000 = 48MB of kexts
667#
668# 0xfffffff000000000 (32MB range for low globals)
669# 0xfffffff002000000 (32MB range to allow for large page physical slide)
670# 0xfffffff004000000 (16KB range to reserve the first available page)
671# 0xfffffff004004000 (48MB range for kexts)
672# 0xfffffff007004000 (Start of xnu proper).
673LDFLAGS_KERNEL_GENARM64 = \
674 -Wl,-pie \
675 -Wl,-static \
f427ee49
A
676 -Wl,-segaddr,__PRELINK_TEXT,$(ARM64_PLKSEG_ADDR) \
677 -Wl,-image_base,$(ARM64_LINK_ADDR) \
678 \
679 -Wl,-rename_section,__HIB,__text,__TEXT_EXEC,__hib_text \
680 \
681 -Wl,-rename_section,__HIB,__const,__DATA_CONST,__hib_const \
682 -Wl,-rename_section,__HIB,__cstring,__DATA_CONST,__hib_const \
683 -Wl,-rename_section,__HIB,__literal8,__DATA_CONST,__hib_const \
684 -Wl,-rename_section,__HIB,__literal16,__DATA_CONST,__hib_const \
685 \
686 -Wl,-rename_segment,__HIB,__HIBDATA \
687 \
d9a64523 688 -Wl,-sectalign,__DATA,__const,0x4000 \
f427ee49 689 -Wl,-sectalign,__DATA,__data,0x4000 \
d9a64523
A
690 -Wl,-rename_section,__DATA,__mod_init_func,__DATA_CONST,__mod_init_func \
691 -Wl,-rename_section,__DATA,__mod_term_func,__DATA_CONST,__mod_term_func \
0a7de745
A
692 -Wl,-rename_section,__DATA,__auth_ptr,__DATA_CONST,__auth_ptr \
693 -Wl,-rename_section,__DATA,__auth_got,__DATA_CONST,__auth_got \
d9a64523 694 -Wl,-rename_section,__DATA,__const,__DATA_CONST,__const \
f427ee49 695 -Wl,-segprot,__DATA_CONST,r--,r-- \
c3c9b80d
A
696 -Wl,-rename_section,__KLD,__const,__KLDDATA,__const \
697 -Wl,-rename_section,__KLD,__cstring,__KLDDATA,__cstring \
698 -Wl,-segprot,__KLDDATA,rw-,rw- \
699 -Wl,-segprot,__KLD,r-x,r-x \
d9a64523
A
700 -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text \
701 -Wl,-rename_section,__TEXT,__stubs,__TEXT_EXEC,__stubs \
d9a64523
A
702 -Wl,-sectcreate,"__PLK_TEXT_EXEC",__text,/dev/null \
703 -Wl,-sectcreate,__PRELINK_DATA,__data,/dev/null \
704 -Wl,-sectcreate,"__PLK_DATA_CONST",__data,/dev/null \
705 -Wl,-sectcreate,"__PLK_LLVM_COV",__llvm_covmap,/dev/null \
706 -Wl,-sectcreate,"__PLK_LINKEDIT",__data,/dev/null
707
2a1bd2d3
A
708LDFLAGS_KERNEL_SEGARM64 = \
709 -Wl,-rename_section,__PPLDATA,__const,__PPLDATA_CONST,__const \
c3c9b80d
A
710 -Wl,-segment_order,__TEXT:__DATA_CONST:__LINKEDIT:__TEXT_EXEC:__KLD:__PPLTEXT:__PPLTRAMP:__PPLDATA_CONST:__LASTDATA_CONST:__LAST:__PPLDATA:__KLDDATA:__DATA:__HIBDATA:__BOOTDATA \
711 -Wl,-segprot,__PPLTEXT,r-x,r-x -Wl,-segprot,__PPLTRAMP,r-x,r-x -Wl,-segprot,__PPLDATA_CONST,r--,r-- -Wl,-segprot,__LASTDATA_CONST,r--,r-- -Wl,-segprot,__LAST,r-x,r-x \
d9a64523
A
712
713LDFLAGS_KERNEL_RELEASEARM64 = \
714 $(LDFLAGS_KERNEL_GENARM64) \
cb323159
A
715 $(LDFLAGS_KERNEL_SEGARM64) \
716 $(LDFLAGS_KERNEL_STRIP_LTO)
d9a64523 717
f427ee49 718LDFLAGS_KERNEL_ONLY_CONFIG_RELEASEARM64 = \
d9a64523
A
719 -Wl,-exported_symbols_list,$(TARGET)/all-kpi.exp
720
721LDFLAGS_KERNEL_DEVELOPMENTARM64 = \
722 $(LDFLAGS_KERNEL_GENARM64) \
723 $(LDFLAGS_KERNEL_SEGARM64) \
724 $(LDFLAGS_NOSTRIP_FLAG)
725
f427ee49 726LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64 =
d9a64523
A
727
728LDFLAGS_KERNEL_KASANARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
729LDFLAGS_KERNEL_DEBUGARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
730
f427ee49
A
731LDFLAGS_KERNEL_ONLY_CONFIG_KASANARM64 = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64)
732LDFLAGS_KERNEL_ONLY_CONFIG_DEBUGARM64 = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64)
733
734#
735# arm64e specific linker flags that should be used only when linking the kernel
736# (and not the static kernel cache / kcgen)
737#
738LDFLAGS_KERNEL_ONLY_SUBARCH_arm64e = \
739 -Wl,-add_split_seg_info \
740 -Wl,-kernel
741
742LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64 = \
743 -Wl,-add_split_seg_info \
744 -Wl,-kernel
745LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64h = $(LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64)
d1ecb069 746
39236c6e 747LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
39037602 748 $(LDFLAGS_KERNEL_SDK) \
39236c6e
A
749 $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
750 $($(addsuffix $(CURRENT_ARCH_CONFIG),LDFLAGS_KERNEL_)) \
751 $($(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
752 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
316670eb 753 $(DEPLOYMENT_TARGET_FLAGS)
1c79356b 754
2a1bd2d3 755LDFLAGS_KERNEL_ONLY += \
f427ee49
A
756 $($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_ONLY_CONFIG_))) \
757 $($(addsuffix $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG),LDFLAGS_KERNEL_ONLY_SUBARCH_)) \
758 -Wl,-alias_list,$(TARGET)/all-alias.exp \
759 -Wl,-sectcreate,__LINKINFO,__symbolsets,$(TARGET)/symbolsets.plist -Wl,-segprot,__LINKINFO,r--,r--
d9a64523 760
1c79356b
A
761#
762# Default runtime libraries to be linked with the kernel
763#
d9a64523
A
764LD_KERNEL_LIBS = -lcc_kext
765LD_KERNEL_ARCHIVES = $(LDFLAGS_KERNEL_SDK) -lfirehose_kernel
2a1bd2d3 766# Link opensource binary library
a991bd8d
A
767ifneq ($(filter T8020 T8101 T8020 T8101,$(CURRENT_MACHINE_CONFIG)),)
768 LDFLAGS_KERNEL_ONLY += -rdynamic -Wl,-force_load,$(KDKROOT)/System/Library/KernelSupport/lib$(CURRENT_MACHINE_CONFIG).os.$(CURRENT_KERNEL_CONFIG).a
2a1bd2d3
A
769endif
770
39236c6e
A
771#
772# DTrace support
773#
cb323159
A
774ifndef DO_CTFMERGE
775DO_CTFMERGE := 1
39236c6e 776ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
f427ee49 777ifneq ($(PLATFORM),MacOSX)
cb323159 778DO_CTFMERGE := 0
39236c6e 779endif
39236c6e 780endif
cb323159 781ifneq ($(CURRENT_KERNEL_CONFIG),KASAN)
f427ee49 782ifneq ($(PLATFORM),MacOSX)
cb323159
A
783ifeq ($(WILL_BUILD_STATIC_KC),1)
784DO_CTFMERGE := 0
785endif
786endif
f427ee49 787endif
cb323159
A
788endif # DO_CTFMERGE
789
b0d623f7 790
1c79356b
A
791#
792# Default INCFLAGS
793#
39037602
A
794INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
795INCFLAGS_EXTERN = -I$(SRCROOT)/EXTERNAL_HEADERS
39236c6e
A
796INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
797INCFLAGS_LOCAL = -I.
39037602 798INCFLAGS_SDK = -I$(SDKROOT)/usr/local/include/kernel
1c79356b 799
39037602 800INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) $(INCFLAGS_SDK)
1c79356b
A
801
802#
803# Default MIGFLAGS
804#
fe8ab488 805MIGFLAGS = $(DEFINES) $(INCFLAGS) -novouchers $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
39236c6e 806 $(DEPLOYMENT_TARGET_FLAGS)
316670eb 807
3e170ce0
A
808# Support for LLVM Profile Guided Optimization (PGO)
809
810ifeq ($(BUILD_PROFILE),1)
811CFLAGS_GEN += -fprofile-instr-generate -DPROFILE
812CXXFLAGS_GEN += -fprofile-instr-generate -DPROFILE
813endif
814
815ifdef USE_PROFILE
816CFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
817CXXFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
818LDFLAGS_KERNEL_GEN += -fprofile-instr-use=$(USE_PROFILE)
819
820CFLAGS_GEN += -Wno-error=profile-instr-out-of-date
821endif
822
316670eb
A
823#
824# Support for LLVM Link Time Optimization (LTO)
825#
fe8ab488
A
826# LTO can be explicitly enabled or disabled with BUILD_LTO=1|0
827# and defaults to enabled except for DEBUG kernels
828#
39236c6e
A
829# CFLAGS_NOLTO_FLAG is needed on a per-file basis (for files
830# that deal poorly with LTO, or files that must be machine
831# code *.o files for xnu to build (i.e, setsegname runs on
832# them).
833#
834# LDFLAGS_NOSTRIP_FLAG is used to support configurations that
835# do not utilize an export list. For these configs to build,
836# we need to prevent the LTO logic from dead stripping them.
316670eb 837
fe8ab488
A
838LTO_ENABLED_RELEASE = 1
839LTO_ENABLED_DEVELOPMENT = 1
840LTO_ENABLED_DEBUG = 0
5ba3f43e 841LTO_ENABLED_KASAN = 0
fe8ab488
A
842
843ifneq ($(BUILD_LTO),)
844USE_LTO = $(BUILD_LTO)
845else
846USE_LTO = $(LTO_ENABLED_$(CURRENT_KERNEL_CONFIG))
847endif
848
849ifeq ($(USE_LTO),1)
39236c6e
A
850CFLAGS_GEN += -flto
851CXXFLAGS_GEN += -flto
cb323159
A
852LDFLAGS_KERNEL_LTO = -Wl,-mllvm,-inline-threshold=100
853LDFLAGS_KERNEL_GEN += $(LDFLAGS_KERNEL_LTO) -Wl,-object_path_lto,$(TARGET)/lto.o
39236c6e 854LDFLAGS_NOSTRIP_FLAG = -rdynamic
cb323159
A
855LDFLAGS_KERNEL_STRIP_LTO = -Wl,-dead_strip,-no_dead_strip_inits_and_terms
856
39236c6e 857CFLAGS_NOLTO_FLAG = -fno-lto
316670eb 858else
cb323159 859LDFLAGS_KERNEL_LTO =
39236c6e 860LDFLAGS_NOSTRIP_FLAG =
cb323159 861LDFLAGS_KERNEL_STRIP_LTO =
39236c6e 862CFLAGS_NOLTO_FLAG =
316670eb 863endif
1c79356b 864
3e170ce0
A
865ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
866BUILD_DSYM := 0
cb323159 867DO_CTFMERGE := 0
3e170ce0
A
868KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
869KC++ = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CXX)
870S_KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
871STRIP = true
872endif
873
1c79356b
A
874#
875# Default VPATH
876#
39236c6e 877export VPATH = .:$(SOURCE)
1c79356b 878
813fb2f6
A
879
880
1c79356b 881#
2d21ac55 882# Macros that control installation of kernel and its header files
1c79356b
A
883#
884# install flags for header files
39037602 885#
39236c6e
A
886INSTALL_FLAGS = -c -S -m 0444
887DATA_INSTALL_FLAGS = -c -S -m 0644
f427ee49 888DATA_INSTALL_FLAGS_RO = -c -S -m 0444
39236c6e 889EXEC_INSTALL_FLAGS = -c -S -m 0755
1c79356b
A
890
891#
892# Header file destinations
893#
cb323159
A
894
895ifeq ($(DRIVERKIT),1)
896 SDKHEADERSROOT=$(DRIVERKITRUNTIMEROOT)
897 # only whitelisted headers install outside of the DriverKit Runtime hierarchy
898 DRIVERKITSDKHEADERSROOT=$(DRIVERKITROOT)
899 DRIVERKITFRAMEDIR = $(DRIVERKITROOT)/System/Library/Frameworks
900endif
901
902FRAMEDIR = $(SDKHEADERSROOT)/System/Library/Frameworks
6d2010ae
A
903
904SINCVERS = B
905SINCFRAME = $(FRAMEDIR)/System.framework
906SINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers
907SPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders
908SRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources
909
1c79356b 910ifndef INCDIR
cb323159
A
911 INCDIR = $(SDKHEADERSROOT)/usr/include
912endif
913ifndef DRIVERKITINCDIR
914 DRIVERKITINCDIR = $(DRIVERKITSDKHEADERSROOT)/usr/include
1c79356b
A
915endif
916ifndef LCLDIR
f427ee49
A
917 ifeq ($(LIBKERN_USE_USR_LOCAL_INCLUDE),)
918 LCLDIR = $(SPINCDIR)
919 else
920 LCLDIR = $(SDKHEADERSROOT)/usr/local/include
921 endif
1c79356b 922endif
cb323159
A
923ifndef DRIVERKITLCLDIR
924 DRIVERKITLCLDIR = $(DRIVERKITSDKHEADERSROOT)/usr/local/include
925endif
1c79356b
A
926
927KINCVERS = A
928KINCFRAME = $(FRAMEDIR)/Kernel.framework
929KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
0b4e3aa0 930KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
91447636
A
931KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
932
cb323159
A
933DKIT_INCVERS = A
934DKIT_INCFRAME = DriverKit.framework
935DKIT_INCDIR = $(DKIT_INCFRAME)/Versions/$(DKIT_INCVERS)/Headers
936DKIT_PINCDIR = $(DKIT_INCFRAME)/Versions/$(DKIT_INCVERS)/PrivateHeaders
937# DriverKit SDK frameworks use shallow bundle structure
938DRIVERKIT_DKIT_INCDIR = $(DKIT_INCFRAME)/Headers
939DRIVERKIT_DKIT_PINCDIR = $(DKIT_INCFRAME)/PrivateHeaders
940
91447636
A
941XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
942
6d2010ae 943
39236c6e
A
944PLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DPLATFORM_$(x) $(foreach token,$(PLATFORM_UNIFDEF_BLACKLIST_TOKENS_$(x)),-U$(token)),-UPLATFORM_$(x)))
945
d9a64523 946
cb323159
A
947SPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -UDRIVERKIT -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
948SINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -UDRIVERKIT -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
949DKPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -DDRIVERKIT -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
950DKINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -DDRIVERKIT -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
951KPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DKERNEL -DPRIVATE -UDRIVERKIT -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
952KINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -DKERNEL -UPRIVATE -UDRIVERKIT -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
953DATA_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
1c79356b
A
954
955#
39236c6e 956# Compononent Header file destinations
1c79356b
A
957#
958EXPDIR = EXPORT_HDRS/$(COMPONENT)
959
960#
961# Strip Flags
962#
39037602
A
963STRIP_FLAGS_RELEASE = -S -x
964STRIP_FLAGS_DEVELOPMENT = -S
5ba3f43e 965STRIP_FLAGS_KASAN = $(STRIP_FLAGS_DEVELOPMENT)
39037602 966STRIP_FLAGS_DEBUG = -S
39236c6e 967STRIP_FLAGS_PROFILE = -S -x
1c79356b 968
39037602 969STRIP_FLAGS = $($(addsuffix $(CURRENT_KERNEL_CONFIG),STRIP_FLAGS_))
1c79356b 970
2d21ac55
A
971#
972# dsymutil flags
973#
fe8ab488 974DSYMUTIL_FLAGS_GEN = --minimize
2d21ac55 975
fe8ab488
A
976DSYMUTIL_FLAGS_X86_64 = --arch=x86_64
977DSYMUTIL_FLAGS_X86_64H = --arch=x86_64h
d9a64523
A
978DSYMUTIL_FLAGS_ARM = --arch=arm
979DSYMUTIL_FLAGS_ARM64 =
fe8ab488
A
980
981DSYMUTIL_FLAGS = $(DSYMUTIL_FLAGS_GEN) \
982 $($(addsuffix $(CURRENT_ARCH_CONFIG),DSYMUTIL_FLAGS_))
2d21ac55 983
9bccf70c
A
984#
985# Man Page destination
986#
39236c6e 987MANDIR = /usr/share/man
9bccf70c 988
b0d623f7
A
989#
990# DEBUG alias location
991#
5ba3f43e 992DEVELOPER_EXTRAS_DIR = /AppleInternal/CoreOS/xnu_$(CURRENT_KERNEL_CONFIG_LC)
2d21ac55 993
1c79356b 994#
39236c6e 995# mach_kernel install location
1c79356b 996#
39236c6e 997INSTALL_KERNEL_DIR = /
1c79356b 998
fe8ab488
A
999#
1000# new OS X install location
1001#
1002SYSTEM_LIBRARY_KERNELS_DIR = /System/Library/Kernels
1003
1004#
1005# File names in DSTROOT
1006#
1007
1008ifeq ($(PLATFORM),MacOSX)
1009KERNEL_FILE_NAME_PREFIX = kernel
1010else
1011KERNEL_FILE_NAME_PREFIX = mach
1012endif
1013
1014ifeq ($(CURRENT_MACHINE_CONFIG),NONE)
1015ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
1016KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX)
1017KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
1018else
1019KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC)
1020KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
1021endif
1022else
1023KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_MACHINE_CONFIG_LC)
1024KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX)_$(CURRENT_KERNEL_CONFIG_LC).py
1025endif
1026
39037602
A
1027CURRENT_ALIAS_MACHINE_CONFIG = $(word 4,$(subst ^, ,$(CURRENT_BUILD_CONFIG)))
1028CURRENT_ALIAS_MACHINE_CONFIG_LC = $(shell printf "%s" "$(CURRENT_ALIAS_MACHINE_CONFIG)" | $(TR) A-Z a-z)
1029ifneq ($(CURRENT_ALIAS_MACHINE_CONFIG),)
1030ALIAS_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_ALIAS_MACHINE_CONFIG_LC)
1031endif
1032
39236c6e
A
1033#
1034# System.kext pseudo-kext install location
1035#
1036INSTALL_EXTENSIONS_DIR = /System/Library/Extensions
1037
1038#
fe8ab488 1039# KDK location
39236c6e
A
1040#
1041INSTALL_KERNEL_SYM_DIR = /System/Library/Extensions/KDK
1042
1043#
1044# Misc. Etc.
1045#
1046INSTALL_SHARE_MISC_DIR = /usr/share/misc
1047INSTALL_DTRACE_SCRIPTS_DIR = /usr/lib/dtrace
39037602 1048INSTALL_DTRACE_LIBEXEC_DIR = /usr/libexec/dtrace
39236c6e
A
1049
1050#
1051# Overrides for XBS build aliases
1052#
f427ee49 1053ifneq ($(filter $(RC_ProjectName),xnu_debug),)
39236c6e 1054INSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
fe8ab488
A
1055INSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
1056INSTALL_KERNEL_SYM_TO_KDK = 1
39236c6e 1057INSTALL_XNU_DEBUG_FILES = 1
3e170ce0 1058else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
39236c6e
A
1059INSTALL_KERNEL_SYM_TO_KDK = 1
1060USE_BINARY_PLIST = 1
3e170ce0 1061else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
39236c6e 1062USE_BINARY_PLIST = 1
fe8ab488
A
1063else ifeq ($(PLATFORM),MacOSX)
1064INSTALL_KERNEL_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
1065INSTALL_KERNEL_SYM_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
1066INSTALL_KERNEL_SYM_TO_KDK = $(if $(filter YES,$(DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT)),1,0)
39236c6e 1067endif
1c79356b 1068
f427ee49 1069ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
5c9f4661
A
1070INSTALL_KASAN_ONLY = 1
1071endif
1072
2d21ac55 1073# vim: set ft=make: