| 1 |
# SPDX-License-Identifier: GPL-2.0 |
| 2 |
all: |
| 3 |
|
| 4 |
include ../lib.mk |
| 5 |
|
| 6 |
.PHONY: all all_32 all_64 warn_32bit_failure clean |
| 7 |
|
| 8 |
UNAME_M := $(shell uname -m) |
| 9 |
CAN_BUILD_I386 := $(shell ./check_cc.sh "$(CC)" trivial_32bit_program.c -m32) |
| 10 |
CAN_BUILD_X86_64 := $(shell ./check_cc.sh "$(CC)" trivial_64bit_program.c) |
| 11 |
CAN_BUILD_WITH_NOPIE := $(shell ./check_cc.sh "$(CC)" trivial_program.c -no-pie) |
| 12 |
|
| 13 |
TARGETS_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 sigtrap_loop \ |
| 16 |
syscall_arg_fault fsgsbase_restore sigaltstack |
| 17 |
TARGETS_C_BOTHBITS += nx_stack |
| 18 |
TARGETS_C_32BIT_ONLY := entry_from_vm86 test_syscall_vdso unwind_vdso \ |
| 19 |
test_FCMOV test_FCOMI test_FISTTP \ |
| 20 |
vdso_restorer |
| 21 |
TARGETS_C_64BIT_ONLY := fsgsbase sysret_rip syscall_numbering \ |
| 22 |
corrupt_xstate_header amx lam test_shadow_stack avx apx |
| 23 |
# Some selftests require 32bit support enabled also on 64bit systems |
| 24 |
TARGETS_C_32BIT_NEEDED := ldt_gdt ptrace_syscall |
| 25 |
|
| 26 |
TARGETS_C_32BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_32BIT_ONLY) $(TARGETS_C_32BIT_NEEDED) |
| 27 |
TARGETS_C_64BIT_ALL := $(TARGETS_C_BOTHBITS) $(TARGETS_C_64BIT_ONLY) |
| 28 |
ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),11) |
| 29 |
TARGETS_C_64BIT_ALL += $(TARGETS_C_32BIT_NEEDED) |
| 30 |
endif |
| 31 |
|
| 32 |
BINARIES_32 := $(TARGETS_C_32BIT_ALL:%=%_32) |
| 33 |
BINARIES_64 := $(TARGETS_C_64BIT_ALL:%=%_64) |
| 34 |
|
| 35 |
BINARIES_32 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_32)) |
| 36 |
BINARIES_64 := $(patsubst %,$(OUTPUT)/%,$(BINARIES_64)) |
| 37 |
|
| 38 |
CFLAGS := -O2 -g -std=gnu99 -pthread -Wall $(KHDR_INCLUDES) |
| 39 |
CFLAGS += -I $(top_srcdir)/tools/testing/selftests/ |
| 40 |
|
| 41 |
# call32_from_64 in thunks.S uses absolute addresses. |
| 42 |
ifeq ($(CAN_BUILD_WITH_NOPIE),1) |
| 43 |
CFLAGS += -no-pie |
| 44 |
|
| 45 |
ifneq ($(LLVM),) |
| 46 |
# clang only wants to see -no-pie during linking. Here, we don't have a separate |
| 47 |
# linking stage, so a compiler warning is unavoidable without (wastefully) |
| 48 |
# restructuring the Makefile. Avoid this by simply disabling that warning. |
| 49 |
CFLAGS += -Wno-unused-command-line-argument |
| 50 |
endif |
| 51 |
endif |
| 52 |
|
| 53 |
define gen-target-rule-32 |
| 54 |
$(1) $(1)_32: $(OUTPUT)/$(1)_32 |
| 55 |
.PHONY: $(1) $(1)_32 |
| 56 |
endef |
| 57 |
|
| 58 |
define gen-target-rule-64 |
| 59 |
$(1) $(1)_64: $(OUTPUT)/$(1)_64 |
| 60 |
.PHONY: $(1) $(1)_64 |
| 61 |
endef |
| 62 |
|
| 63 |
ifeq ($(CAN_BUILD_I386),1) |
| 64 |
all: all_32 |
| 65 |
TEST_PROGS += $(BINARIES_32) |
| 66 |
EXTRA_CFLAGS += -DCAN_BUILD_32 |
| 67 |
$(foreach t,$(TARGETS_C_32BIT_ALL),$(eval $(call gen-target-rule-32,$(t)))) |
| 68 |
endif |
| 69 |
|
| 70 |
ifeq ($(CAN_BUILD_X86_64),1) |
| 71 |
all: all_64 |
| 72 |
TEST_PROGS += $(BINARIES_64) |
| 73 |
EXTRA_CFLAGS += -DCAN_BUILD_64 |
| 74 |
$(foreach t,$(TARGETS_C_64BIT_ALL),$(eval $(call gen-target-rule-64,$(t)))) |
| 75 |
endif |
| 76 |
|
| 77 |
all_32: $(BINARIES_32) |
| 78 |
|
| 79 |
all_64: $(BINARIES_64) |
| 80 |
|
| 81 |
EXTRA_CLEAN := $(BINARIES_32) $(BINARIES_64) srso |
| 82 |
|
| 83 |
$(BINARIES_32): $(OUTPUT)/%_32: %.c helpers.h |
| 84 |
$(CC) -m32 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $< $(EXTRA_FILES) -lrt -ldl -lm |
| 85 |
|
| 86 |
$(BINARIES_64): $(OUTPUT)/%_64: %.c helpers.h |
| 87 |
$(CC) -m64 -o $@ $(CFLAGS) $(EXTRA_CFLAGS) $< $(EXTRA_FILES) -lrt -ldl |
| 88 |
|
| 89 |
# x86_64 users should be encouraged to install 32-bit libraries |
| 90 |
ifeq ($(CAN_BUILD_I386)$(CAN_BUILD_X86_64),01) |
| 91 |
all: warn_32bit_failure |
| 92 |
|
| 93 |
warn_32bit_failure: |
| 94 |
@echo "Warning: you seem to have a broken 32-bit build" 2>&1; \ |
| 95 |
echo "environment. This will reduce test coverage of 64-bit" 2>&1; \ |
| 96 |
echo "kernels. If you are using a Debian-like distribution," 2>&1; \ |
| 97 |
echo "try:"; 2>&1; \ |
| 98 |
echo ""; \ |
| 99 |
echo " apt-get install gcc-multilib libc6-i386 libc6-dev-i386"; \ |
| 100 |
echo ""; \ |
| 101 |
echo "If you are using a Fedora-like distribution, try:"; \ |
| 102 |
echo ""; \ |
| 103 |
echo " yum install glibc-devel.*i686"; \ |
| 104 |
echo ""; \ |
| 105 |
echo "If you are using a SUSE-like distribution, try:"; \ |
| 106 |
echo ""; \ |
| 107 |
echo " zypper install gcc-32bit glibc-devel-static-32bit"; \ |
| 108 |
exit 0; |
| 109 |
endif |
| 110 |
|
| 111 |
# Add an additional file to the source file list for a given target, and also |
| 112 |
# add a Makefile dependency on that same file. However, do these separately, so |
| 113 |
# that the compiler invocation ("$(CC) file1.c file2.S") is not combined with |
| 114 |
# the dependencies ("header3.h"), because clang, unlike gcc, will not accept |
| 115 |
# header files as an input to the compiler invocation. |
| 116 |
define extra-files |
| 117 |
$(OUTPUT)/$(1): EXTRA_FILES := $(2) |
| 118 |
$(OUTPUT)/$(1): $(2) |
| 119 |
endef |
| 120 |
|
| 121 |
$(eval $(call extra-files,sysret_ss_attrs_64,thunks.S)) |
| 122 |
$(eval $(call extra-files,ptrace_syscall_32,raw_syscall_helper_32.S)) |
| 123 |
$(eval $(call extra-files,test_syscall_vdso_32,thunks_32.S)) |
| 124 |
$(eval $(call extra-files,fsgsbase_restore_64,clang_helpers_64.S)) |
| 125 |
$(eval $(call extra-files,fsgsbase_restore_32,clang_helpers_32.S)) |
| 126 |
$(eval $(call extra-files,sysret_rip_64,clang_helpers_64.S)) |
| 127 |
|
| 128 |
# check_initial_reg_state is special: it needs a custom entry, and it |
| 129 |
# needs to be static so that its interpreter doesn't destroy its initial |
| 130 |
# state. |
| 131 |
$(OUTPUT)/check_initial_reg_state_32: CFLAGS += -Wl,-ereal_start -static |
| 132 |
$(OUTPUT)/check_initial_reg_state_64: CFLAGS += -Wl,-ereal_start -static |
| 133 |
|
| 134 |
$(OUTPUT)/nx_stack_32: CFLAGS += -Wl,-z,noexecstack |
| 135 |
$(OUTPUT)/nx_stack_64: CFLAGS += -Wl,-z,noexecstack |
| 136 |
|
| 137 |
$(OUTPUT)/avx_64: CFLAGS += -mno-avx -mno-avx512f |
| 138 |
$(OUTPUT)/amx_64: EXTRA_FILES += xstate.c |
| 139 |
$(OUTPUT)/avx_64: EXTRA_FILES += xstate.c |
| 140 |
$(OUTPUT)/apx_64: EXTRA_FILES += xstate.c |