1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 2e9886aceSAndy Lutomirskiall: 3e9886aceSAndy Lutomirski 4e9886aceSAndy Lutomirskiinclude ../lib.mk 5e9886aceSAndy Lutomirski 6e9886aceSAndy Lutomirski.PHONY: all all_32 all_64 warn_32bit_failure clean 73f705dfdSAndy Lutomirski 89279ddf2SDominik BrodowskiUNAME_M := $(shell uname -m) 99279ddf2SDominik BrodowskiCAN_BUILD_I386 := $(shell ./check_cc.sh $(CC) trivial_32bit_program.c -m32) 109279ddf2SDominik BrodowskiCAN_BUILD_X86_64 := $(shell ./check_cc.sh $(CC) trivial_64bit_program.c) 110dd3a694SFlorian WeimerCAN_BUILD_WITH_NOPIE := $(shell ./check_cc.sh $(CC) trivial_program.c -no-pie) 129279ddf2SDominik Brodowski 139279ddf2SDominik BrodowskiTARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \ 1448febc03SDave Hansen check_initial_reg_state sigreturn iopl ioperm \ 15c7e5789bSVincenzo Frascino test_vsyscall mov_ss_trap \ 168919f072SChang S. Bae syscall_arg_fault fsgsbase_restore sigaltstack 179402eaf4SAndy LutomirskiTARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \ 180f672809SAndy Lutomirski test_FCMOV test_FCOMI test_FISTTP \ 1965cacec1SAndy Lutomirski vdso_restorer 20*b7c11876SAndy LutomirskiTARGETS_C_64BIT_ONLY := fsgsbase sysret_rip syscall_numbering \ 21*b7c11876SAndy Lutomirski corrupt_xstate_header 229279ddf2SDominik Brodowski# Some selftests require 32bit support enabled also on 64bit systems 239279ddf2SDominik BrodowskiTARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall 243f705dfdSAndy Lutomirski 259279ddf2SDominik BrodowskiTARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED) 26c31b3425SAndy LutomirskiTARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY) 279279ddf2SDominik Brodowskiifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11) 289279ddf2SDominik BrodowskiTARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED) 299279ddf2SDominik Brodowskiendif 309279ddf2SDominik Brodowski 31c2affbf9SAndy LutomirskiBINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32) 32c31b3425SAndy LutomirskiBINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64) 333f705dfdSAndy Lutomirski 34a8ba798bSbamvor.zhangjian@huawei.comBINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) 35a8ba798bSbamvor.zhangjian@huawei.comBINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) 36a8ba798bSbamvor.zhangjian@huawei.com 370dd3a694SFlorian WeimerCFLAGS := -O2 -g -std=gnu99 -pthread -Wall 380dd3a694SFlorian Weimer 390dd3a694SFlorian Weimer# call32_from_64 in thunks.S uses absolute addresses. 400dd3a694SFlorian Weimerifeq ($(CAN_BUILD_WITH_NOPIE),1) 410dd3a694SFlorian WeimerCFLAGS += -no-pie 420dd3a694SFlorian Weimerendif 433f705dfdSAndy Lutomirski 44cc08d1b9SDmitry Safonovdefine gen-target-rule-32 45cc08d1b9SDmitry Safonov$(1) $(1)_32: $(OUTPUT)/$(1)_32 46cc08d1b9SDmitry Safonov.PHONY: $(1) $(1)_32 47cc08d1b9SDmitry Safonovendef 48cc08d1b9SDmitry Safonov 49cc08d1b9SDmitry Safonovdefine gen-target-rule-64 50cc08d1b9SDmitry Safonov$(1) $(1)_64: $(OUTPUT)/$(1)_64 51cc08d1b9SDmitry Safonov.PHONY: $(1) $(1)_64 52cc08d1b9SDmitry Safonovendef 53cc08d1b9SDmitry Safonov 54e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_I386),1) 553f705dfdSAndy Lutomirskiall: all_32 56c1e6e5cbSAndy LutomirskiTEST_PROGS += $(BINARIES_32) 574105c697SDominik BrodowskiEXTRA_CFLAGS += -DCAN_BUILD_32 58cc08d1b9SDmitry Safonov$(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t)))) 59e9886aceSAndy Lutomirskiendif 60e9886aceSAndy Lutomirski 61e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_X86_64),1) 623f705dfdSAndy Lutomirskiall: all_64 6307620abeSTyler BakerTEST_PROGS += $(BINARIES_64) 644105c697SDominik BrodowskiEXTRA_CFLAGS += -DCAN_BUILD_64 65cc08d1b9SDmitry Safonov$(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t)))) 663f705dfdSAndy Lutomirskiendif 673f705dfdSAndy Lutomirski 68e9886aceSAndy Lutomirskiall_32: $(BINARIES_32) 693f705dfdSAndy Lutomirski 703f705dfdSAndy Lutomirskiall_64: $(BINARIES_64) 713f705dfdSAndy Lutomirski 72eebed11aSShuah KhanEXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64) 733f705dfdSAndy Lutomirski 74cced0b24SAndy Lutomirski$(BINARIES_32): $(OUTPUT)/%_32: %.c helpers.h 7557ca6897SDenys Vlasenko $(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm 763f705dfdSAndy Lutomirski 77cced0b24SAndy Lutomirski$(BINARIES_64): $(OUTPUT)/%_64: %.c helpers.h 783f705dfdSAndy Lutomirski $(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl 793f705dfdSAndy Lutomirski 80e9886aceSAndy Lutomirski# x86_64 users should be encouraged to install 32-bit libraries 81e9886aceSAndy Lutomirskiifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) 82e9886aceSAndy Lutomirskiall: warn_32bit_failure 83e9886aceSAndy Lutomirski 84e9886aceSAndy Lutomirskiwarn_32bit_failure: 85e9886aceSAndy Lutomirski @echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ 86e9886aceSAndy Lutomirski echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ 87e9886aceSAndy Lutomirski echo "kernels. If you are using a Debian-like distribution," 2>&1; \ 88e9886aceSAndy Lutomirski echo "try:"; 2>&1; \ 893f705dfdSAndy Lutomirski echo ""; \ 903f705dfdSAndy Lutomirski echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ 913f705dfdSAndy Lutomirski echo ""; \ 923f705dfdSAndy Lutomirski echo "If you are using a Fedora-like distribution, try:"; \ 933f705dfdSAndy Lutomirski echo ""; \ 943f705dfdSAndy Lutomirski echo " yum install glibc-devel.*i686"; \ 95e9886aceSAndy Lutomirski exit 0; 96e9886aceSAndy Lutomirskiendif 97e22438f8SAndy Lutomirski 98e22438f8SAndy Lutomirski# Some tests have additional dependencies. 99a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/sysret_ss_attrs_64: thunks.S 100a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S 101a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/test_syscall_vdso_32: thunks_32.S 102e21d50f3SAndy Lutomirski 103e21d50f3SAndy Lutomirski# check_initial_reg_state is special: it needs a custom entry, and it 104e21d50f3SAndy Lutomirski# needs to be static so that its interpreter doesn't destroy its initial 105e21d50f3SAndy Lutomirski# state. 106a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static 107a8ba798bSbamvor.zhangjian@huawei.com$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static 108