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