1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2e9886aceSAndy Lutomirskiall:
3e9886aceSAndy Lutomirski
4e9886aceSAndy Lutomirskiinclude ../lib.mk
5e9886aceSAndy Lutomirski
6e9886aceSAndy Lutomirski.PHONY: all all_32 all_64 warn_32bit_failure clean
73f705dfdSAndy Lutomirski
89279ddf2SDominik BrodowskiUNAME_M := $(shell uname -m)
99279ddf2SDominik BrodowskiCAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
109279ddf2SDominik BrodowskiCAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
119279ddf2SDominik Brodowski
129279ddf2SDominik BrodowskiTARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
139279ddf2SDominik Brodowski			check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
14352909b4SAndy Lutomirski			protection_keys test_vdso test_vsyscall
156c25da5aSAndy LutomirskiTARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
160f672809SAndy Lutomirski			test_FCMOV test_FCOMI test_FISTTP \
1765cacec1SAndy Lutomirski			vdso_restorer
187f951220SDominik BrodowskiTARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
199279ddf2SDominik Brodowski# Some selftests require 32bit support enabled also on 64bit systems
209279ddf2SDominik BrodowskiTARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
213f705dfdSAndy Lutomirski
229279ddf2SDominik BrodowskiTARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
23c31b3425SAndy LutomirskiTARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
249279ddf2SDominik Brodowskiifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
259279ddf2SDominik BrodowskiTARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
269279ddf2SDominik Brodowskiendif
279279ddf2SDominik Brodowski
28c2affbf9SAndy LutomirskiBINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
29c31b3425SAndy LutomirskiBINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
303f705dfdSAndy Lutomirski
31a8ba798bSbamvor.zhangjian@huawei.comBINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
32a8ba798bSbamvor.zhangjian@huawei.comBINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
33a8ba798bSbamvor.zhangjian@huawei.com
343346a6a4SShuah KhanCFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
353f705dfdSAndy Lutomirski
36e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_I386),1)
373f705dfdSAndy Lutomirskiall: all_32
38c1e6e5cbSAndy LutomirskiTEST_PROGS += $(BINARIES_32)
394105c697SDominik BrodowskiEXTRA_CFLAGS += -DCAN_BUILD_32
40e9886aceSAndy Lutomirskiendif
41e9886aceSAndy Lutomirski
42e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_X86_64),1)
433f705dfdSAndy Lutomirskiall: all_64
4407620abeSTyler BakerTEST_PROGS += $(BINARIES_64)
454105c697SDominik BrodowskiEXTRA_CFLAGS += -DCAN_BUILD_64
463f705dfdSAndy Lutomirskiendif
473f705dfdSAndy Lutomirski
48e9886aceSAndy Lutomirskiall_32: $(BINARIES_32)
493f705dfdSAndy Lutomirski
503f705dfdSAndy Lutomirskiall_64: $(BINARIES_64)
513f705dfdSAndy Lutomirski
52eebed11aSShuah KhanEXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
533f705dfdSAndy Lutomirski
54a8ba798bSbamvor.zhangjian@huawei.com$(BINARIES_32): $(OUTPUT)/%_32: %.c
5557ca6897SDenys Vlasenko	$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
563f705dfdSAndy Lutomirski
57a8ba798bSbamvor.zhangjian@huawei.com$(BINARIES_64): $(OUTPUT)/%_64: %.c
583f705dfdSAndy Lutomirski	$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
593f705dfdSAndy Lutomirski
60e9886aceSAndy Lutomirski# x86_64 users should be encouraged to install 32-bit libraries
61e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
62e9886aceSAndy Lutomirskiall: warn_32bit_failure
63e9886aceSAndy Lutomirski
64e9886aceSAndy Lutomirskiwarn_32bit_failure:
65e9886aceSAndy Lutomirski	@echo "Warning: you seem to have a broken 32-bit build" 2>&1; 	\
66e9886aceSAndy Lutomirski	echo "environment.  This will reduce test coverage of 64-bit" 2>&1; \
67e9886aceSAndy Lutomirski	echo "kernels.  If you are using a Debian-like distribution," 2>&1; \
68e9886aceSAndy Lutomirski	echo "try:"; 2>&1; \
693f705dfdSAndy Lutomirski	echo "";							\
703f705dfdSAndy Lutomirski	echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
713f705dfdSAndy Lutomirski	echo "";							\
723f705dfdSAndy Lutomirski	echo "If you are using a Fedora-like distribution, try:";	\
733f705dfdSAndy Lutomirski	echo "";							\
743f705dfdSAndy Lutomirski	echo "  yum install glibc-devel.*i686";				\
75e9886aceSAndy Lutomirski	exit 0;
76e9886aceSAndy Lutomirskiendif
77e22438f8SAndy Lutomirski
78e22438f8SAndy Lutomirski# Some tests have additional dependencies.
79a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/sysret_ss_attrs_64: thunks.S
80a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
81a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/test_syscall_vdso_32: thunks_32.S
82e21d50f3SAndy Lutomirski
83e21d50f3SAndy Lutomirski# check_initial_reg_state is special: it needs a custom entry, and it
84e21d50f3SAndy Lutomirski# needs to be static so that its interpreter doesn't destroy its initial
85e21d50f3SAndy Lutomirski# state.
86a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
87a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
88