xref: /xnu-10002.81.5/makedefs/MakeInc.san (revision 5e3eaea39dcf651e66cb99ba7d70e32cc4a99587)
1# -*- mode: makefile;-*-
2#
3# Copyright (C) 2021 Apple Inc. All rights reserved.
4#
5# MakeInc.san contains global definitions for building,
6# linking and installing sanitizer runtime support.
7#
8
9#
10# Generates rule to build symbolset file from specific export file.
11#
12#     $(1) - Kext name (without .symbolset suffix)
13#     $(2) - Exports name (without .exports suffix)
14
15define san_symbolset_template
16
17SYMBOL_SET_BUILD_$(1) := $$(OBJPATH)/config/$(1).symbolset
18
19# Our external dependency on config/allsymbols from config hierarchy config_all is hardcoded in the toplevel Makefile!
20$$(SYMBOL_SET_BUILD_$(1)): $$(SRCROOT)/config/$(2).exports $$(OBJPATH)/config/allsymbols $$(KEXT_CREATE_SYMBOL_SET)
21	@$$(LOG_SYMBOLSET) "$(1)$$(Color0) ($$(ColorLF)$$(CURRENT_ARCH_CONFIG_LC), $$(CURRENT_KERNEL_CONFIG_LC) $$(Color0))"
22	$$(_v)$$(KEXT_CREATE_SYMBOL_SET)			\
23		$$(ARCH_FLAGS_$$(CURRENT_ARCH_CONFIG))	\
24		-import $$(OBJPATH)/config/allsymbols		\
25		-export $$<		                \
26		-output $$@ $(_vstdout)
27
28endef
29
30#
31# Generate rule to build System.kext plugin for give sanitizer.
32#
33#     $(1) - Name of the kext plugin
34#     $(2) - Name of the kext variant binary (Kasan_kasan, Kcov, ...)
35#
36
37define san_kext_dstroot_rule_template
38
39DSTROOT_KEXT_$(2) := $$(DSTROOT_SYSTEM_KEXT_PATH)/$(1)/$(2)
40
41$$(DSTROOT_KEXT_$(2)): $$(DSTROOT_SYSTEM_KEXT_PATH)/$(1)/% : $$(SYMROOT_SYSTEM_KEXT_PATH)/$(1)/%
42	$$(_v)$$(MKDIR) $$(@D)
43	@$$(LOG_INSTALLVARIANT) "$$(Color0)symbolset $$(ColorF)$$(@F)$$(Color0) ($$(ColorLF)$$(CURRENT_KERNEL_CONFIG_LC)$$(Color0))"
44	$$(_v)$$(INSTALL) $$(EXEC_INSTALL_FLAGS) $$< $$@
45
46endef
47
48#
49# Generate rule to build System.kext plugin in SYMROOT
50#
51#     $(1) - Name of the kext plugin
52#     $(2) - Name of the kext variant binary (Kasan_kasan, Kcov, ...)
53#     $(3) - build configs to get symbolset binaries from corresponding OBJDIR
54#
55
56define san_kext_symroot_rule_template
57
58SYMROOT_KEXT_$(2) := $$(SYMROOT_SYSTEM_KEXT_PATH)/$(1)/$(2)
59
60$$(SYMROOT_KEXT_$(2)): $$(addsuffix /config/$(2).symbolset, \
61		$$(addprefix $$(OBJROOT)/,$$(foreach bc,$(3),$$(call function_convert_build_config_to_objdir,$$(bc)))))
62	@$$(LOG_INSTALLSYM) "$$(Color0)symbolset $$(ColorF)$(2)$$(Color0) ($$(ColorLF)$$(CURRENT_KERNEL_CONFIG_LC)$$(Color0))"
63	$$(_v)$$(MKDIR) $$(@D)
64	$$(_v)$$(LIPO) -create `(echo $$^ | xargs -L 1 lipo -detailed_info) | \
65		awk '/is architecture/ {s[$$$$6]=$$$$3} END {for (a in s) {print s[a]}}'` -output $$@ $$(_vstdout)
66
67endef
68