git: 5889b1f052fe - stable/14 - arm64: do not register elf32 brand if hardware cannot exec aarch32

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Thu, 23 Nov 2023 04:01:01 UTC
The branch stable/14 has been updated by kib:

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

commit 5889b1f052fef73cd75dbb71e05d855fa8a10bb4
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-11-16 19:45:52 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-11-23 04:00:36 +0000

    arm64: do not register elf32 brand if hardware cannot exec aarch32
    
    (cherry picked from commit 0aa93010c571b88a6402405be22745fa05a5baab)
---
 sys/arm64/arm64/elf32_machdep.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/sys/arm64/arm64/elf32_machdep.c b/sys/arm64/arm64/elf32_machdep.c
index 26aa2cddfdb2..4acb68b09108 100644
--- a/sys/arm64/arm64/elf32_machdep.c
+++ b/sys/arm64/arm64/elf32_machdep.c
@@ -153,8 +153,16 @@ static Elf32_Brandinfo freebsd32_brand_info = {
 	.header_supported= elf32_arm_abi_supported,
 };
 
-SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST,
-    (sysinit_cfunc_t)elf32_insert_brand_entry, &freebsd32_brand_info);
+static void
+register_elf32_brand(void *arg)
+{
+	/* Check if we support AArch32 */
+	if (ID_AA64PFR0_EL0_VAL(READ_SPECIALREG(id_aa64pfr0_el1)) ==
+	    ID_AA64PFR0_EL0_64_32) {
+		elf32_insert_brand_entry(&freebsd32_brand_info);
+	}
+}
+SYSINIT(elf32, SI_SUB_EXEC, SI_ORDER_FIRST, register_elf32_brand, NULL);
 
 static bool
 elf32_arm_abi_supported(struct image_params *imgp, int32_t *osrel __unused,
@@ -162,11 +170,6 @@ elf32_arm_abi_supported(struct image_params *imgp, int32_t *osrel __unused,
 {
 	const Elf32_Ehdr *hdr;
 
-	/* Check if we support AArch32 */
-	if (ID_AA64PFR0_EL0_VAL(READ_SPECIALREG(id_aa64pfr0_el1)) !=
-	    ID_AA64PFR0_EL0_64_32)
-		return (false);
-
 #define	EF_ARM_EABI_FREEBSD_MIN	EF_ARM_EABI_VER4
 	hdr = (const Elf32_Ehdr *)imgp->image_header;
 	if (EF_ARM_EABI_VERSION(hdr->e_flags) < EF_ARM_EABI_FREEBSD_MIN) {