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