18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci# Copyright (C) 2020 ARM Limited 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci# preserve CC value from top level Makefile 58c2ecf20Sopenharmony_ciifeq ($(CC),cc) 68c2ecf20Sopenharmony_ciCC := $(CROSS_COMPILE)gcc 78c2ecf20Sopenharmony_ciendif 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciCFLAGS += -mbranch-protection=pac-ret 108c2ecf20Sopenharmony_ci# check if the compiler supports ARMv8.3 and branch protection with PAuth 118c2ecf20Sopenharmony_cipauth_cc_support := $(shell if ($(CC) $(CFLAGS) -march=armv8.3-a -E -x c /dev/null -o /dev/null 2>&1) then echo "1"; fi) 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciifeq ($(pauth_cc_support),1) 148c2ecf20Sopenharmony_ciTEST_GEN_PROGS := pac 158c2ecf20Sopenharmony_ciTEST_GEN_FILES := pac_corruptor.o helper.o 168c2ecf20Sopenharmony_ciTEST_GEN_PROGS_EXTENDED := exec_target 178c2ecf20Sopenharmony_ciendif 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ciinclude ../../lib.mk 208c2ecf20Sopenharmony_ci 218c2ecf20Sopenharmony_ciifeq ($(pauth_cc_support),1) 228c2ecf20Sopenharmony_ci# pac* and aut* instructions are not available on architectures berfore 238c2ecf20Sopenharmony_ci# ARMv8.3. Therefore target ARMv8.3 wherever they are used directly 248c2ecf20Sopenharmony_ci$(OUTPUT)/pac_corruptor.o: pac_corruptor.S 258c2ecf20Sopenharmony_ci $(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci$(OUTPUT)/helper.o: helper.c 288c2ecf20Sopenharmony_ci $(CC) -c $^ -o $@ $(CFLAGS) -march=armv8.3-a 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci# when -mbranch-protection is enabled and the target architecture is ARMv8.3 or 318c2ecf20Sopenharmony_ci# greater, gcc emits pac* instructions which are not in HINT NOP space, 328c2ecf20Sopenharmony_ci# preventing the tests from occurring at all. Compile for ARMv8.2 so tests can 338c2ecf20Sopenharmony_ci# run on earlier targets and print a meaningful error messages 348c2ecf20Sopenharmony_ci$(OUTPUT)/exec_target: exec_target.c $(OUTPUT)/helper.o 358c2ecf20Sopenharmony_ci $(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci$(OUTPUT)/pac: pac.c $(OUTPUT)/pac_corruptor.o $(OUTPUT)/helper.o 388c2ecf20Sopenharmony_ci $(CC) $^ -o $@ $(CFLAGS) -march=armv8.2-a 398c2ecf20Sopenharmony_ciendif 40