xref: /OK3568_Linux_fs/kernel/tools/testing/selftests/arm64/pauth/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun# Copyright (C) 2020 ARM Limited
3*4882a593Smuzhiyun
4*4882a593Smuzhiyun# preserve CC value from top level Makefile
5*4882a593Smuzhiyunifeq ($(CC),cc)
6*4882a593SmuzhiyunCC := $(CROSS_COMPILE)gcc
7*4882a593Smuzhiyunendif
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunCFLAGS += -mbranch-protection=pac-ret
10*4882a593Smuzhiyun# check if the compiler supports ARMv8.3 and branch protection with PAuth
11*4882a593Smuzhiyunpauth_cc_support := $(shell if ($(CC) $(CFLAGS) -march=armv8.3-a -E -x c /dev/null -o /dev/null 2>&1) then echo "1"; fi)
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunifeq ($(pauth_cc_support),1)
14*4882a593SmuzhiyunTEST_GEN_PROGS := pac
15*4882a593SmuzhiyunTEST_GEN_FILES := pac_corruptor.o helper.o
16*4882a593SmuzhiyunTEST_GEN_PROGS_EXTENDED := exec_target
17*4882a593Smuzhiyunendif
18*4882a593Smuzhiyun
19*4882a593Smuzhiyuninclude ../../lib.mk
20*4882a593Smuzhiyun
21*4882a593Smuzhiyunifeq ($(pauth_cc_support),1)
22*4882a593Smuzhiyun# pac* and aut* instructions are not available on architectures berfore
23*4882a593Smuzhiyun# ARMv8.3. Therefore target ARMv8.3 wherever they are used directly
24*4882a593Smuzhiyun$(OUTPUT)/pac_corruptor.o: pac_corruptor.S
25*4882a593Smuzhiyun	$(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun$(OUTPUT)/helper.o: helper.c
28*4882a593Smuzhiyun	$(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun# when -mbranch-protection is enabled and the target architecture is ARMv8.3 or
31*4882a593Smuzhiyun# greater, gcc emits pac* instructions which are not in HINT NOP space,
32*4882a593Smuzhiyun# preventing the tests from occurring at all. Compile for ARMv8.2 so tests can
33*4882a593Smuzhiyun# run on earlier targets and print a meaningful error messages
34*4882a593Smuzhiyun$(OUTPUT)/exec_target: exec_target.c $(OUTPUT)/helper.o
35*4882a593Smuzhiyun	$(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun$(OUTPUT)/pac: pac.c $(OUTPUT)/pac_corruptor.o $(OUTPUT)/helper.o
38*4882a593Smuzhiyun	$(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a
39*4882a593Smuzhiyunendif
40