1*e74e1d55SBoyan Karatotev# SPDX-License-Identifier: GPL-2.0 2*e74e1d55SBoyan Karatotev# Copyright (C) 2020 ARM Limited 3*e74e1d55SBoyan Karatotev 4*e74e1d55SBoyan Karatotev# preserve CC value from top level Makefile 5*e74e1d55SBoyan Karatotevifeq ($(CC),cc) 6*e74e1d55SBoyan KaratotevCC := $(CROSS_COMPILE)gcc 7*e74e1d55SBoyan Karatotevendif 8*e74e1d55SBoyan Karatotev 9*e74e1d55SBoyan KaratotevCFLAGS += -mbranch-protection=pac-ret 10*e74e1d55SBoyan Karatotev# check if the compiler supports ARMv8.3 and branch protection with PAuth 11*e74e1d55SBoyan 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) 12*e74e1d55SBoyan Karatotev 13*e74e1d55SBoyan Karatotevifeq ($(pauth_cc_support),1) 14*e74e1d55SBoyan KaratotevTEST_GEN_PROGS := pac 15*e74e1d55SBoyan KaratotevTEST_GEN_FILES := pac_corruptor.o 16*e74e1d55SBoyan Karatotevendif 17*e74e1d55SBoyan Karatotev 18*e74e1d55SBoyan Karatotevinclude ../../lib.mk 19*e74e1d55SBoyan Karatotev 20*e74e1d55SBoyan Karatotevifeq ($(pauth_cc_support),1) 21*e74e1d55SBoyan Karatotev# pac* and aut* instructions are not available on architectures berfore 22*e74e1d55SBoyan Karatotev# ARMv8.3. Therefore target ARMv8.3 wherever they are used directly 23*e74e1d55SBoyan Karatotev$(OUTPUT)/pac_corruptor.o: pac_corruptor.S 24*e74e1d55SBoyan Karatotev $(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a 25*e74e1d55SBoyan Karatotev 26*e74e1d55SBoyan Karatotev# when -mbranch-protection is enabled and the target architecture is ARMv8.3 or 27*e74e1d55SBoyan Karatotev# greater, gcc emits pac* instructions which are not in HINT NOP space, 28*e74e1d55SBoyan Karatotev# preventing the tests from occurring at all. Compile for ARMv8.2 so tests can 29*e74e1d55SBoyan Karatotev# run on earlier targets and print a meaningful error messages 30*e74e1d55SBoyan Karatotev$(OUTPUT)/pac: pac.c $(OUTPUT)/pac_corruptor.o 31*e74e1d55SBoyan Karatotev $(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a 32*e74e1d55SBoyan Karatotevendif 33