x86/entry/64: Fix CR3 restore in paranoid_exit()
[sfrench/cifs-2.6.git] / tools / testing / selftests / x86 / Makefile
1 # SPDX-License-Identifier: GPL-2.0
2 all:
3
4 include ../lib.mk
5
6 .PHONY: all all_32 all_64 warn_32bit_failure clean
7
8 UNAME_M := $(shell uname -m)
9 CAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32)
10 CAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c)
11
12 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
13                         check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
14                         protection_keys test_vdso test_vsyscall
15 TARGETS_C_32BIT_ONLY := entry_from_vm86 syscall_arg_fault test_syscall_vdso unwind_vdso \
16                         test_FCMOV test_FCOMI test_FISTTP \
17                         vdso_restorer
18 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip
19 # Some selftests require 32bit support enabled also on 64bit systems
20 TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
21
22 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
23 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
24 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
25 TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
26 endif
27
28 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
29 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
30
31 BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
32 BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
33
34 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall -no-pie
35
36 ifeq ($(CAN_BUILD_I386),1)
37 all: all_32
38 TEST_PROGS += $(BINARIES_32)
39 EXTRA_CFLAGS += -DCAN_BUILD_32
40 endif
41
42 ifeq ($(CAN_BUILD_X86_64),1)
43 all: all_64
44 TEST_PROGS += $(BINARIES_64)
45 EXTRA_CFLAGS += -DCAN_BUILD_64
46 endif
47
48 all_32: $(BINARIES_32)
49
50 all_64: $(BINARIES_64)
51
52 EXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
53
54 $(BINARIES_32): $(OUTPUT)/%_32: %.c
55         $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
56
57 $(BINARIES_64): $(OUTPUT)/%_64: %.c
58         $(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
59
60 # x86_64 users should be encouraged to install 32-bit libraries
61 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
62 all: warn_32bit_failure
63
64 warn_32bit_failure:
65         @echo "Warning: you seem to have a broken 32-bit build" 2>&1;   \
66         echo "environment.  This will reduce test coverage of 64-bit" 2>&1; \
67         echo "kernels.  If you are using a Debian-like distribution," 2>&1; \
68         echo "try:"; 2>&1; \
69         echo "";                                                        \
70         echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
71         echo "";                                                        \
72         echo "If you are using a Fedora-like distribution, try:";       \
73         echo "";                                                        \
74         echo "  yum install glibc-devel.*i686";                         \
75         exit 0;
76 endif
77
78 # Some tests have additional dependencies.
79 $(OUTPUT)/sysret_ss_attrs_64: thunks.S
80 $(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
81 $(OUTPUT)/test_syscall_vdso_32: thunks_32.S
82
83 # check_initial_reg_state is special: it needs a custom entry, and it
84 # needs to be static so that its interpreter doesn't destroy its initial
85 # state.
86 $(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
87 $(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static