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