| 1 |
# SPDX-License-Identifier: GPL-2.0 |
| 2 |
# Copyright (C) 2020 ARM Limited |
| 3 |
|
| 4 |
# preserve CC value from top level Makefile |
| 5 |
ifeq ($(CC),cc) |
| 6 |
CC := $(CROSS_COMPILE)gcc |
| 7 |
endif |
| 8 |
|
| 9 |
CFLAGS += -mbranch-protection=pac-ret |
| 10 |
|
| 11 |
# All supported LLVMs have PAC, test for GCC |
| 12 |
ifeq ($(LLVM),1) |
| 13 |
pauth_cc_support := 1 |
| 14 |
else |
| 15 |
# check if the compiler supports ARMv8.3 and branch protection with PAuth |
| 16 |
pauth_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 |
endif |
| 18 |
|
| 19 |
ifeq ($(pauth_cc_support),1) |
| 20 |
TEST_GEN_PROGS := pac |
| 21 |
TEST_GEN_FILES := pac_corruptor.o helper.o |
| 22 |
TEST_GEN_PROGS_EXTENDED := exec_target |
| 23 |
endif |
| 24 |
|
| 25 |
include ../../lib.mk |
| 26 |
|
| 27 |
ifeq ($(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 |
| 45 |
endif |