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