Makefile (81867b75dbfde82fda5476c7c219a777aa36fbaf) Makefile (ab25464bdabd45f283cc1194e332040f89071106)
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
4#
5
6asflags-y := -D__KVM_NVHE_HYPERVISOR__
7ccflags-y := -D__KVM_NVHE_HYPERVISOR__
8
1# SPDX-License-Identifier: GPL-2.0
2#
3# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
4#
5
6asflags-y := -D__KVM_NVHE_HYPERVISOR__
7ccflags-y := -D__KVM_NVHE_HYPERVISOR__
8
9obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o hyp-main.o
9obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o
10obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
11 ../fpsimd.o ../hyp-entry.o
12
10obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
11 ../fpsimd.o ../hyp-entry.o
12
13obj-y := $(patsubst %.o,%.hyp.o,$(obj-y))
14extra-y := $(patsubst %.hyp.o,%.hyp.tmp.o,$(obj-y))
13##
14## Build rules for compiling nVHE hyp code
15## Output of this folder is `kvm_nvhe.o`, a partially linked object
16## file containing all nVHE hyp code and data.
17##
15
18
16$(obj)/%.hyp.tmp.o: $(src)/%.c FORCE
19hyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y))
20obj-y := kvm_nvhe.o
21extra-y := $(hyp-obj) kvm_nvhe.tmp.o hyp.lds
22
23# 1) Compile all source files to `.nvhe.o` object files. The file extension
24# avoids file name clashes for files shared with VHE.
25$(obj)/%.nvhe.o: $(src)/%.c FORCE
17 $(call if_changed_rule,cc_o_c)
26 $(call if_changed_rule,cc_o_c)
18$(obj)/%.hyp.tmp.o: $(src)/%.S FORCE
27$(obj)/%.nvhe.o: $(src)/%.S FORCE
19 $(call if_changed_rule,as_o_S)
28 $(call if_changed_rule,as_o_S)
20$(obj)/%.hyp.o: $(obj)/%.hyp.tmp.o FORCE
21 $(call if_changed,hypcopy)
22
29
23# Disable reordering functions by GCC (enabled at -O2).
24# This pass puts functions into '.text.*' sections to aid the linker
25# in optimizing ELF layout. See HYPCOPY comment below for more info.
26ccflags-y += $(call cc-option,-fno-reorder-functions)
30# 2) Compile linker script.
31$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
32 $(call if_changed_dep,cpp_lds_S)
27
33
34# 3) Partially link all '.nvhe.o' files and apply the linker script.
35# Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
36# Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
37# the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
38# keep the dependency on the target while avoiding an error from
39# GNU ld if the linker script is passed to it twice.
40LDFLAGS_kvm_nvhe.tmp.o := -r -T
41$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
42 $(call if_changed,ld)
43
44# 4) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
45# Prefixes names of ELF symbols with '__kvm_nvhe_'.
46$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.tmp.o FORCE
47 $(call if_changed,hypcopy)
48
28# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
49# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
29# and relevant ELF section names to avoid clashes with VHE code/data.
30#
31# Hyp code is assumed to be in the '.text' section of the input object
32# files (with the exception of specialized sections such as
33# '.hyp.idmap.text'). This assumption may be broken by a compiler that
34# divides code into sections like '.text.unlikely' so as to optimize
35# ELF layout. HYPCOPY checks that no such sections exist in the input
36# using `objdump`, otherwise they would be linked together with other
37# kernel code and not memory-mapped correctly at runtime.
50# to avoid clashes with VHE code/data.
38quiet_cmd_hypcopy = HYPCOPY $@
51quiet_cmd_hypcopy = HYPCOPY $@
39 cmd_hypcopy = \
40 if $(OBJDUMP) -h $< | grep -F '.text.'; then \
41 echo "$@: function reordering not supported in nVHE hyp code" >&2; \
42 /bin/false; \
43 fi; \
44 $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ \
45 --rename-section=.text=.hyp.text \
46 $< $@
52 cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
47
48# Remove ftrace and Shadow Call Stack CFLAGS.
49# This is equivalent to the 'notrace' and '__noscs' annotations.
50KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))
51
52# KVM nVHE code is run at a different exception code with a different map, so
53# compiler instrumentation that inserts callbacks or checks into the code may
54# cause crashes. Just disable it.
55GCOV_PROFILE := n
56KASAN_SANITIZE := n
57UBSAN_SANITIZE := n
58KCOV_INSTRUMENT := n
59
60# Skip objtool checking for this directory because nVHE code is compiled with
61# non-standard build rules.
62OBJECT_FILES_NON_STANDARD := y
53
54# Remove ftrace and Shadow Call Stack CFLAGS.
55# This is equivalent to the 'notrace' and '__noscs' annotations.
56KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))
57
58# KVM nVHE code is run at a different exception code with a different map, so
59# compiler instrumentation that inserts callbacks or checks into the code may
60# cause crashes. Just disable it.
61GCOV_PROFILE := n
62KASAN_SANITIZE := n
63UBSAN_SANITIZE := n
64KCOV_INSTRUMENT := n
65
66# Skip objtool checking for this directory because nVHE code is compiled with
67# non-standard build rules.
68OBJECT_FILES_NON_STANDARD := y