On Sun, Oct 20, 2024 at 10:28:25PM +0200, Omar Polo wrote:
> The changelog is available here:
> 
> https://github.com/taisei-project/taisei/releases/tag/v1.4.2
> 
> I played it a bit and seems to work :)

I managed to remove USE_NOBTCFI! The following diff is to be applied on
top of yours. I lifted the ifdefs for the C file from our own
/usr/lib/clang/16/include/cet.h .

        Lucas


diff 958e86792bdef182359f04840bc7f4b5048f160a 
c500735242689105255cc0741f462ee7800d6e68
commit - 958e86792bdef182359f04840bc7f4b5048f160a
commit + c500735242689105255cc0741f462ee7800d6e68
blob - fda034398a4d0780b009df55ba203686bf76623a
blob + 6c120fc21967767274d6b51153e854ab53ceda1a
--- games/taisei/Makefile
+++ games/taisei/Makefile
@@ -2,14 +2,11 @@
 # modern video cards
 ONLY_FOR_ARCHS =       amd64 aarch64 i386
 
-# the koishi coroutine library needs boost 1.81.0+ for BTI
-# https://github.com/taisei-project/koishi/issues/6
-USE_NOBTCFI =          Yes
-
 COMMENT =              clone of the touhou games
 
 VERSION =              1.4.2
 DISTNAME =             taisei-${VERSION}
+REVISION =             0
 
 CATEGORIES =           games
 
blob - /dev/null
blob + 9cc5284a35a69df414c2bba14f52ef1fdd9c39c8 (mode 644)
--- /dev/null
+++ 
games/taisei/patches/patch-external_koishi_src_fcontext_asm_jump_x86_64_sysv_elf_gas_S
@@ -0,0 +1,25 @@
+Add support for BTI on amd64.
+
+Index: external/koishi/src/fcontext/asm/jump_x86_64_sysv_elf_gas.S
+--- external/koishi/src/fcontext/asm/jump_x86_64_sysv_elf_gas.S.orig
++++ external/koishi/src/fcontext/asm/jump_x86_64_sysv_elf_gas.S
+@@ -23,13 +23,18 @@
+  *  
----------------------------------------------------------------------------------
  *
+  *                                                                            
          *
+  
****************************************************************************************/
+-
++# if defined __CET__
++#  include <cet.h>
++# else
++#  define _CET_ENDBR
++# endif
+ .file "jump_x86_64_sysv_elf_gas.S"
+ .text
+ .globl jump_fcontext
+ .type jump_fcontext,@function
+ .align 16
+ jump_fcontext:
++    _CET_ENDBR
+     leaq  -0x38(%rsp), %rsp /* prepare stack */
+ 
+ #if !defined(BOOST_USE_TSX)
blob - /dev/null
blob + 090f2bc075028eed23f219aa166f398015337d4c (mode 644)
--- /dev/null
+++ 
games/taisei/patches/patch-external_koishi_src_fcontext_asm_make_x86_64_sysv_elf_gas_S
@@ -0,0 +1,41 @@
+Add support for BTI on amd64.
+
+Index: external/koishi/src/fcontext/asm/make_x86_64_sysv_elf_gas.S
+--- external/koishi/src/fcontext/asm/make_x86_64_sysv_elf_gas.S.orig
++++ external/koishi/src/fcontext/asm/make_x86_64_sysv_elf_gas.S
+@@ -23,13 +23,18 @@
+  *  
----------------------------------------------------------------------------------
  *
+  *                                                                            
          *
+  
****************************************************************************************/
+-
++# if defined __CET__
++#  include <cet.h>
++# else
++#  define _CET_ENDBR
++# endif
+ .file "make_x86_64_sysv_elf_gas.S"
+ .text
+ .globl make_fcontext
+ .type make_fcontext,@function
+ .align 16
+ make_fcontext:
++    _CET_ENDBR
+     /* first arg of make_fcontext() == top of context-stack */
+     movq  %rdi, %rax
+ 
+@@ -64,6 +69,7 @@ make_fcontext:
+     ret /* return pointer to context-data */
+ 
+ trampoline:
++    _CET_ENDBR
+     /* store return address on stack */
+     /* fix stack alignment */
+     push %rbp
+@@ -71,6 +77,7 @@ trampoline:
+     jmp *%rbx
+ 
+ finish:
++    _CET_ENDBR
+     /* exit code is zero */
+     xorq  %rdi, %rdi
+     /* exit application */
blob - /dev/null
blob + fb9d1fba88af6daaad0825310196183a5d147ef3 (mode 644)
--- /dev/null
+++ 
games/taisei/patches/patch-external_koishi_src_fcontext_asm_ontop_x86_64_sysv_elf_gas_S
@@ -0,0 +1,25 @@
+Add support for BTI on amd64.
+
+Index: external/koishi/src/fcontext/asm/ontop_x86_64_sysv_elf_gas.S
+--- external/koishi/src/fcontext/asm/ontop_x86_64_sysv_elf_gas.S.orig
++++ external/koishi/src/fcontext/asm/ontop_x86_64_sysv_elf_gas.S
+@@ -23,13 +23,18 @@
+  *  
----------------------------------------------------------------------------------
  *
+  *                                                                            
          *
+  
****************************************************************************************/
+-
++# if defined __CET__
++#  include <cet.h>
++# else
++#  define _CET_ENDBR
++# endif
+ .file "ontop_x86_64_sysv_elf_gas.S"
+ .text
+ .globl ontop_fcontext
+ .type ontop_fcontext,@function
+ .align 16
+ ontop_fcontext:
++    _CET_ENDBR
+     /* preserve ontop-function in R8 */
+     movq  %rdx, %r8
+ 
blob - /dev/null
blob + 229cc30270e16ffbc3c8ada327f6e0685c8b8f22 (mode 644)
--- /dev/null
+++ games/taisei/patches/patch-external_koishi_src_fcontext_fcontext_c
@@ -0,0 +1,35 @@
+Add support for BTI on amd64. ifdefs lifted from
+/usr/lib/clang/16/include/cet.h .
+
+Index: external/koishi/src/fcontext/fcontext.c
+--- external/koishi/src/fcontext/fcontext.c.orig
++++ external/koishi/src/fcontext/fcontext.c
+@@ -4,6 +4,20 @@
+ #include <stdlib.h>
+ #include <assert.h>
+ 
++# ifdef __LP64__
++#  if __CET__ & 0x1
++#    define _CET_ENDBR __asm("endbr64")
++#  else
++#    define _CET_ENDBR
++#  endif
++# else
++#  if __CET__ & 0x1
++#    define _CET_ENDBR __asm("endbr32")
++#  else
++#    define _CET_ENDBR
++#  endif
++# endif
++
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+@@ -39,6 +53,7 @@ typedef struct fcontext_fiber {
+ 
+ static void koishi_fiber_swap(koishi_fiber_t *from, koishi_fiber_t *to) {
+       transfer_t tf = jump_fcontext(to->fctx, from);
++      _CET_ENDBR;
+       from = (koishi_fiber_t*)tf.data;
+       from->fctx = tf.fctx;
+ }

Reply via email to