git: fd5aaf2ea017 - main - libc: Teach libc about the BTI elf note

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Tue, 21 Nov 2023 11:17:20 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=fd5aaf2ea0178b03aa93c35245053247e5d3840c

commit fd5aaf2ea0178b03aa93c35245053247e5d3840c
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2023-10-12 14:22:18 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2023-11-21 10:02:51 +0000

    libc: Teach libc about the BTI elf note
    
    Add the Branch Target Identification (BTI) note to libc assembly
    sources. As all obect files need the note for the library to have it
    we need to insert it in all asm files.
    
    Reviewed by:    emaste, markj
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D42228
---
 lib/libc/aarch64/gen/_ctx_start.S | 4 ++++
 lib/libc/aarch64/gen/_setjmp.S    | 3 +++
 lib/libc/aarch64/gen/fabs.S       | 4 ++++
 lib/libc/aarch64/gen/setjmp.S     | 3 +++
 lib/libc/aarch64/gen/sigsetjmp.S  | 3 +++
 lib/libc/aarch64/string/memmove.S | 4 ++++
 lib/libc/aarch64/sys/cerror.S     | 4 ++++
 lib/libc/aarch64/sys/syscall.S    | 3 +++
 lib/libc/aarch64/sys/vfork.S      | 3 +++
 lib/libc/sys/Makefile.inc         | 7 +++++++
 10 files changed, 38 insertions(+)

diff --git a/lib/libc/aarch64/gen/_ctx_start.S b/lib/libc/aarch64/gen/_ctx_start.S
index 15edcf21d463..a4049e6c241a 100644
--- a/lib/libc/aarch64/gen/_ctx_start.S
+++ b/lib/libc/aarch64/gen/_ctx_start.S
@@ -27,9 +27,13 @@
  */
 
 #include <machine/asm.h>
+#include <sys/elf_common.h>
+
 ENTRY(_ctx_start)
 	blr	x19		/* Call func from makecontext */
 	mov	x0, x20		/* Load ucp saved in makecontext */
 	bl	_C_LABEL(ctx_done)
 	bl	_C_LABEL(abort)
 END(_ctx_start)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/gen/_setjmp.S b/lib/libc/aarch64/gen/_setjmp.S
index 4fc9ce304893..037eccf1a48a 100644
--- a/lib/libc/aarch64/gen/_setjmp.S
+++ b/lib/libc/aarch64/gen/_setjmp.S
@@ -30,6 +30,7 @@
 
 #include <machine/asm.h>
 #include <machine/setjmp.h>
+#include <sys/elf_common.h>
 
 ENTRY(_setjmp)
 	/* Store the magic value and stack pointer */
@@ -101,3 +102,5 @@ botch:
 	bl	_C_LABEL(abort)
 #endif
 END(_longjmp)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/gen/fabs.S b/lib/libc/aarch64/gen/fabs.S
index 29e4b89d5ee1..91967a10299b 100644
--- a/lib/libc/aarch64/gen/fabs.S
+++ b/lib/libc/aarch64/gen/fabs.S
@@ -24,7 +24,11 @@
  */
 
 #include <machine/asm.h>
+#include <sys/elf_common.h>
+
 ENTRY(fabs)
 	fabs d0, d0
 	ret
 END(fabs)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/gen/setjmp.S b/lib/libc/aarch64/gen/setjmp.S
index ecc677de2620..97d98ae2fb52 100644
--- a/lib/libc/aarch64/gen/setjmp.S
+++ b/lib/libc/aarch64/gen/setjmp.S
@@ -30,6 +30,7 @@
 
 #include <machine/asm.h>
 #include <machine/setjmp.h>
+#include <sys/elf_common.h>
 
 ENTRY(setjmp)
 	sub	sp, sp, #16
@@ -119,3 +120,5 @@ botch:
 	bl	_C_LABEL(longjmperror)
 	bl	_C_LABEL(abort)
 END(longjmp)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/gen/sigsetjmp.S b/lib/libc/aarch64/gen/sigsetjmp.S
