x86/syscalls: Split the x32 syscalls into their own table
[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 CAN_BUILD_WITH_NOPIE := $(shell ./check_cc.sh $(CC) trivial_program.c -no-pie)
12
13 TARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
14                         check_initial_reg_state sigreturn iopl mpx-mini-test ioperm \
15                         protection_keys test_vdso test_vsyscall mov_ss_trap \
16                         syscall_arg_fault
17 TARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \
18                         test_FCMOV test_FCOMI test_FISTTP \
19                         vdso_restorer
20 TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip syscall_numbering
21 # Some selftests require 32bit support enabled also on 64bit systems
22 TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
23
24 TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
25 TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
26 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
27 TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
28 endif
29
30 BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
31 BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
32
33 BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
34 BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
35
36 CFLAGS := -O2 -g -std=gnu99 -pthread -Wall
37
38 # call32_from_64 in thunks.S uses absolute addresses.
39 ifeq ($(CAN_BUILD_WITH_NOPIE),1)
40 CFLAGS += -no-pie
41 endif
42
43 define gen-target-rule-32
44 $(1) $(1)_32: $(OUTPUT)/$(1)_32
45 .PHONY: $(1) $(1)_32
46 endef
47
48 define gen-target-rule-64
49 $(1) $(1)_64: $(OUTPUT)/$(1)_64
50 .PHONY: $(1) $(1)_64
51 endef
52
53 ifeq ($(CAN_BUILD_I386),1)
54 all: all_32
55 TEST_PROGS += $(BINARIES_32)
56 EXTRA_CFLAGS += -DCAN_BUILD_32
57 $(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t))))
58 endif
59
60 ifeq ($(CAN_BUILD_X86_64),1)
61 all: all_64
62 TEST_PROGS += $(BINARIES_64)
63 EXTRA_CFLAGS += -DCAN_BUILD_64
64 $(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t))))
65 endif
66
67 all_32: $(BINARIES_32)
68
69 all_64: $(BINARIES_64)
70
71 EXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
72
73 $(BINARIES_32): $(OUTPUT)/%_32: %.c
74         $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
75
76 $(BINARIES_64): $(OUTPUT)/%_64: %.c
77         $(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
78
79 # x86_64 users should be encouraged to install 32-bit libraries
80 ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
81 all: warn_32bit_failure
82
83 warn_32bit_failure:
84         @echo "Warning: you seem to have a broken 32-bit build" 2>&1;   \
85         echo "environment.  This will reduce test coverage of 64-bit" 2>&1; \
86         echo "kernels.  If you are using a Debian-like distribution," 2>&1; \
87         echo "try:"; 2>&1; \
88         echo "";                                                        \
89         echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
90         echo "";                                                        \
91         echo "If you are using a Fedora-like distribution, try:";       \
92         echo "";                                                        \
93         echo "  yum install glibc-devel.*i686";                         \
94         exit 0;
95 endif
96
97 # Some tests have additional dependencies.
98 $(OUTPUT)/sysret_ss_attrs_64: thunks.S
99 $(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
100 $(OUTPUT)/test_syscall_vdso_32: thunks_32.S
101
102 # check_initial_reg_state is special: it needs a custom entry, and it
103 # needs to be static so that its interpreter doesn't destroy its initial
104 # state.
105 $(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
106 $(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static