xref: /linux/arch/arm64/kvm/hyp/nvhe/Makefile (revision ab25464bdabd45f283cc1194e332040f89071106)
176217129SDavid Brazdil# SPDX-License-Identifier: GPL-2.0
276217129SDavid Brazdil#
376217129SDavid Brazdil# Makefile for Kernel-based Virtual Machine module, HYP/nVHE part
476217129SDavid Brazdil#
576217129SDavid Brazdil
676217129SDavid Brazdilasflags-y := -D__KVM_NVHE_HYPERVISOR__
776217129SDavid Brazdilccflags-y := -D__KVM_NVHE_HYPERVISOR__
876217129SDavid Brazdil
9c04dd455SDavid Brazdilobj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o
10c04dd455SDavid Brazdilobj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
11c04dd455SDavid Brazdil	 ../fpsimd.o ../hyp-entry.o
1276217129SDavid Brazdil
13*ab25464bSDavid Brazdil##
14*ab25464bSDavid Brazdil## Build rules for compiling nVHE hyp code
15*ab25464bSDavid Brazdil## Output of this folder is `kvm_nvhe.o`, a partially linked object
16*ab25464bSDavid Brazdil## file containing all nVHE hyp code and data.
17*ab25464bSDavid Brazdil##
1876217129SDavid Brazdil
19*ab25464bSDavid Brazdilhyp-obj := $(patsubst %.o,%.nvhe.o,$(obj-y))
20*ab25464bSDavid Brazdilobj-y := kvm_nvhe.o
21*ab25464bSDavid Brazdilextra-y := $(hyp-obj) kvm_nvhe.tmp.o hyp.lds
22*ab25464bSDavid Brazdil
23*ab25464bSDavid Brazdil# 1) Compile all source files to `.nvhe.o` object files. The file extension
24*ab25464bSDavid Brazdil#    avoids file name clashes for files shared with VHE.
25*ab25464bSDavid Brazdil$(obj)/%.nvhe.o: $(src)/%.c FORCE
2676217129SDavid Brazdil	$(call if_changed_rule,cc_o_c)
27*ab25464bSDavid Brazdil$(obj)/%.nvhe.o: $(src)/%.S FORCE
2876217129SDavid Brazdil	$(call if_changed_rule,as_o_S)
29*ab25464bSDavid Brazdil
30*ab25464bSDavid Brazdil# 2) Compile linker script.
31*ab25464bSDavid Brazdil$(obj)/hyp.lds: $(src)/hyp.lds.S FORCE
32*ab25464bSDavid Brazdil	$(call if_changed_dep,cpp_lds_S)
33*ab25464bSDavid Brazdil
34*ab25464bSDavid Brazdil# 3) Partially link all '.nvhe.o' files and apply the linker script.
35*ab25464bSDavid Brazdil#    Prefixes names of ELF sections with '.hyp', eg. '.hyp.text'.
36*ab25464bSDavid Brazdil#    Note: The following rule assumes that the 'ld' rule puts LDFLAGS before
37*ab25464bSDavid Brazdil#          the list of dependencies to form '-T $(obj)/hyp.lds'. This is to
38*ab25464bSDavid Brazdil#          keep the dependency on the target while avoiding an error from
39*ab25464bSDavid Brazdil#          GNU ld if the linker script is passed to it twice.
40*ab25464bSDavid BrazdilLDFLAGS_kvm_nvhe.tmp.o := -r -T
41*ab25464bSDavid Brazdil$(obj)/kvm_nvhe.tmp.o: $(obj)/hyp.lds $(addprefix $(obj)/,$(hyp-obj)) FORCE
42*ab25464bSDavid Brazdil	$(call if_changed,ld)
43*ab25464bSDavid Brazdil
44*ab25464bSDavid Brazdil# 4) Produce the final 'kvm_nvhe.o', ready to be linked into 'vmlinux'.
45*ab25464bSDavid Brazdil#    Prefixes names of ELF symbols with '__kvm_nvhe_'.
46*ab25464bSDavid Brazdil$(obj)/kvm_nvhe.o: $(obj)/kvm_nvhe.tmp.o FORCE
4776217129SDavid Brazdil	$(call if_changed,hypcopy)
4876217129SDavid Brazdil
49bdbc0c7aSDavid Brazdil# The HYPCOPY command uses `objcopy` to prefix all ELF symbol names
50*ab25464bSDavid Brazdil# to avoid clashes with VHE code/data.
5176217129SDavid Brazdilquiet_cmd_hypcopy = HYPCOPY $@
52*ab25464bSDavid Brazdil      cmd_hypcopy = $(OBJCOPY) --prefix-symbols=__kvm_nvhe_ $< $@
53c50cb043SDavid Brazdil
54c50cb043SDavid Brazdil# Remove ftrace and Shadow Call Stack CFLAGS.
55c50cb043SDavid Brazdil# This is equivalent to the 'notrace' and '__noscs' annotations.
56c50cb043SDavid BrazdilKBUILD_CFLAGS := $(filter-out $(CC_FLAGS_FTRACE) $(CC_FLAGS_SCS), $(KBUILD_CFLAGS))
5776217129SDavid Brazdil
5876217129SDavid Brazdil# KVM nVHE code is run at a different exception code with a different map, so
5976217129SDavid Brazdil# compiler instrumentation that inserts callbacks or checks into the code may
6076217129SDavid Brazdil# cause crashes. Just disable it.
6176217129SDavid BrazdilGCOV_PROFILE	:= n
6276217129SDavid BrazdilKASAN_SANITIZE	:= n
6376217129SDavid BrazdilUBSAN_SANITIZE	:= n
6476217129SDavid BrazdilKCOV_INSTRUMENT	:= n
6576217129SDavid Brazdil
6676217129SDavid Brazdil# Skip objtool checking for this directory because nVHE code is compiled with
6776217129SDavid Brazdil# non-standard build rules.
6876217129SDavid BrazdilOBJECT_FILES_NON_STANDARD := y
69