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