18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ciall:
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ciinclude ../lib.mk
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci.PHONY: all all_32 all_64 warn_32bit_failure clean
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ciUNAME_M := $(shell uname -m)
98c2ecf20Sopenharmony_ciCAN_BUILD_I386 := $(shell ./check_cc.sh "$(CC)" trivial_32bit_program.c -m32)
108c2ecf20Sopenharmony_ciCAN_BUILD_X86_64 := $(shell ./check_cc.sh "$(CC)" trivial_64bit_program.c)
118c2ecf20Sopenharmony_ciCAN_BUILD_WITH_NOPIE := $(shell ./check_cc.sh "$(CC)" trivial_program.c -no-pie)
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ciTARGETS_C_BOTHBITS := single_step_syscall sysret_ss_attrs syscall_nt test_mremap_vdso \
148c2ecf20Sopenharmony_ci			check_initial_reg_state sigreturn iopl ioperm \
158c2ecf20Sopenharmony_ci			test_vdso test_vsyscall mov_ss_trap \
168c2ecf20Sopenharmony_ci			syscall_arg_fault fsgsbase_restore
178c2ecf20Sopenharmony_ciTARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \
188c2ecf20Sopenharmony_ci			test_FCMOV test_FCOMI test_FISTTP \
198c2ecf20Sopenharmony_ci			vdso_restorer
208c2ecf20Sopenharmony_ciTARGETS_C_64BIT_ONLY := fsgsbase sysret_rip syscall_numbering
218c2ecf20Sopenharmony_ci# Some selftests require 32bit support enabled also on 64bit systems
228c2ecf20Sopenharmony_ciTARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciTARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED)
258c2ecf20Sopenharmony_ciTARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY)
268c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11)
278c2ecf20Sopenharmony_ciTARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED)
288c2ecf20Sopenharmony_ciendif
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ciBINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32)
318c2ecf20Sopenharmony_ciBINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64)
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ciBINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32))
348c2ecf20Sopenharmony_ciBINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64))
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciCFLAGS := -O2 -g -std=gnu99 -pthread -Wall
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci# call32_from_64 in thunks.S uses absolute addresses.
398c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_WITH_NOPIE),1)
408c2ecf20Sopenharmony_ciCFLAGS += -no-pie
418c2ecf20Sopenharmony_ciendif
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cidefine gen-target-rule-32
448c2ecf20Sopenharmony_ci$(1) $(1)_32: $(OUTPUT)/$(1)_32
458c2ecf20Sopenharmony_ci.PHONY: $(1) $(1)_32
468c2ecf20Sopenharmony_ciendef
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cidefine gen-target-rule-64
498c2ecf20Sopenharmony_ci$(1) $(1)_64: $(OUTPUT)/$(1)_64
508c2ecf20Sopenharmony_ci.PHONY: $(1) $(1)_64
518c2ecf20Sopenharmony_ciendef
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_I386),1)
548c2ecf20Sopenharmony_ciall: all_32
558c2ecf20Sopenharmony_ciTEST_PROGS += $(BINARIES_32)
568c2ecf20Sopenharmony_ciEXTRA_CFLAGS += -DCAN_BUILD_32
578c2ecf20Sopenharmony_ci$(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t))))
588c2ecf20Sopenharmony_ciendif
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_X86_64),1)
618c2ecf20Sopenharmony_ciall: all_64
628c2ecf20Sopenharmony_ciTEST_PROGS += $(BINARIES_64)
638c2ecf20Sopenharmony_ciEXTRA_CFLAGS += -DCAN_BUILD_64
648c2ecf20Sopenharmony_ci$(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t))))
658c2ecf20Sopenharmony_ciendif
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciall_32: $(BINARIES_32)
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ciall_64: $(BINARIES_64)
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ciEXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci$(BINARIES_32): $(OUTPUT)/%_32: %.c helpers.h
748c2ecf20Sopenharmony_ci	$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl -lm
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci$(BINARIES_64): $(OUTPUT)/%_64: %.c helpers.h
778c2ecf20Sopenharmony_ci	$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $^ -lrt -ldl
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci# x86_64 users should be encouraged to install 32-bit libraries
808c2ecf20Sopenharmony_ciifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01)
818c2ecf20Sopenharmony_ciall: warn_32bit_failure
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ciwarn_32bit_failure:
848c2ecf20Sopenharmony_ci	@echo "Warning: you seem to have a broken 32-bit build" 2>&1; 	\
858c2ecf20Sopenharmony_ci	echo "environment.  This will reduce test coverage of 64-bit" 2>&1; \
868c2ecf20Sopenharmony_ci	echo "kernels.  If you are using a Debian-like distribution," 2>&1; \
878c2ecf20Sopenharmony_ci	echo "try:"; 2>&1; \
888c2ecf20Sopenharmony_ci	echo "";							\
898c2ecf20Sopenharmony_ci	echo "  apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \
908c2ecf20Sopenharmony_ci	echo "";							\
918c2ecf20Sopenharmony_ci	echo "If you are using a Fedora-like distribution, try:";	\
928c2ecf20Sopenharmony_ci	echo "";							\
938c2ecf20Sopenharmony_ci	echo "  yum install glibc-devel.*i686";				\
948c2ecf20Sopenharmony_ci	exit 0;
958c2ecf20Sopenharmony_ciendif
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci# Some tests have additional dependencies.
988c2ecf20Sopenharmony_ci$(OUTPUT)/sysret_ss_attrs_64: thunks.S
998c2ecf20Sopenharmony_ci$(OUTPUT)/ptrace_syscall_32: raw_syscall_helper_32.S
1008c2ecf20Sopenharmony_ci$(OUTPUT)/test_syscall_vdso_32: thunks_32.S
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci# check_initial_reg_state is special: it needs a custom entry, and it
1038c2ecf20Sopenharmony_ci# needs to be static so that its interpreter doesn't destroy its initial
1048c2ecf20Sopenharmony_ci# state.
1058c2ecf20Sopenharmony_ci$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static
1068c2ecf20Sopenharmony_ci$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static
107