xref: /aosp_15_r20/external/ltp/testcases/kernel/kvm/Makefile (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker# SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker# Copyright (c) 2021 Linux Test Project
3*49cdfc7eSAndroid Build Coastguard Worker
4*49cdfc7eSAndroid Build Coastguard Workertop_srcdir		?= ../../..
5*49cdfc7eSAndroid Build Coastguard Worker
6*49cdfc7eSAndroid Build Coastguard Workerinclude $(top_srcdir)/include/mk/testcases.mk
7*49cdfc7eSAndroid Build Coastguard Worker
8*49cdfc7eSAndroid Build Coastguard WorkerASFLAGS =
9*49cdfc7eSAndroid Build Coastguard WorkerCPPFLAGS += -I$(abs_srcdir)/include
10*49cdfc7eSAndroid Build Coastguard WorkerGUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
11*49cdfc7eSAndroid Build Coastguard WorkerGUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -fno-stack-protector -mno-mmx -mno-sse
12*49cdfc7eSAndroid Build Coastguard WorkerGUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -z noexecstack
13*49cdfc7eSAndroid Build Coastguard WorkerGUEST_LDLIBS =
14*49cdfc7eSAndroid Build Coastguard WorkerKVM_LD ?= $(LD)
15*49cdfc7eSAndroid Build Coastguard Worker
16*49cdfc7eSAndroid Build Coastguard WorkerFILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Workerifeq ($(HOST_CPU),x86_64)
19*49cdfc7eSAndroid Build Coastguard Worker	ifneq (,$(findstring m32,$(CFLAGS)))
20*49cdfc7eSAndroid Build Coastguard Worker		HOST_CPU = x86
21*49cdfc7eSAndroid Build Coastguard Worker	endif
22*49cdfc7eSAndroid Build Coastguard Workerendif
23*49cdfc7eSAndroid Build Coastguard Worker
24*49cdfc7eSAndroid Build Coastguard Workerifeq ($(HOST_CPU),x86)
25*49cdfc7eSAndroid Build Coastguard Worker	GUEST_CFLAGS += -m32
26*49cdfc7eSAndroid Build Coastguard Worker	ASFLAGS += --32
27*49cdfc7eSAndroid Build Coastguard Worker
28*49cdfc7eSAndroid Build Coastguard Worker	ifdef LTP_CFLAGS_FFIXED_EBP
29*49cdfc7eSAndroid Build Coastguard Worker		GUEST_CFLAGS += -ffixed-ebp
30*49cdfc7eSAndroid Build Coastguard Worker	endif
31*49cdfc7eSAndroid Build Coastguard Workerendif
32*49cdfc7eSAndroid Build Coastguard Worker
33*49cdfc7eSAndroid Build Coastguard Worker# Some distros enable -pie by default. That breaks KVM payload linking.
34*49cdfc7eSAndroid Build Coastguard Workerifdef LTP_CFLAGS_NOPIE
35*49cdfc7eSAndroid Build Coastguard Worker	GUEST_CFLAGS += -fno-pie
36*49cdfc7eSAndroid Build Coastguard Worker	GUEST_LDFLAGS += -no-pie
37*49cdfc7eSAndroid Build Coastguard Workerendif
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard WorkerGUEST_LDFLAGS += -Wl,-T$(abs_srcdir)/linker/$(HOST_CPU).lds
40*49cdfc7eSAndroid Build Coastguard WorkerARCH_OBJ = bootstrap_$(HOST_CPU).o
41*49cdfc7eSAndroid Build Coastguard Worker
42*49cdfc7eSAndroid Build Coastguard Workerifeq ($(HOST_CPU),x86_64)
43*49cdfc7eSAndroid Build Coastguard WorkerARCH_OBJ += lib_x86.o
44*49cdfc7eSAndroid Build Coastguard WorkerBIN_FORMAT=elf64-x86-64
45*49cdfc7eSAndroid Build Coastguard Workerelse ifeq ($(HOST_CPU),x86)
46*49cdfc7eSAndroid Build Coastguard WorkerARCH_OBJ += lib_x86.o
47*49cdfc7eSAndroid Build Coastguard WorkerBIN_FORMAT=elf32-i386
48*49cdfc7eSAndroid Build Coastguard Workerelse
49*49cdfc7eSAndroid Build Coastguard WorkerMAKE_TARGETS =
50*49cdfc7eSAndroid Build Coastguard Workerendif
51*49cdfc7eSAndroid Build Coastguard Worker
52*49cdfc7eSAndroid Build Coastguard Workerlib_guest.o $(ARCH_OBJ): CPPFLAGS	:= $(GUEST_CPPFLAGS)
53*49cdfc7eSAndroid Build Coastguard Workerlib_guest.o $(ARCH_OBJ): CFLAGS		:= $(GUEST_CFLAGS)
54*49cdfc7eSAndroid Build Coastguard Worker
55*49cdfc7eSAndroid Build Coastguard Workerkvm_svm03: CFLAGS += -pthread
56*49cdfc7eSAndroid Build Coastguard Workerkvm_svm03: LDLIBS += -pthread
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Workerinclude $(top_srcdir)/include/mk/generic_leaf_target.mk
59*49cdfc7eSAndroid Build Coastguard Worker
60*49cdfc7eSAndroid Build Coastguard Worker%-payload.o: %.c lib_guest.o $(ARCH_OBJ)
61*49cdfc7eSAndroid Build Coastguard Workerifdef VERBOSE
62*49cdfc7eSAndroid Build Coastguard Worker	$(CC) $(GUEST_CPPFLAGS) $(GUEST_CFLAGS) $(GUEST_LDFLAGS) -o $*-payload.elf $^ $(GUEST_LDLIBS)
63*49cdfc7eSAndroid Build Coastguard Worker	objcopy -O binary -j .init.boot -j .text -j .data -j .init -j .preinit_array -j .init_array --gap-fill=0 $*-payload.elf $*-payload.bin
64*49cdfc7eSAndroid Build Coastguard Worker	$(KVM_LD) -z noexecstack -r -T $(abs_srcdir)/linker/payload.lds --oformat=$(BIN_FORMAT) -o $@ $*-payload.bin
65*49cdfc7eSAndroid Build Coastguard Workerelse
66*49cdfc7eSAndroid Build Coastguard Worker	@$(CC) $(GUEST_CPPFLAGS) $(GUEST_CFLAGS) $(GUEST_LDFLAGS) -o $*-payload.elf $^ $(GUEST_LDLIBS)
67*49cdfc7eSAndroid Build Coastguard Worker	@objcopy -O binary -j .init.boot -j .text -j .data -j .init -j .preinit_array -j .init_array --gap-fill=0 $*-payload.elf $*-payload.bin
68*49cdfc7eSAndroid Build Coastguard Worker	@$(KVM_LD) -z noexecstack -r -T $(abs_srcdir)/linker/payload.lds --oformat=$(BIN_FORMAT) -o $@ $*-payload.bin
69*49cdfc7eSAndroid Build Coastguard Worker	@echo KVM_CC $(target_rel_dir)$@
70*49cdfc7eSAndroid Build Coastguard Workerendif
71*49cdfc7eSAndroid Build Coastguard Worker	@rm $*-payload.elf $*-payload.bin
72*49cdfc7eSAndroid Build Coastguard Worker
73*49cdfc7eSAndroid Build Coastguard Worker$(MAKE_TARGETS): %: %-payload.o lib_host.o
74