index cdff7a46c85b..daf3914b6278 100644
--- a/lib/libc/aarch64/gen/sigsetjmp.S
+++ b/lib/libc/aarch64/gen/sigsetjmp.S
@@ -28,6 +28,7 @@
 
 #include <machine/asm.h>
 #include <machine/setjmp.h>
+#include <sys/elf_common.h>
 
 ENTRY(sigsetjmp)
 	cmp	x1, #0
@@ -52,3 +53,5 @@ ENTRY(siglongjmp)
 .Lmagic:
 	.quad	_JB_MAGIC__SETJMP
 END(siglongjmp)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/string/memmove.S b/lib/libc/aarch64/string/memmove.S
index e2f99790e0da..6ca014b3a565 100644
--- a/lib/libc/aarch64/string/memmove.S
+++ b/lib/libc/aarch64/string/memmove.S
@@ -3,3 +3,7 @@
  * as it stops MISRCS from picking up the C implementation and rtld expects
  * to copy the memmove object file into its object directory.
  */
+
+#include <machine/asm.h>
+#include <sys/elf_common.h>
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/sys/cerror.S b/lib/libc/aarch64/sys/cerror.S
index a83514bc2511..85e75af8ec0d 100644
--- a/lib/libc/aarch64/sys/cerror.S
+++ b/lib/libc/aarch64/sys/cerror.S
@@ -25,6 +25,8 @@
  */
 
 #include <machine/asm.h>
+#include <sys/elf_common.h>
+
 ENTRY(cerror)
 	.hidden	cerror
 	sub	sp, sp, #16
@@ -37,3 +39,5 @@ ENTRY(cerror)
 	add	sp, sp, #16
 	ret
 END(cerror)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/sys/syscall.S b/lib/libc/aarch64/sys/syscall.S
index 2c7e207f82f7..037c4b12ddae 100644
--- a/lib/libc/aarch64/sys/syscall.S
+++ b/lib/libc/aarch64/sys/syscall.S
@@ -27,6 +27,9 @@
  */
 
 #include <machine/asm.h>
+#include <sys/elf_common.h>
 #include "SYS.h"
 
 RSYSCALL(syscall)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/aarch64/sys/vfork.S b/lib/libc/aarch64/sys/vfork.S
index f9489738a3c7..03ae5a6325ba 100644
--- a/lib/libc/aarch64/sys/vfork.S
+++ b/lib/libc/aarch64/sys/vfork.S
@@ -25,6 +25,7 @@
  */
 
 #include <machine/asm.h>
+#include <sys/elf_common.h>
 #include "SYS.h"
 
 ENTRY(__sys_vfork)
@@ -38,3 +39,5 @@ ENTRY(__sys_vfork)
 	mov	lr, x2
 	ret
 END(__sys_vfork)
+
+GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index e9a9f8f5935c..53c7a1c20580 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -124,12 +124,18 @@ NOTE_GNU_STACK='\t.section .note.GNU-stack,"",%%progbits\n'
 .else
 NOTE_GNU_STACK=''
 .endif
+.if ${MACHINE_CPUARCH} == "aarch64"
+FEATURE_NOTE='\#include <sys/elf_common.h>\nGNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)'
+.else
+FEATURE_NOTE=''
+.endif
 
 ${SASM}:
 	printf '/* %sgenerated by libc/sys/Makefile.inc */\n' @ > ${.TARGET}
 	printf '#include "compat.h"\n' >> ${.TARGET}
 	printf '#include "SYS.h"\nRSYSCALL(${.PREFIX})\n' >> ${.TARGET}
 	printf  ${NOTE_GNU_STACK} >>${.TARGET}
+	printf  ${FEATURE_NOTE} >> ${.TARGET}
 
 ${SPSEUDO}:
 	printf '/* %sgenerated by libc/sys/Makefile.inc */\n' @ > ${.TARGET}
@@ -137,6 +143,7 @@ ${SPSEUDO}:
 	printf '#include "SYS.h"\nPSEUDO(${.PREFIX:S/_//})\n' \
 	    >> ${.TARGET}
 	printf ${NOTE_GNU_STACK} >>${.TARGET}
+	printf ${FEATURE_NOTE} >> ${.TARGET}
 
 MAN+=	abort2.2 \
 	accept.2 \