Add patch for arm64 BTI hints in Boost.Context asm

Resolves: RHEL-50164

The patch had to be modified to remove the .hidden directives added
upstream by 245904742b8a15f94fd5fe963fac746239f8900c (which is included
in boost-1.87.0).
This commit is contained in:
Jonathan Wakely 2026-04-22 10:38:53 +01:00
parent 02695ebc08
commit af5d757e7a
2 changed files with 125 additions and 1 deletions

View File

@ -0,0 +1,117 @@
commit 1be6822473b78278af1779fc6f642128996473d8
Author: Zayd Rajab <zaydr@amazon.com>
Date: Fri Aug 15 22:13:10 2025 +0000
[AArch64][BTI] Add BTI hint + GNU property to fcontext trampolines (ELF/GAS)
The AArch64 fcontext trampolines (jump_fcontext, make_fcontext, ontop_fcontext)
are indirect-entry-points. On BTI-enforcing systems they must begin with a BTI
or the first resume can trap with SIGILL.
Insert `bti c` (hint #34) at each entry under `__ARM_FEATURE_BTI_DEFAULT`, and
emit `GNU_PROPERTY_AARCH64_FEATURE_1_BTI` from each AArch64 assembly file so
linkers map the DSO with PROT_BTI without requiring -z force-bti.
Scope: ELF/GAS AArch64 trampolines only; +4 bytes per entry
Fixes #308
diff --git a/src/asm/jump_arm64_aapcs_elf_gas.S b/src/asm/jump_arm64_aapcs_elf_gas.S
index 7c1f075..b8abb2e 100644
--- a/libs/context/src/asm/jump_arm64_aapcs_elf_gas.S
+++ b/libs/context/src/asm/jump_arm64_aapcs_elf_gas.S
@@ -53,10 +53,28 @@
.file "jump_arm64_aapcs_elf_gas.S"
.text
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+/* Mark this object as requiring BTI, enabling the linker to set BTI on the output */
+ .pushsection .note.gnu.property, "a", %note
+ .p2align 3
+ .long 4 /* namesz */
+ .long 16 /* descsz (16 bytes) */
+ .long 5 /* type = NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU"
+ .p2align 3
+ .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
+ .long 4 /* datasz = 4 */
+ .long 1 /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
+ .long 0 /* pad to 8-byte alignment */
+ .popsection
+#endif
.align 2
.global jump_fcontext
.type jump_fcontext, %function
jump_fcontext:
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+ hint #34 /* bti c: valid indirect-entry target */
+#endif
# prepare stack for GP + FPU
sub sp, sp, #0xb0
diff --git a/src/asm/make_arm64_aapcs_elf_gas.S b/src/asm/make_arm64_aapcs_elf_gas.S
index 8ac825b..2465254 100644
--- a/libs/context/src/asm/make_arm64_aapcs_elf_gas.S
+++ b/libs/context/src/asm/make_arm64_aapcs_elf_gas.S
@@ -53,10 +53,28 @@
.file "make_arm64_aapcs_elf_gas.S"
.text
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+/* Mark this object as requiring BTI, enabling the linker to set BTI on the output */
+ .pushsection .note.gnu.property, "a", %note
+ .p2align 3
+ .long 4 /* namesz */
+ .long 16 /* descsz (16 bytes) */
+ .long 5 /* type = NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU"
+ .p2align 3
+ .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
+ .long 4 /* datasz = 4 */
+ .long 1 /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
+ .long 0 /* pad to 8-byte alignment */
+ .popsection
+#endif
.align 2
.global make_fcontext
.type make_fcontext, %function
make_fcontext:
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+ hint #34 /* bti c */
+#endif
# shift address in x0 (allocated stack) to lower 16 byte boundary
and x0, x0, ~0xF
diff --git a/src/asm/ontop_arm64_aapcs_elf_gas.S b/src/asm/ontop_arm64_aapcs_elf_gas.S
index 8e40fc7..1e6b466 100644
--- a/libs/context/src/asm/ontop_arm64_aapcs_elf_gas.S
+++ b/libs/context/src/asm/ontop_arm64_aapcs_elf_gas.S
@@ -53,10 +53,28 @@
.file "ontop_arm64_aapcs_elf_gas.S"
.text
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+/* Mark this object as requiring BTI, enabling the linker to set BTI on the output */
+ .pushsection .note.gnu.property, "a", %note
+ .p2align 3
+ .long 4 /* namesz */
+ .long 16 /* descsz (16 bytes) */
+ .long 5 /* type = NT_GNU_PROPERTY_TYPE_0 */
+ .asciz "GNU"
+ .p2align 3
+ .long 0xc0000000 /* GNU_PROPERTY_AARCH64_FEATURE_1_AND */
+ .long 4 /* datasz = 4 */
+ .long 1 /* GNU_PROPERTY_AARCH64_FEATURE_1_BTI */
+ .long 0 /* pad to 8-byte alignment */
+ .popsection
+#endif
.align 2
.global ontop_fcontext
.type ontop_fcontext, %function
ontop_fcontext:
+#if defined(__ARM_FEATURE_BTI_DEFAULT) && (__ARM_FEATURE_BTI_DEFAULT == 1)
+ hint #34 /* bti c */
+#endif
# prepare stack for GP + FPU
sub sp, sp, #0xb0

View File

@ -46,7 +46,7 @@ Name: boost
%global real_name boost
Summary: The free peer-reviewed portable C++ source libraries
Version: 1.83.0
Release: 7%{?dist}
Release: 8%{?dist}
License: BSL-1.0 AND MIT AND Python-2.0.1
# Replace each . with _ in %%{version}
@ -166,6 +166,9 @@ Patch8: boost-1.83-regex-test-fixes.patch
# https://github.com/boostorg/thread/pull/408
Patch9: boost-1.83-fix-no-member-named_that_error.patch
# https://github.com/boostorg/context/pull/312
Patch10: boost-1.83-context-arm64-bti-hint.patch
%bcond_with tests
%bcond_with docs_generated
@ -1295,6 +1298,10 @@ fi
%{_mandir}/man1/b2.1*
%changelog
* Wed Apr 22 2026 Jonathan Wakely <jwakely@redhat.com> - 1.83.0-8
- Add patch for arm64 BTI hints in Boost.Context asm
Resolves: RHEL-50164
* Tue Jan 27 2026 Patrick Palka <ppalka@redhat.com> - 1.83.0-7
- Add boost-url dependency to metapackage
Resolves: RHEL-124169