[9/12] arm: Make libgcc bti compatible

Message ID gkrk0b9v8ql.fsf@arm.com
State Superseded
Headers
Series arm: Enables return address verification and branch target identification on Cortex-M |

Commit Message

Andrea Corallo April 28, 2022, 9:48 a.m. UTC
  This change add bti instructions at the beginning of arm specific
libgcc hand written assembly routines.

2022-03-31  Andrea Corallo  <andrea.corallo@arm.com>

	* libgcc/config/arm/crti.S (FUNC_START): Add bti instruction if
	necessary.
	* libgcc/config/arm/lib1funcs.S (THUMB_FUNC_START, FUNC_START):
	Likewise.
  

Comments

Richard Earnshaw July 1, 2022, 3:03 p.m. UTC | #1
On 28/04/2022 10:48, Andrea Corallo via Gcc-patches wrote:
> This change add bti instructions at the beginning of arm specific
> libgcc hand written assembly routines.
> 
> 2022-03-31  Andrea Corallo  <andrea.corallo@arm.com>
> 
> 	* libgcc/config/arm/crti.S (FUNC_START): Add bti instruction if
> 	necessary.
> 	* libgcc/config/arm/lib1funcs.S (THUMB_FUNC_START, FUNC_START):
> 	Likewise.
> 

+#if defined(__ARM_FEATURE_BTI)

Wouldn't it be better to use __ARM_FEATURE_BTI_DEFAULT?  That way we 
only get BTI instructions in multilib variants that have asked for BTI.

R.
  

Patch

diff --git a/libgcc/config/arm/crti.S b/libgcc/config/arm/crti.S
index 0192972a7e6..bac2d87fbb9 100644
--- a/libgcc/config/arm/crti.S
+++ b/libgcc/config/arm/crti.S
@@ -51,7 +51,9 @@ 
 .macro FUNC_START
 #ifdef __thumb__
 	.thumb
-	
+#if defined(__ARM_FEATURE_BTI)
+	bti
+#endif
 	push	{r3, r4, r5, r6, r7, lr}
 #else
 	.arm
diff --git a/libgcc/config/arm/lib1funcs.S b/libgcc/config/arm/lib1funcs.S
index 8c39c9f20a2..45dfb5da9ee 100644
--- a/libgcc/config/arm/lib1funcs.S
+++ b/libgcc/config/arm/lib1funcs.S
@@ -345,6 +345,9 @@  LSYM(Ldiv0):
 	TYPE	(\name)
 	.thumb_func
 SYM (\name):
+#if defined(__ARM_FEATURE_BTI)
+	bti
+#endif
 .endm
 
 /* Function start macros.  Variants for ARM and Thumb.  */
@@ -372,6 +375,9 @@  SYM (\name):
 	THUMB_FUNC
 	THUMB_SYNTAX
 SYM (__\name):
+#if defined(__ARM_FEATURE_BTI)
+	bti
+#endif
 .endm
 
 .macro ARM_SYM_START name