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