Generate BTI GNU note for TS assembly files
Add GNU note after compiling assembly files to
avoid having warning.
Signed-off-by: Gabor Toth <gabor.toth2@arm.com>
Change-Id: I9c293826ec0d0a3ad7df5d19eab80e1d0d8069ae
diff --git a/components/common/utils/include/asm.S b/components/common/utils/include/asm.S
index d3cecc3..9ed065f 100644
--- a/components/common/utils/include/asm.S
+++ b/components/common/utils/include/asm.S
@@ -1,8 +1,17 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2014, STMicroelectronics International N.V.
*/
+#if defined(BTI_ENABLED)
+#include <arm64_bti.S>
+
+#define BTI(...) __VA_ARGS__
+#else
+#define BTI(...)
+#endif
+
.macro FUNC name colon section=default
.ifc \section\(),default
.section .text.\name
@@ -13,6 +22,7 @@
.type \name , %function
.balign 4
\name \colon
+ BTI(bti c)
.endm
.macro DATA name colon
@@ -30,6 +40,7 @@
.type \name , %function
.balign 4
\name \colon
+ BTI(bti c)
.endm
.macro LOCAL_DATA name colon
diff --git a/components/common/utils/include/elf_common.h b/components/common/utils/include/elf_common.h
index 9c67b9d..a2bf375 100644
--- a/components/common/utils/include/elf_common.h
+++ b/components/common/utils/include/elf_common.h
@@ -1,5 +1,6 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*-
+ * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
* Copyright (c) 2000, 2001, 2008, 2011, David E. O'Brien
* Copyright (c) 1998 John D. Polstra.
* All rights reserved.
@@ -31,13 +32,14 @@
#ifndef _SYS_ELF_COMMON_H_
#define _SYS_ELF_COMMON_H_ 1
-#include <stdint.h>
-
/*
* ELF definitions that are independent of architecture or word size.
*/
#ifndef __ASSEMBLER__
+
+#include <stdint.h>
+
/*
* Note header. The ".note" section contains an array of notes. Each
* begins with this header, aligned to a word boundary. Immediately
diff --git a/components/messaging/ffa/libsp/aarch64/ffa_syscalls_a64.S b/components/messaging/ffa/libsp/aarch64/ffa_syscalls_a64.S
index 6ffeb0b..d883ecb 100644
--- a/components/messaging/ffa/libsp/aarch64/ffa_syscalls_a64.S
+++ b/components/messaging/ffa/libsp/aarch64/ffa_syscalls_a64.S
@@ -25,3 +25,5 @@
stp x6, x7, [x8, #48]
ret
END_FUNC ffa_svc
+
+BTI(emit_aarch64_feature_1_and GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
diff --git a/environments/opteesp/default_toolchain_file.cmake b/environments/opteesp/default_toolchain_file.cmake
index 00ddf89..613cd43 100644
--- a/environments/opteesp/default_toolchain_file.cmake
+++ b/environments/opteesp/default_toolchain_file.cmake
@@ -34,6 +34,7 @@
# flag, and to turn on the BTI flag in the output anyway.
set(TS_MANDATORY_AARCH_FLAGS "${TS_MANDATORY_AARCH_FLAGS} -mbranch-protection=bti")
set(TS_MANDATORY_LINKER_FLAGS "${TS_MANDATORY_LINKER_FLAGS} -zforce-bti")
+ add_compile_definitions("BTI_ENABLED")
elseif(BTI_ENABLED STREQUAL "OFF")
set(TS_MANDATORY_AARCH_FLAGS "${TS_MANDATORY_AARCH_FLAGS} -mbranch-protection=none")
endif()
diff --git a/environments/sp/default_toolchain_file.cmake b/environments/sp/default_toolchain_file.cmake
index b2c4bb1..f0945f1 100644
--- a/environments/sp/default_toolchain_file.cmake
+++ b/environments/sp/default_toolchain_file.cmake
@@ -33,6 +33,7 @@
# flag, and to turn on the BTI flag in the output anyway.
set(TS_MANDATORY_AARCH_FLAGS "${TS_MANDATORY_AARCH_FLAGS} -mbranch-protection=bti")
set(TS_MANDATORY_LINKER_FLAGS "${TS_MANDATORY_LINKER_FLAGS} -zforce-bti")
+ add_compile_definitions("BTI_ENABLED")
elseif(BTI_ENABLED STREQUAL "OFF")
set(TS_MANDATORY_AARCH_FLAGS "${TS_MANDATORY_AARCH_FLAGS} -mbranch-protection=none")
endif()
diff --git a/environments/sp/entry.S b/environments/sp/entry.S
index 29c61c3..ab6c0af 100644
--- a/environments/sp/entry.S
+++ b/environments/sp/entry.S
@@ -83,3 +83,5 @@
.asciz "Only R_AARCH64_RELATIVE type relocation is supported"
.align 8
END_FUNC __sp_entry
+
+BTI(emit_aarch64_feature_1_and GNU_PROPERTY_AARCH64_FEATURE_1_BTI)