forked from apple/darwin-xnu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeInc.def
716 lines (598 loc) · 19.3 KB
/
MakeInc.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
# -*- mode: makefile;-*-
#
# Copyright (C) 1999-2017 Apple Inc. All rights reserved.
#
# MakeInc.def contains global definitions for building,
# linking, and installing files.
#
#
# Architecture Configuration options
#
SUPPORTED_ARCH_CONFIGS := X86_64 X86_64H
#
# Kernel Configuration options
#
SUPPORTED_KERNEL_CONFIGS = RELEASE DEVELOPMENT DEBUG PROFILE KASAN
#
# Machine Configuration options
#
SUPPORTED_X86_64_MACHINE_CONFIGS = NONE
SUPPORTED_X86_64H_MACHINE_CONFIGS = NONE
#
# Setup up *_LC variables during recursive invocations
#
ifndef CURRENT_ARCH_CONFIG_LC
export CURRENT_ARCH_CONFIG_LC := $(shell printf "%s" "$(CURRENT_ARCH_CONFIG)" | $(TR) A-Z a-z)
endif
ifndef CURRENT_KERNEL_CONFIG_LC
export CURRENT_KERNEL_CONFIG_LC := $(shell printf "%s" "$(CURRENT_KERNEL_CONFIG)" | $(TR) A-Z a-z)
endif
ifndef CURRENT_MACHINE_CONFIG_LC
export CURRENT_MACHINE_CONFIG_LC := $(shell printf "%s" "$(CURRENT_MACHINE_CONFIG)" | $(TR) A-Z a-z)
endif
#
# Component List
#
COMPONENT_LIST = osfmk bsd libkern iokit pexpert libsa security san
COMPONENT = $(if $(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(word 2,$(subst /, ,$(RELATIVE_SOURCE_PATH))),$(firstword $(subst /, ,$(RELATIVE_SOURCE_PATH))))
COMPONENT_IMPORT_LIST = $(filter-out $(COMPONENT),$(COMPONENT_LIST))
#
# Deployment target flag
#
ifeq ($(PLATFORM),MacOSX)
DEPLOYMENT_TARGET_FLAGS = -mmacosx-version-min=$(SDKVERSION)
else ifeq ($(PLATFORM),WatchOS)
DEPLOYMENT_TARGET_FLAGS = -mwatchos-version-min=$(SDKVERSION)
else ifeq ($(PLATFORM),tvOS)
DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
else ifeq ($(PLATFORM),AppleTVOS)
DEPLOYMENT_TARGET_FLAGS = -mtvos-version-min=$(SDKVERSION)
else ifeq ($(PLATFORM),BridgeOS)
DEPLOYMENT_TARGET_FLAGS = -mbridgeos-version-min=$(SDKVERSION)
else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
DEPLOYMENT_TARGET_FLAGS = -miphoneos-version-min=$(SDKVERSION)
else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
DEPLOYMENT_TARGET_FLAGS =
else
DEPLOYMENT_TARGET_FLAGS =
endif
DEPLOYMENT_TARGET_DEFINES = -DPLATFORM_$(PLATFORM)
#
# Standard defines list
#
DEFINES = -DAPPLE -DKERNEL -DKERNEL_PRIVATE -DXNU_KERNEL_PRIVATE \
-DPRIVATE -D__MACHO__=1 -Dvolatile=__volatile $(CONFIG_DEFINES) \
$(SEED_DEFINES)
#
# Compiler command
#
KCC = $(CC)
KC++ = $(CXX)
GENASSYM_KCC = $(CC)
#
# Compiler warning flags
#
USE_WERROR := 1
ifneq ($(BUILD_WERROR),)
USE_WERROR := $(BUILD_WERROR)
endif
ifeq ($(USE_WERROR),1)
WERROR := -Werror
endif
# Shared C/C++ warning flags
WARNFLAGS_STD := \
-Weverything \
-Wextra \
$(WERROR) \
-Wpointer-arith \
-Wreturn-type \
-Wcast-qual \
-Wwrite-strings \
-Wswitch \
-Wcast-align \
-Wchar-subscripts \
-Wredundant-decls \
-Wextra-tokens \
-Wunreachable-code \
-Wno-assign-enum \
-Wno-bad-function-cast \
-Wno-c++98-compat \
-Wno-c++-compat \
-Wno-conditional-uninitialized \
-Wno-conversion \
-Wnull-conversion \
-Wstring-conversion \
-Wliteral-conversion \
-Wnon-literal-null-conversion \
-Wint-conversion \
-Wenum-conversion \
-Wfloat-conversion \
-Wconstant-conversion \
-Wpointer-bool-conversion \
-Wno-covered-switch-default \
-Wno-disabled-macro-expansion \
-Wno-documentation-unknown-command \
-Wno-format-non-iso \
-Wno-format-nonliteral \
-Wno-reserved-id-macro \
-Wno-language-extension-token \
-Wno-missing-variable-declarations \
-Wno-packed \
-Wno-padded \
-Wno-partial-availability \
-Wno-pedantic \
-Wno-shift-sign-overflow \
-Wno-switch-enum \
-Wno-undef \
-Wno-unused-macros \
-Wno-used-but-marked-unused \
-Wno-variadic-macros \
-Wno-vla \
-Wno-zero-length-array
CWARNFLAGS_STD = \
$(WARNFLAGS_STD) \
-Wstrict-prototypes \
-Wmissing-prototypes \
-Wshadow \
-Winline \
-Wnested-externs
# Can be overridden in Makefile.template or Makefile.$arch
export CWARNFLAGS ?= $(CWARNFLAGS_STD)
define add_perfile_cflags
$(1)_CWARNFLAGS_ADD += $2
endef
CXXWARNFLAGS_STD = \
$(WARNFLAGS_STD) \
-Wno-c++98-compat-pedantic \
-Wno-exit-time-destructors \
-Wno-global-constructors \
-Wno-old-style-cast
# overloaded-virtual warnings are non-fatal (9000888)
CXXWARNFLAGS_STD += -Wno-error=overloaded-virtual
# Can be overridden in Makefile.template or Makefile.$arch
export CXXWARNFLAGS ?= $(CXXWARNFLAGS_STD)
define add_perfile_cxxflags
$(1)_CXXWARNFLAGS_ADD += $2
endef
#
# Default ARCH_FLAGS, for use with compiler/linker/assembler/mig drivers
ARCH_FLAGS_X86_64 = -arch x86_64
ARCH_FLAGS_X86_64H = -arch x86_64h
#
# Default CFLAGS
#
ifdef RC_NONARCH_CFLAGS
OTHER_CFLAGS = $(RC_NONARCH_CLFAGS)
endif
#
# Debug info
#
DSYMINFODIR = Contents
DSYMKGMACROSDIR = Contents/Resources
DSYMLLDBMACROSDIR = Contents/Resources/Python
DSYMDWARFDIR = Contents/Resources/DWARF
DEBUG_CFLAGS := -g
BUILD_DSYM := 1
#
# We must not use -fno-keep-inline-functions, or it will remove the dtrace
# probes from the kernel.
#
CFLAGS_GEN = $(DEBUG_CFLAGS) -nostdinc \
-fno-builtin -fno-common \
-fsigned-bitfields $(OTHER_CFLAGS)
CFLAGS_RELEASE =
CFLAGS_DEVELOPMENT =
CFLAGS_DEBUG =
CFLAGS_KASAN = $(CFLAGS_DEVELOPMENT)
CFLAGS_PROFILE = -pg
CFLAGS_X86_64 = -Dx86_64 -DX86_64 -D__X86_64__ -DLP64 \
-DPAGE_SIZE_FIXED -mkernel -msoft-float
CFLAGS_X86_64H = $(CFLAGS_X86_64)
CFLAGS_RELEASEX86_64 = -O2
CFLAGS_DEVELOPMENTX86_64 = -O2
CFLAGS_KASANX86_64 = $(CFLAGS_DEVELOPMENTX86_64)
# No space optimization for the DEBUG kernel for the benefit of gdb:
CFLAGS_DEBUGX86_64 = -O0
CFLAGS_PROFILEX86_64 = -O2
CFLAGS_RELEASEX86_64H = -O2
CFLAGS_DEVELOPMENTX86_64H = -O2
CFLAGS_KASANX86_64H = $(CFLAGS_DEVELOPMENTX86_64H)
# No space optimization for the DEBUG kernel for the benefit of gdb:
CFLAGS_DEBUGX86_64H = -O0
CFLAGS_PROFILEX86_64H = -O2
CFLAGS_RELEASEARM = -O2
CFLAGS_DEVELOPMENTARM = -O2
CFLAGS_DEBUGARM = -O0
CFLAGS_PROFILEARM = -O2
#
# KASAN support
#
ifeq ($(CURRENT_KERNEL_CONFIG),KASAN)
KASAN = 1
endif
ifeq ($(KASAN),1)
BUILD_LTO = 0
KASAN_SHIFT_X86_64=0xdffffe1000000000
KASAN_SHIFT_X86_64H=$(KASAN_SHIFT_X86_64)
KASAN_SHIFT=$($(addsuffix $(CURRENT_ARCH_CONFIG),KASAN_SHIFT_))
KASAN_BLACKLIST=$(OBJROOT)/san/kasan-blacklist-$(CURRENT_ARCH_CONFIG_LC)
CFLAGS_GEN += -DKASAN=1 -DKASAN_SHIFT=$(KASAN_SHIFT) -fsanitize=address \
-mllvm -asan-globals-live-support \
-mllvm -asan-mapping-offset=$(KASAN_SHIFT) \
-fsanitize-blacklist=$(KASAN_BLACKLIST)
endif
CFLAGS = $(CFLAGS_GEN) \
$($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) \
$($(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),CFLAGS_))) \
$(DEPLOYMENT_TARGET_FLAGS) \
$(DEPLOYMENT_TARGET_DEFINES) \
$(DEFINES)
#
# Default C++ flags
#
OTHER_CXXFLAGS =
CXXFLAGS_GEN = -std=gnu++11 -fapple-kext $(OTHER_CXXFLAGS)
CXXFLAGS = $(CXXFLAGS_GEN) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),CXXFLAGS_)) \
$($(addsuffix $(CURRENT_KERNEL_CONFIG),CXXFLAGS_))
#
# Assembler command
#
AS = $(CC)
S_KCC = $(CC)
#
# Default SFLAGS
#
SFLAGS_GEN = -D__ASSEMBLER__ -DASSEMBLER $(OTHER_CFLAGS)
SFLAGS_RELEASE =
SFLAGS_DEVELOPMENT =
SFLAGS_KASAN = $(SFLAGS_DEVELOPMENT) -DKASAN=1
SFLAGS_DEBUG =
SFLAGS_PROFILE =
SFLAGS_X86_64 = $(CFLAGS_X86_64)
SFLAGS_X86_64H = $(CFLAGS_X86_64H)
SFLAGS = $(SFLAGS_GEN) \
$($(addsuffix $(CURRENT_MACHINE_CONFIG),MACHINE_FLAGS_$(CURRENT_ARCH_CONFIG)_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),SFLAGS_)) \
$($(addsuffix $(CURRENT_KERNEL_CONFIG),SFLAGS_)) \
$(DEPLOYMENT_TARGET_FLAGS) \
$(DEPLOYMENT_TARGET_DEFINES) \
$(DEFINES)
#
# Linker command
#
LD = $(KC++) -nostdlib
#
# Default LDFLAGS
#
# Availability of DWARF allows DTrace CTF (compressed type format) to be constructed.
# ctf_insert creates the CTF section. It needs reserved padding in the
# headers for the load command segment and the CTF section structures.
#
LDFLAGS_KERNEL_GEN = \
-nostdlib \
-fapple-kext \
-Wl,-e,__start \
-Wl,-sectalign,__TEXT,__text,0x1000 \
-Wl,-sectalign,__DATA,__common,0x1000 \
-Wl,-sectalign,__DATA,__bss,0x1000 \
-Wl,-sectcreate,__PRELINK_TEXT,__text,/dev/null \
-Wl,-sectcreate,"__PLK_TEXT_EXEC",__text,/dev/null \
-Wl,-sectcreate,__PRELINK_DATA,__data,/dev/null \
-Wl,-sectcreate,"__PLK_DATA_CONST",__data,/dev/null \
-Wl,-sectcreate,"__PLK_LLVM_COV",__llvm_covmap,/dev/null \
-Wl,-sectcreate,"__PLK_LINKEDIT",__data,/dev/null \
-Wl,-sectcreate,__PRELINK_INFO,__info,/dev/null \
-Wl,-new_linker \
-Wl,-pagezero_size,0x0 \
-Wl,-version_load_command \
-Wl,-function_starts \
-Wl,-headerpad,152
LDFLAGS_KERNEL_SDK = -L$(SDKROOT)/usr/local/lib/kernel -lfirehose_kernel
LDFLAGS_KERNEL_RELEASE =
LDFLAGS_KERNEL_DEVELOPMENT =
LDFLAGS_KERNEL_KASAN = $(LDFLAGS_KERNEL_DEVELOPMENT)
LDFLAGS_KERNEL_DEBUG =
LDFLAGS_KERNEL_PROFILE =
# KASLR static slide config:
ifndef SLIDE
SLIDE=0x00
endif
KERNEL_MIN_ADDRESS = 0xffffff8000000000
KERNEL_BASE_OFFSET = 0x100000
KERNEL_STATIC_SLIDE = $(shell printf "0x%016x" \
$$[ $(SLIDE) << 21 ])
KERNEL_STATIC_BASE = $(shell printf "0x%016x" \
$$[ $(KERNEL_MIN_ADDRESS) + $(KERNEL_BASE_OFFSET) ])
KERNEL_HIB_SECTION_BASE = $(shell printf "0x%016x" \
$$[ $(KERNEL_STATIC_BASE) + $(KERNEL_STATIC_SLIDE) ])
KERNEL_TEXT_BASE = $(shell printf "0x%016x" \
$$[ $(KERNEL_HIB_SECTION_BASE) + 0x100000 ])
LDFLAGS_KERNEL_RELEASEX86_64 = \
-Wl,-pie \
-Wl,-segaddr,__HIB,$(KERNEL_HIB_SECTION_BASE) \
-Wl,-image_base,$(KERNEL_TEXT_BASE) \
-Wl,-seg_page_size,__TEXT,0x200000 \
-Wl,-sectalign,__HIB,__bootPT,0x1000 \
-Wl,-sectalign,__HIB,__desc,0x1000 \
-Wl,-sectalign,__HIB,__data,0x1000 \
-Wl,-sectalign,__HIB,__text,0x1000 \
-Wl,-sectalign,__HIB,__const,0x1000 \
-Wl,-sectalign,__HIB,__bss,0x1000 \
-Wl,-sectalign,__HIB,__common,0x1000 \
-Wl,-sectalign,__HIB,__llvm_prf_cnts,0x1000 \
-Wl,-sectalign,__HIB,__llvm_prf_names,0x1000 \
-Wl,-sectalign,__HIB,__llvm_prf_data,0x1000 \
-Wl,-sectalign,__HIB,__textcoal_nt,0x1000 \
-Wl,-rename_section,__DATA,__const,__CONST,__constdata \
-Wl,-no_zero_fill_sections \
$(LDFLAGS_NOSTRIP_FLAG)
ifeq ($(KASAN),1)
LDFLAGS_KERNEL_RELEASEX86_64 += \
-Wl,-sectalign,__HIB,__cstring,0x1000 \
-Wl,-sectalign,__HIB,__asan_globals,0x1000 \
-Wl,-sectalign,__HIB,__asan_liveness,0x1000 \
-Wl,-sectalign,__HIB,__mod_term_func,0x1000 \
-Wl,-rename_section,__HIB,__mod_init_func,__NULL,__mod_init_func \
-Wl,-rename_section,__HIB,__eh_frame,__NULL,__eh_frame
endif
# Define KERNEL_BASE_OFFSET so known at compile time:
CFLAGS_X86_64 += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
CFLAGS_X86_64H += -DKERNEL_BASE_OFFSET=$(KERNEL_BASE_OFFSET)
LDFLAGS_KERNEL_DEBUGX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
LDFLAGS_KERNEL_DEVELOPMENTX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
LDFLAGS_KERNEL_KASANX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
LDFLAGS_KERNEL_PROFILEX86_64 = $(LDFLAGS_KERNEL_RELEASEX86_64)
LDFLAGS_KERNEL_RELEASEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64)
LDFLAGS_KERNEL_DEBUGX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
LDFLAGS_KERNEL_DEVELOPMENTX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
LDFLAGS_KERNEL_KASANX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
LDFLAGS_KERNEL_PROFILEX86_64H = $(LDFLAGS_KERNEL_RELEASEX86_64H)
LDFLAGS_KERNEL = $(LDFLAGS_KERNEL_GEN) \
$(LDFLAGS_KERNEL_SDK) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),LDFLAGS_KERNEL_)) \
$($(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_)) \
$($(addsuffix $(CURRENT_ARCH_CONFIG), $(addsuffix $(CURRENT_KERNEL_CONFIG),LDFLAGS_KERNEL_))) \
$(DEPLOYMENT_TARGET_FLAGS)
#
# Default runtime libraries to be linked with the kernel
#
LD_KERNEL_LIBS = -lcc_kext
#
# DTrace support
#
ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
ifneq ($(filter ARM%,$(CURRENT_ARCH_CONFIG)),)
DO_CTFCONVERT = 0
DO_CTFMERGE = 0
DO_CTFMACHO = 0
else
DO_CTFCONVERT = $(SUPPORTS_CTFCONVERT)
DO_CTFMERGE = 1
DO_CTFMACHO = $(NEEDS_CTF_MACHOS)
endif
else
DO_CTFCONVERT = $(SUPPORTS_CTFCONVERT)
DO_CTFMERGE = 1
DO_CTFMACHO = $(NEEDS_CTF_MACHOS)
endif
#
# Default INCFLAGS
#
INCFLAGS_IMPORT = $(patsubst %, -I$(OBJROOT)/EXPORT_HDRS/%, $(COMPONENT_IMPORT_LIST))
INCFLAGS_EXTERN = -I$(SRCROOT)/EXTERNAL_HEADERS
INCFLAGS_GEN = -I$(SRCROOT)/$(COMPONENT) -I$(OBJROOT)/EXPORT_HDRS/$(COMPONENT)
INCFLAGS_LOCAL = -I.
INCFLAGS_SDK = -I$(SDKROOT)/usr/local/include/kernel
INCFLAGS = $(INCFLAGS_LOCAL) $(INCFLAGS_GEN) $(INCFLAGS_IMPORT) $(INCFLAGS_EXTERN) $(INCFLAGS_MAKEFILE) $(INCFLAGS_SDK)
#
# Default MIGFLAGS
#
MIGFLAGS = $(DEFINES) $(INCFLAGS) -novouchers $($(addsuffix $(CURRENT_ARCH_CONFIG),CFLAGS_)) $($(addsuffix $(CURRENT_ARCH_CONFIG),ARCH_FLAGS_)) \
$(DEPLOYMENT_TARGET_FLAGS)
# Support for LLVM Profile Guided Optimization (PGO)
ifeq ($(BUILD_PROFILE),1)
CFLAGS_GEN += -fprofile-instr-generate -DPROFILE
CXXFLAGS_GEN += -fprofile-instr-generate -DPROFILE
endif
ifdef USE_PROFILE
CFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
CXXFLAGS_GEN += -fprofile-instr-use=$(USE_PROFILE)
LDFLAGS_KERNEL_GEN += -fprofile-instr-use=$(USE_PROFILE)
CFLAGS_GEN += -Wno-error=profile-instr-out-of-date
endif
#
# Support for LLVM Link Time Optimization (LTO)
#
# LTO can be explicitly enabled or disabled with BUILD_LTO=1|0
# and defaults to enabled except for DEBUG kernels
#
# CFLAGS_NOLTO_FLAG is needed on a per-file basis (for files
# that deal poorly with LTO, or files that must be machine
# code *.o files for xnu to build (i.e, setsegname runs on
# them).
#
# LDFLAGS_NOSTRIP_FLAG is used to support configurations that
# do not utilize an export list. For these configs to build,
# we need to prevent the LTO logic from dead stripping them.
LTO_ENABLED_RELEASE = 1
LTO_ENABLED_DEVELOPMENT = 1
LTO_ENABLED_DEBUG = 0
LTO_ENABLED_KASAN = 0
ifneq ($(BUILD_LTO),)
USE_LTO = $(BUILD_LTO)
else
USE_LTO = $(LTO_ENABLED_$(CURRENT_KERNEL_CONFIG))
endif
SUPPORTS_CTFCONVERT = 0
ifeq ($(USE_LTO),1)
CFLAGS_GEN += -flto
CXXFLAGS_GEN += -flto
LDFLAGS_KERNEL_GEN += -Wl,-mllvm,-inline-threshold=125 -Wl,-object_path_lto,$(TARGET)/lto.o # -Wl,-mllvm -Wl,-disable-fp-elim
LDFLAGS_NOSTRIP_FLAG = -rdynamic
CFLAGS_NOLTO_FLAG = -fno-lto
NEEDS_CTF_MACHOS = 1
else
LDFLAGS_NOSTRIP_FLAG =
CFLAGS_NOLTO_FLAG =
ifneq ($(CTFCONVERT),)
SUPPORTS_CTFCONVERT = 1
endif
NEEDS_CTF_MACHOS = 0
endif
ifeq ($(BUILD_JSON_COMPILATION_DATABASE),1)
BUILD_DSYM := 0
DO_CTFCONVERT := 0
DO_CTFMERGE := 0
DO_CTFMACHO := 0
KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
KC++ = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CXX)
S_KCC = $(JSONCOMPILATIONDB) $(OBJPATH)/compile_commands.json $(PWD) $< $(CC)
STRIP = true
endif
#
# Default VPATH
#
export VPATH = .:$(SOURCE)
#
# Macros that control installation of kernel and its header files
#
# install flags for header files
#
INSTALL_FLAGS = -c -S -m 0444
DATA_INSTALL_FLAGS = -c -S -m 0644
EXEC_INSTALL_FLAGS = -c -S -m 0755
#
# Header file destinations
#
FRAMEDIR = /System/Library/Frameworks
SINCVERS = B
SINCFRAME = $(FRAMEDIR)/System.framework
SINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Headers
SPINCDIR = $(SINCFRAME)/Versions/$(SINCVERS)/PrivateHeaders
SRESDIR = $(SINCFRAME)/Versions/$(SINCVERS)/Resources
ifndef INCDIR
INCDIR = /usr/include
endif
ifndef LCLDIR
LCLDIR = $(SPINCDIR)
endif
KINCVERS = A
KINCFRAME = $(FRAMEDIR)/Kernel.framework
KINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Headers
KPINCDIR = $(KINCFRAME)/Versions/$(KINCVERS)/PrivateHeaders
KRESDIR = $(KINCFRAME)/Versions/$(KINCVERS)/Resources
XNU_PRIVATE_UNIFDEF = -UMACH_KERNEL_PRIVATE -UBSD_KERNEL_PRIVATE -UIOKIT_KERNEL_PRIVATE -ULIBKERN_KERNEL_PRIVATE -ULIBSA_KERNEL_PRIVATE -UPEXPERT_KERNEL_PRIVATE -UXNU_KERNEL_PRIVATE
PLATFORM_UNIFDEF = $(foreach x,$(SUPPORTED_PLATFORMS),$(if $(filter $(PLATFORM),$(x)),-DPLATFORM_$(x) $(foreach token,$(PLATFORM_UNIFDEF_BLACKLIST_TOKENS_$(x)),-U$(token)),-UPLATFORM_$(x)))
SPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -DPRIVATE -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
SINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UKERNEL -UPRIVATE -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
KPINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -DKERNEL_PRIVATE -DPRIVATE -DKERNEL -U_OPEN_SOURCE_ -U__OPEN_SOURCE__
KINCFRAME_UNIFDEF = $(PLATFORM_UNIFDEF) $(XNU_PRIVATE_UNIFDEF) $(SEED_DEFINES) -UKERNEL_PRIVATE -UPRIVATE -DKERNEL -D_OPEN_SOURCE_ -D__OPEN_SOURCE__
#
# Compononent Header file destinations
#
EXPDIR = EXPORT_HDRS/$(COMPONENT)
#
# Strip Flags
#
STRIP_FLAGS_RELEASE = -S -x
STRIP_FLAGS_DEVELOPMENT = -S
STRIP_FLAGS_KASAN = $(STRIP_FLAGS_DEVELOPMENT)
STRIP_FLAGS_DEBUG = -S
STRIP_FLAGS_PROFILE = -S -x
STRIP_FLAGS = $($(addsuffix $(CURRENT_KERNEL_CONFIG),STRIP_FLAGS_))
#
# dsymutil flags
#
DSYMUTIL_FLAGS_GEN = --minimize
DSYMUTIL_FLAGS_X86_64 = --arch=x86_64
DSYMUTIL_FLAGS_X86_64H = --arch=x86_64h
DSYMUTIL_FLAGS = $(DSYMUTIL_FLAGS_GEN) \
$($(addsuffix $(CURRENT_ARCH_CONFIG),DSYMUTIL_FLAGS_))
#
# Man Page destination
#
MANDIR = /usr/share/man
#
# DEBUG alias location
#
DEVELOPER_EXTRAS_DIR = /AppleInternal/CoreOS/xnu_$(CURRENT_KERNEL_CONFIG_LC)
#
# mach_kernel install location
#
INSTALL_KERNEL_DIR = /
#
# new OS X install location
#
SYSTEM_LIBRARY_KERNELS_DIR = /System/Library/Kernels
#
# File names in DSTROOT
#
ifeq ($(PLATFORM),MacOSX)
KERNEL_FILE_NAME_PREFIX = kernel
else
KERNEL_FILE_NAME_PREFIX = mach
endif
ifeq ($(CURRENT_MACHINE_CONFIG),NONE)
ifeq ($(CURRENT_KERNEL_CONFIG),RELEASE)
KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX)
KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
else
KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC)
KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX).py
endif
else
KERNEL_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_MACHINE_CONFIG_LC)
KERNEL_LLDBBOOTSTRAP_NAME = $(KERNEL_FILE_NAME_PREFIX)_$(CURRENT_KERNEL_CONFIG_LC).py
endif
CURRENT_ALIAS_MACHINE_CONFIG = $(word 4,$(subst ^, ,$(CURRENT_BUILD_CONFIG)))
CURRENT_ALIAS_MACHINE_CONFIG_LC = $(shell printf "%s" "$(CURRENT_ALIAS_MACHINE_CONFIG)" | $(TR) A-Z a-z)
ifneq ($(CURRENT_ALIAS_MACHINE_CONFIG),)
ALIAS_FILE_NAME = $(KERNEL_FILE_NAME_PREFIX).$(CURRENT_KERNEL_CONFIG_LC).$(CURRENT_ALIAS_MACHINE_CONFIG_LC)
endif
#
# System.kext pseudo-kext install location
#
INSTALL_EXTENSIONS_DIR = /System/Library/Extensions
#
# KDK location
#
INSTALL_KERNEL_SYM_DIR = /System/Library/Extensions/KDK
#
# Misc. Etc.
#
INSTALL_SHARE_MISC_DIR = /usr/share/misc
INSTALL_DTRACE_SCRIPTS_DIR = /usr/lib/dtrace
INSTALL_DTRACE_LIBEXEC_DIR = /usr/libexec/dtrace
#
# Overrides for XBS build aliases
#
ifeq ($(RC_ProjectName),xnu_debug)
INSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
INSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
INSTALL_KERNEL_SYM_TO_KDK = 1
INSTALL_XNU_DEBUG_FILES = 1
else ifeq ($(RC_ProjectName),xnu_kasan)
ifeq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
# MacOS
INSTALL_KERNEL_DIR := $(DEVELOPER_EXTRAS_DIR)
INSTALL_KERNEL_SYM_DIR := $(DEVELOPER_EXTRAS_DIR)
endif
INSTALL_KERNEL_SYM_TO_KDK = 1
INSTALL_KASAN_ONLY = 1
else ifneq ($(filter $(SUPPORTED_EMBEDDED_PLATFORMS),$(PLATFORM)),)
INSTALL_KERNEL_SYM_TO_KDK = 1
USE_BINARY_PLIST = 1
else ifneq ($(filter $(SUPPORTED_SIMULATOR_PLATFORMS),$(PLATFORM)),)
USE_BINARY_PLIST = 1
else ifeq ($(PLATFORM),MacOSX)
INSTALL_KERNEL_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
INSTALL_KERNEL_SYM_DIR := $(SYSTEM_LIBRARY_KERNELS_DIR)
INSTALL_KERNEL_SYM_TO_KDK = $(if $(filter YES,$(DWARF_DSYM_FILE_SHOULD_ACCOMPANY_PRODUCT)),1,0)
endif
# vim: set ft=make: