]> git.saurik.com Git - apple/xnu.git/blob - makedefs/MakeInc.def
b2e90a4a3367bc616b92bf9c2e55d65530220f38
[apple/xnu.git] / makedefs / MakeInc.def
1 # -*- mode: makefile;-*-
2 #
3 # Copyright (C) 1999-2020 Apple Inc. All rights reserved.
4 #
5 # MakeInc.def contains global definitions for building,
6 # linking, and installing files.
7 #
8
9 #
10 # Architecture Configuration options
11 #
12 SUPPORTED_ARCH_CONFIGS := X86_64 X86_64H ARM ARM64
13
14 #
15 # Kernel Configuration options
16 #
17 SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE KASAN
18
19
20 #
21 # Machine Configuration options
22 #
23
24 SUPPORTED_X86_64_MACHINE_CONFIGS = NONE
25 SUPPORTED_X86_64H_MACHINE_CONFIGS = NONE
26
27 ifneq ($(findstring _Sim,$(RC_ProjectName)),)
28 SUPPORTED_ARM_MACHINE_CONFIGS = NONE
29 SUPPORTED_ARM64_MACHINE_CONFIGS = NONE
30 else ifneq ($(findstring _host,$(RC_ProjectName)),)
31 SUPPORTED_ARM_MACHINE_CONFIGS = NONE
32 SUPPORTED_ARM64_MACHINE_CONFIGS = NONE
33 else
34 SUPPORTED_ARM_MACHINE_CONFIGS = T8002 T8004
35 SUPPORTED_ARM64_MACHINE_CONFIGS = T7000 T7001 S8000 S8001 T8010 T8011 BCM2837 T8020 T8101 T8103
36
37 endif
38
39 #
40 # Setup up *_LC variables during recursive invocations
41 #
42
43 ifndef CURRENT_ARCH_CONFIG_LC
44 export CURRENT_ARCH_CONFIG_LC := $(shell printf "%s" "$(CURRENT_ARCH_CONFIG)" | $(TR) A-Z a-z)
45 endif
46
47 ifndef CURRENT_KERNEL_CONFIG_LC
48 export CURRENT_KERNEL_CONFIG_LC := $(shell printf "%s" "$(CURRENT_KERNEL_CONFIG)" | $(TR) A-Z a-z)
49 endif
50
51 ifndef CURRENT_MACHINE_CONFIG_LC
52 export CURRENT_MACHINE_CONFIG_LC := $(shell printf "%s" "$(CURRENT_MACHINE_CONFIG)" | $(TR) A-Z a-z)
53 endif
54
55 #
56 # Component List
57 #
58 COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security san
59 COMPONENT = $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))))
60 COMPONENT_IMPORT_LIST = $(filter-out $(COMPONENT),$(COMPONENT_LIST))
61
62 MACHINE_FLAGS_ARM64_T7000 = -DARM64_BOARD_CONFIG_T7000 -mcpu=apple-h7
63 MACHINE_FLAGS_ARM64_T7001 = -DARM64_BOARD_CONFIG_T7001 -mcpu=apple-h7
64 MACHINE_FLAGS_ARM64_S8000 = -DARM64_BOARD_CONFIG_S8000 -mcpu=apple-h8
65 MACHINE_FLAGS_ARM64_S8001 = -DARM64_BOARD_CONFIG_S8001 -mcpu=apple-h8
66 MACHINE_FLAGS_ARM_T8002 = -DARM_BOARD_CONFIG_T8002
67 MACHINE_FLAGS_ARM_T8004 = -DARM_BOARD_CONFIG_T8004
68 MACHINE_FLAGS_ARM64_T8010 = -DARM64_BOARD_CONFIG_T8010 -mcpu=hurricane
69 MACHINE_FLAGS_ARM64_T8011 = -DARM64_BOARD_CONFIG_T8011 -mcpu=hurricane
70 MACHINE_FLAGS_ARM64_BCM2837 = -DARM64_BOARD_CONFIG_BCM2837
71 MACHINE_FLAGS_ARM64_T8020 = -DARM64_BOARD_CONFIG_T8020 -mcpu=vortex
72 MACHINE_FLAGS_ARM64_T8101 = -DARM64_BOARD_CONFIG_T8101 -mcpu=apple-a14
73 MACHINE_FLAGS_ARM64_T8103 = -DARM64_BOARD_CONFIG_T8103 -mcpu=apple-a14
74
75
76 #
77 # Deployment target flag
78 #
79 ifeq ($(PLATFORM),MacOSX)
80 DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION) -DXNU_TARGET_OS_OSX
81 DEPLOYMENT_LINKER_FLAGS = -Wl,-macosx_version_min,$(SDKVERSION)
82 else 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)
85 else ifeq ($(PLATFORM),WatchOS)
86 DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_WATCH
87 DEPLOYMENT_LINKER_FLAGS =
88 else ifeq ($(PLATFORM),tvOS)
89 DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_TV
90 DEPLOYMENT_LINKER_FLAGS =
91 else ifeq ($(PLATFORM),AppleTVOS)
92 DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_TV
93 else ifeq ($(PLATFORM),BridgeOS)
94 DEPLOYMENT_TARGET_FLAGS = -mbridgeos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_BRIDGE
95 DEPLOYMENT_LINKER_FLAGS =
96 else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
97 DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION) -DXNU_TARGET_OS_IOS
98 DEPLOYMENT_LINKER_FLAGS = -Wl,-ios_version_min,$(SDKVERSION)
99 else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
100 DEPLOYMENT_TARGET_FLAGS =
101 DEPLOYMENT_LINKER_FLAGS =
102 else
103 DEPLOYMENT_TARGET_FLAGS =
104 DEPLOYMENT_LINKER_FLAGS =
105 endif
106
107 DEPLOYMENT_TARGET_DEFINES = -DPLATFORM_$(PLATFORM)
108
109
110 ifneq ($(RC_ENABLE_PRODUCT_INFO_FILTER),)
111 SEED_DEFINES += -DRC_ENABLE_XNU_PRODUCT_INFO_FILTER
112 else
113 SEED_DEFINES += -URC_ENABLE_XNU_PRODUCT_INFO_FILTER
114 endif
115
116 #
117 # Standard defines list
118 #
119 DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \
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.
126 CCACHE ?=
127
128 #
129 # Compiler command
130 #
131 KCC = $(CCACHE) $(CC)
132 KC++ = $(CCACHE) $(CXX)
133
134 GENASSYM_KCC = $(CCACHE) $(CC)
135
136 #
137 # Compiler warning flags
138 #
139
140 USE_WERROR := 1
141 ifneq ($(BUILD_WERROR),)
142 USE_WERROR := $(BUILD_WERROR)
143 endif
144
145 ifeq ($(USE_WERROR),1)
146 WERROR := -Werror
147 endif
148
149 # Shared C/C++ warning flags
150 # NOTE: order matters here. -Wno-xxx goes before opt-in of ones we want
151 WARNFLAGS_STD := \
152 -Weverything \
153 -Wno-pedantic \
154 $(WERROR) \
155 -Wno-bad-function-cast \
156 -Wno-c++-compat \
157 -Wno-c++98-compat \
158 -Wno-conditional-uninitialized \
159 -Wno-covered-switch-default \
160 -Wno-disabled-macro-expansion \
161 -Wno-documentation-unknown-command \
162 -Wno-extra-semi-stmt \
163 -Wno-format-non-iso \
164 -Wno-format-nonliteral \
165 -Wno-language-extension-token \
166 -Wno-missing-variable-declarations \
167 -Wno-packed \
168 -Wno-padded \
169 -Wno-partial-availability \
170 -Wno-reserved-id-macro \
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
179
180 # When a new clang has new warnings disable them here until the kernel is fixed.
181 WARNFLAGS_STD := $(WARNFLAGS_STD) \
182 -Wno-unknown-warning-option \
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:
191 WARNFLAGS_STD := $(WARNFLAGS_STD) \
192 -Wno-sign-compare \
193 -Wno-sign-conversion
194
195 CWARNFLAGS_STD = \
196 $(WARNFLAGS_STD)
197
198
199
200 # Can be overridden in Makefile.template or Makefile.$arch
201 export CWARNFLAGS ?= $(CWARNFLAGS_STD)
202
203 define add_perfile_cflags
204 $(1)_CWARNFLAGS_ADD += $2
205 endef
206
207 define rm_perfile_cflags
208 $(1)_CFLAGS_RM += $2
209 endef
210
211 CXXWARNFLAGS_STD = \
212 $(WARNFLAGS_STD) \
213 -Wno-c++98-compat-pedantic \
214 -Wno-exit-time-destructors \
215 -Wno-global-constructors \
216 -Wno-old-style-cast
217
218 # Can be overridden in Makefile.template or Makefile.$arch
219 export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
220
221 define add_perfile_cxxflags
222 $(1)_CXXWARNFLAGS_ADD += $2
223 endef
224
225 #
226 # Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
227
228 ARCH_FLAGS_X86_64 = -arch x86_64
229 ARCH_FLAGS_X86_64H = -arch x86_64h
230
231 ifeq ($(RC_ProjectName),xnu_libraries)
232 WILL_BUILD_STATIC_KC := 1
233 BUILD_STATIC_LINK := 1
234 BUILD_XNU_LIBRARY := 1
235 RC_NONARCH_CFLAGS += -D__BUILDING_XNU_LIBRARY__=1
236 endif
237
238 ifneq ($(filter ARM ARM64,$(CURRENT_ARCH_CONFIG)),)
239
240 ifneq ($(findstring _Sim,$(RC_ProjectName)),)
241 ARCH_FLAGS_ARM64 = -arch arm64e
242 else ifneq ($(findstring _host,$(RC_ProjectName)),)
243 ARCH_FLAGS_ARM64 = -arch arm64e
244 else
245
246 ifndef ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG
247
248 ifneq ($(EMBEDDED_DEVICE_MAP),)
249 export 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 )
250 else
251 # Without embdedded device map, use a default arch string
252 export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell echo $(CURRENT_ARCH_CONFIG) | tr A-Z a-z)
253 ifneq ($(filter ARM64,$(CURRENT_ARCH_CONFIG)),)
254 export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := arm64e
255 endif
256 endif
257 endif
258
259 #
260 # This can have false negatives, and is used to avoid calling CTF when we'll build a static KC
261 #
262 ifndef WILL_BUILD_STATIC_KC
263 ifneq ($(EMBEDDED_DEVICE_MAP),)
264 export 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,%")')
267 else
268 export WILL_BUILD_STATIC_KC := 0
269 endif
270 endif
271
272 BUILD_STATIC_LINK := 1
273
274 ARCH_FLAGS_ARM = -arch $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG)
275 ARCH_FLAGS_ARM64 = -arch $(ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG)
276
277 endif
278
279 else
280 # non arm machine config string
281 ifndef ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG
282 export ARCH_STRING_FOR_CURRENT_MACHINE_CONFIG := $(shell echo $(CURRENT_ARCH_CONFIG) | tr A-Z a-z)
283 endif
284
285 endif
286
287 #
288 # Default CFLAGS
289 #
290 ifdef RC_NONARCH_CFLAGS
291 OTHER_CFLAGS = $(RC_NONARCH_CFLAGS)
292 endif
293
294 #
295 # Debug info
296 #
297 DSYMINFODIR = Contents
298 DSYMKGMACROSDIR = Contents/Resources
299 DSYMLLDBMACROSDIR = Contents/Resources/Python
300 DSYMDWARFDIR = Contents/Resources/DWARF
301
302 DEBUG_CFLAGS := -g
303 BUILD_DSYM := 1
304
305 #
306 # We must not use -fno-keep-inline-functions, or it will remove the dtrace
307 # probes from the kernel.
308 #
309 CFLAGS_GEN = $(DEBUG_CFLAGS) -nostdinc \
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)
319
320 CFLAGS_RELEASE =
321 CFLAGS_DEVELOPMENT =
322 CFLAGS_DEBUG =
323 CFLAGS_KASAN = $(CFLAGS_DEVELOPMENT)
324 CFLAGS_PROFILE = -pg
325
326 CFLAGS_X86_64 = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
327 -DPAGE_SIZE_FIXED -mkernel -msoft-float
328
329 CFLAGS_X86_64H = $(CFLAGS_X86_64)
330
331 CFLAGS_ARM = -Darm -DARM -D__ARM__ -DPAGE_SIZE_FIXED \
332 -momit-leaf-frame-pointer -fno-strict-aliasing -D__API__=v4
333
334 LARGE_MEMORY_DEFINE=-UARM_LARGE_MEMORY
335 ARM64_PLKSEG_ADDR =0xfffffff004004000
336 ARM64_LINK_ADDR =0xfffffff007004000
337
338 # Use ARM_LARGE_MEMORY config for all MacOSX targets.
339 ifneq ($(filter $(PLATFORM),MacOSX),)
340 LARGE_MEMORY_DEFINE=-DARM_LARGE_MEMORY=1
341 ARM64_PLKSEG_ADDR =0xfffffe0004004000
342 ARM64_LINK_ADDR =0xfffffe0007004000
343 endif
344
345
346 CFLAGS_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
348
349 CFLAGS_RELEASEX86_64 = -O2
350 CFLAGS_DEVELOPMENTX86_64 = -O2
351 CFLAGS_KASANX86_64 = $(CFLAGS_DEVELOPMENTX86_64)
352 # No space optimization for the DEBUG kernel for the benefit of gdb:
353 CFLAGS_DEBUGX86_64 = -O0
354 CFLAGS_PROFILEX86_64 = -O2
355
356 CFLAGS_RELEASEX86_64H = -O2
357 CFLAGS_DEVELOPMENTX86_64H = -O2
358 CFLAGS_KASANX86_64H = $(CFLAGS_DEVELOPMENTX86_64H)
359 # No space optimization for the DEBUG kernel for the benefit of gdb:
360 CFLAGS_DEBUGX86_64H = -O0
361 CFLAGS_PROFILEX86_64H = -O2
362
363 CFLAGS_RELEASEARM = -O2
364 CFLAGS_DEVELOPMENTARM = -O2
365 CFLAGS_DEBUGARM = -O0
366 CFLAGS_PROFILEARM = -O2
367
368 CFLAGS_RELEASEARM64 = -O2
369 CFLAGS_DEVELOPMENTARM64 = -O2
370 CFLAGS_KASANARM64 = $(CFLAGS_DEVELOPMENTARM64)
371 CFLAGS_DEBUGARM64 = -O0
372 CFLAGS_PROFILEARM64 = -O2
373
374 #
375 # Sanitizers Support (KASan, UBSan)
376 #
377
378
379 SAN=0
380
381 # KASan support
382 #
383
384 ifeq ($(CURRENT_KERNEL_CONFIG),KASAN)
385 # KASan kernel config implicitly enables the KASan instrumentation.
386 # Instrumentation for other sanitizers is enabled explicitly at build time.
387 KASAN = 1
388 endif
389
390 ifeq ($(KASAN),1)
391 SAN=1
392 BUILD_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.
396 KASAN_SCALE=3
397
398 KASAN_OFFSET_ARM64=0xe000000000000000
399 #
400 # To calculate the kasan offset, subtract the lowest KVA to sanitize, shifted right by 3 bits,
401 # from the base address of the kasan shadow area, (e.g. solve the following equation:
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
407 # ).
408 KASAN_OFFSET_X86_64=0xdffff80000000000
409 KASAN_OFFSET_X86_64H=$(KASAN_OFFSET_X86_64)
410 KASAN_OFFSET=$($(addsuffix $(CURRENT_ARCH_CONFIG),KASAN_OFFSET_))
411 KASAN_BLACKLIST=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
412 CFLAGS_GEN += -DKASAN=1 -DKASAN_OFFSET=$(KASAN_OFFSET) -DKASAN_SCALE=$(KASAN_SCALE) -fsanitize=address \
413 -mllvm -asan-globals-live-support \
414 -mllvm -asan-mapping-offset=$(KASAN_OFFSET) \
415 -fsanitize-blacklist=$(KASAN_BLACKLIST)
416
417 endif
418
419 ifeq ($(UBSAN),1)
420 SAN=1
421 UBSAN_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
423 UBSAN_CHECKS_FATAL = # fatal (calls runtime, must not return)
424 UBSAN_CHECKS_TRAP = vla-bound builtin # emit a trap instruction (no runtime support)
425 UBSAN_DISABLED =
426
427 UBSAN_DISABLED += vptr function # requires unsupported C++ runtime
428 ifeq ($(KASAN),1)
429 # UBSan alignment + KASan code size is too large
430 # UBSan unreachable doesn't play nice with ASan (40723397)
431 UBSAN_DISABLED += alignment unreachable
432 endif
433
434 CFLAGS_GEN += -DUBSAN=1
435 CFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS) $(UBSAN_CHECKS_FATAL) $(UBSAN_CHECKS_TRAP),-fsanitize=$(x))
436 CFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS_FATAL),-fno-sanitize-recover=$(x))
437 CFLAGS_GEN += $(foreach x,$(UBSAN_CHECKS_TRAP),-fsanitize-trap=$(x))
438 CFLAGS_GEN += $(foreach x,$(UBSAN_DISABLED),-fno-sanitize=$(x))
439 endif
440
441 ifeq ($(KSANCOV),1)
442 # Enable SanitizerCoverage instrumentation in xnu
443 SAN = 1
444 KSANCOV_CFLAGS := -fsanitize-coverage=trace-pc-guard
445 CFLAGS_GEN += $(KSANCOV_CFLAGS) -DKSANCOV=1
446 endif
447
448 ifeq ($(SAN),1)
449 CFLAGS_GEN += -fsanitize-blacklist=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
450 endif
451
452
453 CFLAGS = $(CFLAGS_GEN) \
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_))) \
459 $(DEPLOYMENT_TARGET_FLAGS) \
460 $(DEPLOYMENT_TARGET_DEFINES) \
461 $(DEFINES)
462
463 #
464 # Default C++ flags
465 #
466
467 OTHER_CXXFLAGS =
468
469 CXXFLAGS_GEN = -std=gnu++1z -fsized-deallocation -fapple-kext $(OTHER_CXXFLAGS)
470
471 CXXFLAGS = $(CXXFLAGS_GEN) \
472 $($(addsuffix $(CURRENT_ARCH_CONFIG),CXXFLAGS_)) \
473 $($(addsuffix $(CURRENT_KERNEL_CONFIG),CXXFLAGS_))
474
475 #
476 # Assembler command
477 #
478 AS = $(CCACHE) $(CC)
479 S_KCC = $(CC)
480
481 #
482 # Default SFLAGS
483 #
484 SFLAGS_GEN = -D__ASSEMBLER__ -DASSEMBLER $(OTHER_CFLAGS)
485
486 SFLAGS_RELEASE =
487 SFLAGS_DEVELOPMENT =
488 SFLAGS_KASAN = $(SFLAGS_DEVELOPMENT) -DKASAN=1
489 SFLAGS_DEBUG =
490 SFLAGS_PROFILE =
491
492 SFLAGS_X86_64 = $(CFLAGS_X86_64)
493 SFLAGS_X86_64H = $(CFLAGS_X86_64H)
494 SFLAGS_ARM = $(CFLAGS_ARM)
495 SFLAGS_ARM64 = $(CFLAGS_ARM64)
496
497 SFLAGS = $(SFLAGS_GEN) \
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_)) \
502 $(DEPLOYMENT_TARGET_FLAGS) \
503 $(DEPLOYMENT_TARGET_DEFINES) \
504 $(DEFINES)
505
506 #
507 # Linker command
508 #
509 LD = $(KC++) -nostdlib
510
511 #
512 # Default LDFLAGS
513 #
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 #
518 LDFLAGS_KERNEL_GEN = \
519 -nostdlib \
520 -fapple-kext \
521 -Wl,-e,__start \
522 -Wl,-sectalign,__TEXT,__text,0x1000 \
523 -Wl,-sectalign,__DATA,__percpu,0x80 \
524 -Wl,-sectalign,__DATA,__common,0x1000 \
525 -Wl,-sectalign,__DATA,__bss,0x1000 \
526 -Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
527 -Wl,-segprot,__PRELINK_TEXT,r-x,r-x \
528 -Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
529 -Wl,-new_linker \
530 -Wl,-pagezero_size,0x0 \
531 -Wl,-version_load_command \
532 -Wl,-function_starts \
533 -Wl,-headerpad,152
534
535 # LDFLAGS_KERNEL_SDK = -L$(SDKROOT)/usr/local/lib/kernel -lfirehose_kernel
536 LDFLAGS_KERNEL_SDK = -L$(SDKROOT)/usr/local/lib/kernel
537
538 LDFLAGS_KERNEL_RELEASE =
539 LDFLAGS_KERNEL_DEVELOPMENT =
540 LDFLAGS_KERNEL_KASAN = $(LDFLAGS_KERNEL_DEVELOPMENT)
541 LDFLAGS_KERNEL_DEBUG =
542 LDFLAGS_KERNEL_PROFILE =
543
544 # KASLR static slide config:
545 ifndef SLIDE
546 SLIDE=0x00
547 endif
548 KERNEL_MIN_ADDRESS = 0xffffff8000000000
549 KERNEL_BASE_OFFSET = 0x100000
550 KERNEL_STATIC_SLIDE = $(shell printf "0x%016x" \
551 $$[ $(SLIDE) << 21 ])
552 KERNEL_STATIC_BASE = $(shell printf "0x%016x" \
553 $$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ])
554 KERNEL_HIB_SECTION_BASE = $(shell printf "0x%016x" \
555 $$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ])
556 KERNEL_TEXT_BASE = $(shell printf "0x%016x" \
557 $$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ])
558
559 LDFLAGS_KERNEL_RELEASEX86_64 = \
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 \
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 \
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 \
575 -Wl,-sectalign,__HIB,__cstring,0x1000 \
576 -Wl,-rename_section,__DATA,__const,__DATA_CONST,__const \
577 -Wl,-segprot,__DATA_CONST,r--,r-- \
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 \
582 -Wl,-no_zero_fill_sections \
583 $(LDFLAGS_NOSTRIP_FLAG)
584
585 ifeq ($(SAN),1)
586 LDFLAGS_KERNEL_RELEASEX86_64 += \
587 -Wl,-sectalign,__HIB,__cstring,0x1000
588 endif
589
590 ifeq ($(KSANCOV),1)
591 LDFLAGS_KERNEL_RELEASEX86_64 += \
592 -Wl,-sectalign,__HIB,__sancov_guards,0x1000 \
593 -Wl,-sectalign,__HIB,__sancov_pcs,0x1000
594 endif
595
596 # Define KERNEL_BASE_OFFSET so known at compile time:
597 CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
598 CFLAGS_X86_64H += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
599
600 LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
601 LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
602 LDFLAGS_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
608 LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
609
610 LDFLAGS_KERNEL_RELEASEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64)
611 LDFLAGS_KERNEL_DEBUGX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
612 LDFLAGS_KERNEL_DEVELOPMENTX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
613 LDFLAGS_KERNEL_KASANX86_64H = $(LDFLAGS_KERNEL_KASANX86_64)
614 LDFLAGS_KERNEL_PROFILEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
615
616 # We preload ___udivmoddi4 in order to work around an issue with building
617 # LTO on armv7.
618 LDFLAGS_KERNEL_GENARM = \
619 -Wl,-pie \
620 -Wl,-static \
621 -Wl,-image_base,0x80001000 \
622 -Wl,-sectalign,__DATA,__const,0x1000 \
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
628
629 LDFLAGS_KERNEL_RELEASEARM = \
630 $(LDFLAGS_KERNEL_GENARM) \
631 $(LDFLAGS_KERNEL_STRIP_LTO)
632
633 LDFLAGS_KERNEL_ONLY_CONFIG_RELEASEARM = \
634 -Wl,-exported_symbols_list,$(TARGET)/all-kpi.exp
635
636 LDFLAGS_KERNEL_DEVELOPMENTARM = \
637 $(LDFLAGS_KERNEL_GENARM) \
638 $(LDFLAGS_NOSTRIP_FLAG)
639
640 LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM =
641
642 LDFLAGS_KERNEL_DEBUGARM = $(LDFLAGS_KERNEL_DEVELOPMENTARM)
643 LDFLAGS_KERNEL_ONLY_CONFIG_DEBUGARM = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM)
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).
673 LDFLAGS_KERNEL_GENARM64 = \
674 -Wl,-pie \
675 -Wl,-static \
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 \
688 -Wl,-sectalign,__DATA,__const,0x4000 \
689 -Wl,-sectalign,__DATA,__data,0x4000 \
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 \
692 -Wl,-rename_section,__DATA,__auth_ptr,__DATA_CONST,__auth_ptr \
693 -Wl,-rename_section,__DATA,__auth_got,__DATA_CONST,__auth_got \
694 -Wl,-rename_section,__DATA,__const,__DATA_CONST,__const \
695 -Wl,-segprot,__DATA_CONST,r--,r-- \
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 \
700 -Wl,-rename_section,__TEXT,__text,__TEXT_EXEC,__text \
701 -Wl,-rename_section,__TEXT,__stubs,__TEXT_EXEC,__stubs \
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
708 LDFLAGS_KERNEL_SEGARM64 = \
709 -Wl,-rename_section,__PPLDATA,__const,__PPLDATA_CONST,__const \
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 \
712
713 LDFLAGS_KERNEL_RELEASEARM64 = \
714 $(LDFLAGS_KERNEL_GENARM64) \
715 $(LDFLAGS_KERNEL_SEGARM64) \
716 $(LDFLAGS_KERNEL_STRIP_LTO)
717
718 LDFLAGS_KERNEL_ONLY_CONFIG_RELEASEARM64 = \
719 -Wl,-exported_symbols_list,$(TARGET)/all-kpi.exp
720
721 LDFLAGS_KERNEL_DEVELOPMENTARM64 = \
722 $(LDFLAGS_KERNEL_GENARM64) \
723 $(LDFLAGS_KERNEL_SEGARM64) \
724 $(LDFLAGS_NOSTRIP_FLAG)
725
726 LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64 =
727
728 LDFLAGS_KERNEL_KASANARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
729 LDFLAGS_KERNEL_DEBUGARM64 = $(LDFLAGS_KERNEL_DEVELOPMENTARM64)
730
731 LDFLAGS_KERNEL_ONLY_CONFIG_KASANARM64 = $(LDFLAGS_KERNEL_ONLY_CONFIG_DEVELOPMENTARM64)
732 LDFLAGS_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 #
738 LDFLAGS_KERNEL_ONLY_SUBARCH_arm64e = \
739 -Wl,-add_split_seg_info \
740 -Wl,-kernel
741
742 LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64 = \
743 -Wl,-add_split_seg_info \
744 -Wl,-kernel
745 LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64h = $(LDFLAGS_KERNEL_ONLY_SUBARCH_x86_64)
746
747 LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
748 $(LDFLAGS_KERNEL_SDK) \
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_))) \
753 $(DEPLOYMENT_TARGET_FLAGS)
754
755 LDFLAGS_KERNEL_ONLY += \
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--
760
761 #
762 # Default runtime libraries to be linked with the kernel
763 #
764 LD_KERNEL_LIBS = -lcc_kext
765 LD_KERNEL_ARCHIVES = $(LDFLAGS_KERNEL_SDK) -lfirehose_kernel
766 # Link opensource binary library
767 ifneq ($(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
769 endif
770
771 #
772 # DTrace support
773 #
774 ifndef DO_CTFMERGE
775 DO_CTFMERGE := 1
776 ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
777 ifneq ($(PLATFORM),MacOSX)
778 DO_CTFMERGE := 0
779 endif
780 endif
781 ifneq ($(CURRENT_KERNEL_CONFIG),KASAN)
782 ifneq ($(PLATFORM),MacOSX)
783 ifeq ($(WILL_BUILD_STATIC_KC),1)
784 DO_CTFMERGE := 0
785 endif
786 endif
787 endif
788 endif # DO_CTFMERGE
789
790
791 #
792 # Default INCFLAGS
793 #
794 INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
795 INCFLAGS_EXTERN = -I$(SRCROOT)/EXTERNAL_HEADERS
796 INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
797 INCFLAGS_LOCAL = -I.
798 INCFLAGS_SDK = -I$(SDKROOT)/usr/local/include/kernel
799
800 INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) $(INCFLAGS_SDK)
801
802 #
803 # Default MIGFLAGS
804 #
805 MIGFLAGS = $(DEFINES) $(INCFLAGS) -novouchers $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
806 $(DEPLOYMENT_TARGET_FLAGS)
807
808 # Support for LLVM Profile Guided Optimization (PGO)
809
810 ifeq ($(BUILD_PROFILE),1)
811 CFLAGS_GEN += -fprofile-instr-generate -DPROFILE
812 CXXFLAGS_GEN += -fprofile-instr-generate -DPROFILE
813 endif
814
815 ifdef USE_PROFILE
816 CFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
817 CXXFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
818 LDFLAGS_KERNEL_GEN += -fprofile-instr-use=$(USE_PROFILE)
819
820 CFLAGS_GEN += -Wno-error=profile-instr-out-of-date
821 endif
822
823 #
824 # Support for LLVM Link Time Optimization (LTO)
825 #
826 # LTO can be explicitly enabled or disabled with BUILD_LTO=1|0
827 # and defaults to enabled except for DEBUG kernels
828 #
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.
837
838 LTO_ENABLED_RELEASE = 1
839 LTO_ENABLED_DEVELOPMENT = 1
840 LTO_ENABLED_DEBUG = 0
841 LTO_ENABLED_KASAN = 0
842
843 ifneq ($(BUILD_LTO),)
844 USE_LTO = $(BUILD_LTO)
845 else
846 USE_LTO = $(LTO_ENABLED_$(CURRENT_KERNEL_CONFIG))
847 endif
848
849 ifeq ($(USE_LTO),1)
850 CFLAGS_GEN += -flto
851 CXXFLAGS_GEN += -flto
852 LDFLAGS_KERNEL_LTO = -Wl,-mllvm,-inline-threshold=100
853 LDFLAGS_KERNEL_GEN += $(LDFLAGS_KERNEL_LTO) -Wl,-object_path_lto,$(TARGET)/lto.o
854 LDFLAGS_NOSTRIP_FLAG = -rdynamic
855 LDFLAGS_KERNEL_STRIP_LTO = -Wl,-dead_strip,-no_dead_strip_inits_and_terms
856
857 CFLAGS_NOLTO_FLAG = -fno-lto
858 else
859 LDFLAGS_KERNEL_LTO =
860 LDFLAGS_NOSTRIP_FLAG =
861 LDFLAGS_KERNEL_STRIP_LTO =
862 CFLAGS_NOLTO_FLAG =
863 endif
864
865 ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
866 BUILD_DSYM := 0
867 DO_CTFMERGE := 0
868 KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
869 KC++ = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CXX)
870 S_KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
871 STRIP = true
872 endif
873
874 #
875 # Default VPATH
876 #
877 export VPATH = .:$(SOURCE)
878
879
880
881 #
882 # Macros that control installation of kernel and its header files
883 #
884 # install flags for header files
885 #
886 INSTALL_FLAGS = -c -S -m 0444
887 DATA_INSTALL_FLAGS = -c -S -m 0644
888 DATA_INSTALL_FLAGS_RO = -c -S -m 0444
889 EXEC_INSTALL_FLAGS = -c -S -m 0755
890
891 #
892 # Header file destinations
893 #
894
895 ifeq ($(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
900 endif
901
902 FRAMEDIR = $(SDKHEADERSROOT)/System/Library/Frameworks
903
904 SINCVERS = B
905 SINCFRAME = $(FRAMEDIR)/System.framework
906 SINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers
907 SPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders
908 SRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources
909
910 ifndef INCDIR
911 INCDIR = $(SDKHEADERSROOT)/usr/include
912 endif
913 ifndef DRIVERKITINCDIR
914 DRIVERKITINCDIR = $(DRIVERKITSDKHEADERSROOT)/usr/include
915 endif
916 ifndef LCLDIR
917 ifeq ($(LIBKERN_USE_USR_LOCAL_INCLUDE),)
918 LCLDIR = $(SPINCDIR)
919 else
920 LCLDIR = $(SDKHEADERSROOT)/usr/local/include
921 endif
922 endif
923 ifndef DRIVERKITLCLDIR
924 DRIVERKITLCLDIR = $(DRIVERKITSDKHEADERSROOT)/usr/local/include
925 endif
926
927 KINCVERS = A
928 KINCFRAME = $(FRAMEDIR)/Kernel.framework
929 KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
930 KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
931 KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
932
933 DKIT_INCVERS = A
934 DKIT_INCFRAME = DriverKit.framework
935 DKIT_INCDIR = $(DKIT_INCFRAME)/Versions/$(DKIT_INCVERS)/Headers
936 DKIT_PINCDIR = $(DKIT_INCFRAME)/Versions/$(DKIT_INCVERS)/PrivateHeaders
937 # DriverKit SDK frameworks use shallow bundle structure
938 DRIVERKIT_DKIT_INCDIR = $(DKIT_INCFRAME)/Headers
939 DRIVERKIT_DKIT_PINCDIR = $(DKIT_INCFRAME)/PrivateHeaders
940
941 XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
942
943
944 PLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DPLATFORM_$(x) $(foreach token,$(PLATFORM_UNIFDEF_BLACKLIST_TOKENS_$(x)),-U$(token)),-UPLATFORM_$(x)))
945
946
947 SPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -UDRIVERKIT -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
948 SINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -UDRIVERKIT -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
949 DKPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -DDRIVERKIT -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
950 DKINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -DDRIVERKIT -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
951 KPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DKERNEL -DPRIVATE -UDRIVERKIT -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
952 KINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -DKERNEL -UPRIVATE -UDRIVERKIT -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
953 DATA_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
954
955 #
956 # Compononent Header file destinations
957 #
958 EXPDIR = EXPORT_HDRS/$(COMPONENT)
959
960 #
961 # Strip Flags
962 #
963 STRIP_FLAGS_RELEASE = -S -x
964 STRIP_FLAGS_DEVELOPMENT = -S
965 STRIP_FLAGS_KASAN = $(STRIP_FLAGS_DEVELOPMENT)
966 STRIP_FLAGS_DEBUG = -S
967 STRIP_FLAGS_PROFILE = -S -x
968
969 STRIP_FLAGS = $($(addsuffix $(CURRENT_KERNEL_CONFIG),STRIP_FLAGS_))
970
971 #
972 # dsymutil flags
973 #
974 DSYMUTIL_FLAGS_GEN = --minimize
975
976 DSYMUTIL_FLAGS_X86_64 = --arch=x86_64
977 DSYMUTIL_FLAGS_X86_64H = --arch=x86_64h
978 DSYMUTIL_FLAGS_ARM = --arch=arm
979 DSYMUTIL_FLAGS_ARM64 =
980
981 DSYMUTIL_FLAGS = $(DSYMUTIL_FLAGS_GEN) \
982 $($(addsuffix $(CURRENT_ARCH_CONFIG),DSYMUTIL_FLAGS_))
983
984 #
985 # Man Page destination
986 #
987 MANDIR = /usr/share/man
988
989 #
990 # DEBUG alias location
991 #
992 DEVELOPER_EXTRAS_DIR = /AppleInternal/CoreOS/xnu_$(CURRENT_KERNEL_CONFIG_LC)
993
994 #
995 # mach_kernel install location
996 #
997 INSTALL_KERNEL_DIR = /
998
999 #
1000 # new OS X install location
1001 #
1002 SYSTEM_LIBRARY_KERNELS_DIR = /System/Library/Kernels
1003
1004 #
1005 # File names in DSTROOT
1006 #
1007
1008 ifeq ($(PLATFORM),MacOSX)
1009 KERNEL_FILE_NAME_PREFIX = kernel
1010 else
1011 KERNEL_FILE_NAME_PREFIX = mach
1012 endif
1013
1014 ifeq ($(CURRENT_MACHINE_CONFIG),NONE)
1015 ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
1016 KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX)
1017 KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
1018 else
1019 KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC)
1020 KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
1021 endif
1022 else
1023 KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_MACHINE_CONFIG_LC)
1024 KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX)_$(CURRENT_KERNEL_CONFIG_LC).py
1025 endif
1026
1027 CURRENT_ALIAS_MACHINE_CONFIG = $(word 4,$(subst ^, ,$(CURRENT_BUILD_CONFIG)))
1028 CURRENT_ALIAS_MACHINE_CONFIG_LC = $(shell printf "%s" "$(CURRENT_ALIAS_MACHINE_CONFIG)" | $(TR) A-Z a-z)
1029 ifneq ($(CURRENT_ALIAS_MACHINE_CONFIG),)
1030 ALIAS_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_ALIAS_MACHINE_CONFIG_LC)
1031 endif
1032
1033 #
1034 # System.kext pseudo-kext install location
1035 #
1036 INSTALL_EXTENSIONS_DIR = /System/Library/Extensions
1037
1038 #
1039 # KDK location
1040 #
1041 INSTALL_KERNEL_SYM_DIR = /System/Library/Extensions/KDK
1042
1043 #
1044 # Misc. Etc.
1045 #
1046 INSTALL_SHARE_MISC_DIR = /usr/share/misc
1047 INSTALL_DTRACE_SCRIPTS_DIR = /usr/lib/dtrace
1048 INSTALL_DTRACE_LIBEXEC_DIR = /usr/libexec/dtrace
1049
1050 #
1051 # Overrides for XBS build aliases
1052 #
1053 ifneq ($(filter $(RC_ProjectName),xnu_debug),)
1054 INSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
1055 INSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
1056 INSTALL_KERNEL_SYM_TO_KDK = 1
1057 INSTALL_XNU_DEBUG_FILES = 1
1058 else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
1059 INSTALL_KERNEL_SYM_TO_KDK = 1
1060 USE_BINARY_PLIST = 1
1061 else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
1062 USE_BINARY_PLIST = 1
1063 else ifeq ($(PLATFORM),MacOSX)
1064 INSTALL_KERNEL_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
1065 INSTALL_KERNEL_SYM_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
1066 INSTALL_KERNEL_SYM_TO_KDK = $(if $(filter YES,$(DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT)),1,0)
1067 endif
1068
1069 ifneq ($(filter $(RC_ProjectName),xnu_kasan),)
1070 INSTALL_KASAN_ONLY = 1
1071 endif
1072
1073 # vim: set ft=make: