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
8f80fd3a5SDmitry SafonovTARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt ptrace_syscall test_mremap_vdso \
90eb1d0faSAndy Lutomirski			check_initial_reg_state sigreturn ldt_gdt iopl mpx-mini-test ioperm \
10352909b4SAndy Lutomirski			protection_keys test_vdso test_vsyscall
116c25da5aSAndy LutomirskiTARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
120f672809SAndy Lutomirski			test_FCMOV test_FCOMI test_FISTTP \
1365cacec1SAndy Lutomirski			vdso_restorer
1466060214SAndy LutomirskiTARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
153f705dfdSAndy Lutomirski
16c2affbf9SAndy LutomirskiTARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY)
17c31b3425SAndy LutomirskiTARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
18c2affbf9SAndy LutomirskiBINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
19c31b3425SAndy LutomirskiBINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
203f705dfdSAndy Lutomirski
21a8ba798bSbamvor.zhangjian@huawei.comBINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
22a8ba798bSbamvor.zhangjian@huawei.comBINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
23a8ba798bSbamvor.zhangjian@huawei.com
243346a6a4SShuah KhanCFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
253f705dfdSAndy Lutomirski
26f9ea4a33STyler BakerUNAME_M := $(shell uname -m)
27e9886aceSAndy LutomirskiCAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
28e9886aceSAndy LutomirskiCAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
293f705dfdSAndy Lutomirski
30e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_I386),1)
313f705dfdSAndy Lutomirskiall: all_32
32c1e6e5cbSAndy LutomirskiTEST_PROGS += $(BINARIES_32)
33e9886aceSAndy Lutomirskiendif
34e9886aceSAndy Lutomirski
35e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_X86_64),1)
363f705dfdSAndy Lutomirskiall: all_64
3707620abeSTyler BakerTEST_PROGS += $(BINARIES_64)
383f705dfdSAndy Lutomirskiendif
393f705dfdSAndy Lutomirski
40e9886aceSAndy Lutomirskiall_32: $(BINARIES_32)
413f705dfdSAndy Lutomirski
423f705dfdSAndy Lutomirskiall_64: $(BINARIES_64)
433f705dfdSAndy Lutomirski
44eebed11aSShuah KhanEXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
453f705dfdSAndy Lutomirski
46a8ba798bSbamvor.zhangjian@huawei.com$(BINARIES_32): $(OUTPUT)/%_32: %.c
4757ca6897SDenys Vlasenko	$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
483f705dfdSAndy Lutomirski
49a8ba798bSbamvor.zhangjian@huawei.com$(BINARIES_64): $(OUTPUT)/%_64: %.c
503f705dfdSAndy Lutomirski	$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
513f705dfdSAndy Lutomirski
52e9886aceSAndy Lutomirski# x86_64 users should be encouraged to install 32-bit libraries
53e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
54e9886aceSAndy Lutomirskiall: warn_32bit_failure
55e9886aceSAndy Lutomirski
56e9886aceSAndy Lutomirskiwarn_32bit_failure:
57e9886aceSAndy Lutomirski	@echo "Warning: you seem to have a broken 32-bit build" 2>&1; 	\
58e9886aceSAndy Lutomirski	echo "environment.  This will reduce test coverage of 64-bit" 2>&1; \
59e9886aceSAndy Lutomirski	echo "kernels.  If you are using a Debian-like distribution," 2>&1; \
60e9886aceSAndy Lutomirski	echo "try:"; 2>&1; \
613f705dfdSAndy Lutomirski	echo "";							\
623f705dfdSAndy Lutomirski	echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
633f705dfdSAndy Lutomirski	echo "";							\
643f705dfdSAndy Lutomirski	echo "If you are using a Fedora-like distribution, try:";	\
653f705dfdSAndy Lutomirski	echo "";							\
663f705dfdSAndy Lutomirski	echo "  yum install glibc-devel.*i686";				\
67e9886aceSAndy Lutomirski	exit 0;
68e9886aceSAndy Lutomirskiendif
69e22438f8SAndy Lutomirski
70e22438f8SAndy Lutomirski# Some tests have additional dependencies.
71a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/sysret_ss_attrs_64: thunks.S
72a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
73a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/test_syscall_vdso_32: thunks_32.S
74e21d50f3SAndy Lutomirski
75e21d50f3SAndy Lutomirski# check_initial_reg_state is special: it needs a custom entry, and it
76e21d50f3SAndy Lutomirski# needs to be static so that its interpreter doesn't destroy its initial
77e21d50f3SAndy Lutomirski# state.
78a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
79a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
80