xref: /linux/tools/testing/selftests/arm64/pauth/Makefile (revision c771600c6af14749609b49565ffb4cac2959710d)
1e74e1d55SBoyan Karatotev# SPDX-License-Identifier: GPL-2.0
2e74e1d55SBoyan Karatotev# Copyright (C) 2020 ARM Limited
3e74e1d55SBoyan Karatotev
4e74e1d55SBoyan Karatotev# preserve CC value from top level Makefile
5e74e1d55SBoyan Karatotevifeq ($(CC),cc)
6e74e1d55SBoyan KaratotevCC := $(CROSS_COMPILE)gcc
7e74e1d55SBoyan Karatotevendif
8e74e1d55SBoyan Karatotev
9e74e1d55SBoyan KaratotevCFLAGS += -mbranch-protection=pac-ret
10*c297aa7dSMark Brown
11*c297aa7dSMark Brown# All supported LLVMs have PAC, test for GCC
12*c297aa7dSMark Brownifeq ($(LLVM),1)
13*c297aa7dSMark Brownpauth_cc_support := 1
14*c297aa7dSMark Brownelse
15e74e1d55SBoyan Karatotev# check if the compiler supports ARMv8.3 and branch protection with PAuth
16e74e1d55SBoyan Karatotevpauth_cc_support := $(shell if ($(CC) $(CFLAGS) -march=armv8.3-a -E -x c /dev/null -o /dev/null 2>&1) then echo "1"; fi)
17*c297aa7dSMark Brownendif
18e74e1d55SBoyan Karatotev
19e74e1d55SBoyan Karatotevifeq ($(pauth_cc_support),1)
20e74e1d55SBoyan KaratotevTEST_GEN_PROGS := pac
21766d95b1SBoyan KaratotevTEST_GEN_FILES := pac_corruptor.o helper.o
22806a15b2SBoyan KaratotevTEST_GEN_PROGS_EXTENDED := exec_target
23e74e1d55SBoyan Karatotevendif
24e74e1d55SBoyan Karatotev
25e74e1d55SBoyan Karatotevinclude ../../lib.mk
26e74e1d55SBoyan Karatotev
27e74e1d55SBoyan Karatotevifeq ($(pauth_cc_support),1)
28e74e1d55SBoyan Karatotev# pac* and aut* instructions are not available on architectures berfore
29e74e1d55SBoyan Karatotev# ARMv8.3. Therefore target ARMv8.3 wherever they are used directly
30e74e1d55SBoyan Karatotev$(OUTPUT)/pac_corruptor.o: pac_corruptor.S
31e74e1d55SBoyan Karatotev	$(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a
32e74e1d55SBoyan Karatotev
33766d95b1SBoyan Karatotev$(OUTPUT)/helper.o: helper.c
34766d95b1SBoyan Karatotev	$(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a
35766d95b1SBoyan Karatotev
36e74e1d55SBoyan Karatotev# when -mbranch-protection is enabled and the target architecture is ARMv8.3 or
37e74e1d55SBoyan Karatotev# greater, gcc emits pac* instructions which are not in HINT NOP space,
38e74e1d55SBoyan Karatotev# preventing the tests from occurring at all. Compile for ARMv8.2 so tests can
39e74e1d55SBoyan Karatotev# run on earlier targets and print a meaningful error messages
40806a15b2SBoyan Karatotev$(OUTPUT)/exec_target: exec_target.c $(OUTPUT)/helper.o
41806a15b2SBoyan Karatotev	$(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a
42806a15b2SBoyan Karatotev
43766d95b1SBoyan Karatotev$(OUTPUT)/pac: pac.c $(OUTPUT)/pac_corruptor.o $(OUTPUT)/helper.o
44e74e1d55SBoyan Karatotev	$(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a
45e74e1d55SBoyan Karatotevendif
46