Skip to content

Commit 35b5fb3

Browse files
wearyzennashif
authored andcommitted
arch: arm: cortex_m: Add support for PACBTI flags
Introduce a Kconfig choice to select Pointer Authentication and Branch Target Identification (PACBTI) features on Armv8.1-M Mainline CPUs. The available options map to supported `-mbranch-protection` levels (`standard`, `pac-ret`, `bti`, and combinations) documented at https://gcc.gnu.org/onlinedocs/gcc/ARM-Options.html These options enable hardware-assisted control-flow integrity mechanisms on targets like Cortex-M85, and require a toolchain with PACBTI support, such as GCC 14.2 or newer. Signed-off-by: Sudan Landge <sudan.landge@arm.com>
1 parent e7dd7ab commit 35b5fb3

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

arch/arm/core/cortex_m/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
zephyr_library()
44

5+
if(CONFIG_ARMV8_1_M_PACBTI_STANDARD)
6+
zephyr_compile_options(-mbranch-protection=standard)
7+
elseif(CONFIG_ARMV8_1_M_PACBTI_PACRET)
8+
zephyr_compile_options(-mbranch-protection=pac-ret)
9+
elseif(CONFIG_ARMV8_1_M_PACBTI_PACRET_LEAF)
10+
zephyr_compile_options(-mbranch-protection=pac-ret+leaf)
11+
elseif(CONFIG_ARMV8_1_M_PACBTI_BTI)
12+
zephyr_compile_options(-mbranch-protection=bti)
13+
elseif(CONFIG_ARMV8_1_M_PACBTI_PACRET_BTI)
14+
zephyr_compile_options(-mbranch-protection=pac-ret+bti)
15+
elseif(CONFIG_ARMV8_1_M_PACBTI_PACRET_LEAF_BTI)
16+
zephyr_compile_options(-mbranch-protection=pac-ret+leaf+bti)
17+
elseif(CONFIG_ARMV8_1_M_PACBTI_NONE)
18+
#TODO: Enable this after Zephyr SDK updates to GCC version >=14.2
19+
# zephyr_compile_options(-mbranch-protection=none)
20+
endif()
21+
522
zephyr_library_sources(
623
exc_exit.c
724
fault.c

arch/arm/core/cortex_m/Kconfig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ARM Cortex-M platform configuration options
22

33
# Copyright (c) 2014-2015 Wind River Systems, Inc.
4+
# Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
45
# SPDX-License-Identifier: Apache-2.0
56

67
# NOTE: We have the specific core implementations first and outside of the
@@ -298,6 +299,60 @@ config ARMV8_1_M_PMU
298299
This option is enabled when the CPU implements ARMv8-M Performance
299300
Monitoring Unit (PMU).
300301

302+
choice ARMV8_1_M_PACBTI
303+
prompt "Pointer Authentication and Branch Target Identification"
304+
default ARMV8_1_M_PACBTI_NONE
305+
depends on ARMV8_1_M_MAINLINE
306+
307+
config ARMV8_1_M_PACBTI_STANDARD
308+
bool "Standard (PACRET + LEAF + BTI)"
309+
help
310+
This option instructs the compiler to generate code with all branch protection features
311+
enabled at their standard level.
312+
313+
config ARMV8_1_M_PACBTI_PACRET
314+
bool "PACRET only"
315+
help
316+
This option instructs the compiler to generate code with return address signing for
317+
all functions that save the return address to memory.
318+
319+
config ARMV8_1_M_PACBTI_PACRET_LEAF
320+
bool "PACRET + Leaf"
321+
help
322+
This option instructs the compiler to generate code with return address signing for
323+
all functions that save the return address to memory and,
324+
also sign leaf functions even if they do not write the return address to memory.
325+
326+
config ARMV8_1_M_PACBTI_BTI
327+
bool "BTI only"
328+
help
329+
This option enables Branch Target Identification (BTI), which inserts special landing
330+
pad instructions at valid indirect branch targets. This option does not enable Pointer
331+
Authentication (PAC).
332+
333+
config ARMV8_1_M_PACBTI_PACRET_BTI
334+
bool "PACRET + BTI"
335+
help
336+
This option instructs the compiler to generate code with return address signing for
337+
all functions that save the return address to memory and,
338+
add landing-pad instructions at the permitted targets of indirect branch instructions
339+
340+
config ARMV8_1_M_PACBTI_PACRET_LEAF_BTI
341+
bool "PACRET + Leaf + BTI"
342+
help
343+
This option instructs the compiler to generate code with return address signing for
344+
all functions that save the return address to memory and,
345+
also sign leaf functions even if they do not write the return address to memory and,
346+
add landing-pad instructions at the permitted targets of indirect branch instructions
347+
348+
config ARMV8_1_M_PACBTI_NONE
349+
bool "None"
350+
help
351+
This option instructs the compiler to generate code without branch protection or return
352+
address signing
353+
354+
endchoice
355+
301356
config ARMV8_M_PMU_EVENTCNT
302357
int "Number of event counters in the Performance Monitoring Unit"
303358
depends on ARMV8_1_M_PMU

0 commit comments

Comments
 (0)