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