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 10e74e1d55SBoyan Karatotev# check if the compiler supports ARMv8.3 and branch protection with PAuth 11e74e1d55SBoyan 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) 12e74e1d55SBoyan Karatotev 13e74e1d55SBoyan Karatotevifeq ($(pauth_cc_support),1) 14e74e1d55SBoyan KaratotevTEST_GEN_PROGS := pac 15766d95b1SBoyan KaratotevTEST_GEN_FILES := pac_corruptor.o helper.o 16*806a15b2SBoyan KaratotevTEST_GEN_PROGS_EXTENDED := exec_target 17e74e1d55SBoyan Karatotevendif 18e74e1d55SBoyan Karatotev 19e74e1d55SBoyan Karatotevinclude ../../lib.mk 20e74e1d55SBoyan Karatotev 21e74e1d55SBoyan Karatotevifeq ($(pauth_cc_support),1) 22e74e1d55SBoyan Karatotev# pac* and aut* instructions are not available on architectures berfore 23e74e1d55SBoyan Karatotev# ARMv8.3. Therefore target ARMv8.3 wherever they are used directly 24e74e1d55SBoyan Karatotev$(OUTPUT)/pac_corruptor.o: pac_corruptor.S 25e74e1d55SBoyan Karatotev $(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a 26e74e1d55SBoyan Karatotev 27766d95b1SBoyan Karatotev$(OUTPUT)/helper.o: helper.c 28766d95b1SBoyan Karatotev $(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a 29766d95b1SBoyan Karatotev 30e74e1d55SBoyan Karatotev# when -mbranch-protection is enabled and the target architecture is ARMv8.3 or 31e74e1d55SBoyan Karatotev# greater, gcc emits pac* instructions which are not in HINT NOP space, 32e74e1d55SBoyan Karatotev# preventing the tests from occurring at all. Compile for ARMv8.2 so tests can 33e74e1d55SBoyan Karatotev# run on earlier targets and print a meaningful error messages 34*806a15b2SBoyan Karatotev$(OUTPUT)/exec_target: exec_target.c $(OUTPUT)/helper.o 35*806a15b2SBoyan Karatotev $(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a 36*806a15b2SBoyan Karatotev 37766d95b1SBoyan Karatotev$(OUTPUT)/pac: pac.c $(OUTPUT)/pac_corruptor.o $(OUTPUT)/helper.o 38e74e1d55SBoyan Karatotev $(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a 39e74e1d55SBoyan Karatotevendif 40