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