From: Mark Kettenis Subject: Re: glxgears BTI SIGILL, arm64 To: Jonathan Gray Cc: tech@openbsd.org Date: Sun, 17 Mar 2024 21:09:08 +0100 > Date: Sun, 17 Mar 2024 17:08:14 +1100 > From: Jonathan Gray > Content-Type: text/plain; charset=us-ascii > Content-Disposition: inline > > On Sat, Mar 16, 2024 at 12:10:19PM +0000, Stuart Henderson wrote: > > 10913 glxgears PSIG SIGILL SIG_DFL code=ILL_BTCFI addr=0x21ca5a3000 trapno=905969666 > > > > Anyone have suggestions as to how to track this down any further? > > This is on an apple machine? If so it will be using llvmpipe. > To avoid the jit you can use: > > LIBGL_ALWAYS_SOFTWARE=1 GALLIUM_DRIVER=softpipe glxgears > > Do you still see it with that? Diff below seems to fix llvmpipe. At least I can run glxgears now. As far as I can tell there isn't an option that can be passed to the core llvm code that turns it on. What clang does is pass a function attribute or module flag that turns it on. So I made Mesa do the same. Not sure if this is the correct way to do things, but there is a precedent in overriding module parameters. ok? Index: lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_init.c =================================================================== RCS file: /cvs/xenocara/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_init.c,v retrieving revision 1.15 diff -u -p -r1.15 lp_bld_init.c --- lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_init.c 2 Nov 2023 04:53:36 -0000 1.15 +++ lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_init.c 17 Mar 2024 19:39:06 -0000 @@ -360,6 +360,10 @@ init_gallivm_state(struct gallivm_state lp_set_module_stack_alignment_override(gallivm->module, 4); #endif +#if DETECT_ARCH_AARCH64 + lp_set_module_branch_target_enforcement(gallivm->module); +#endif + gallivm->builder = LLVMCreateBuilderInContext(gallivm->context); if (!gallivm->builder) goto fail; Index: lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp =================================================================== RCS file: /cvs/xenocara/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp,v retrieving revision 1.17 diff -u -p -r1.17 lp_bld_misc.cpp --- lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 2 Nov 2023 04:53:36 -0000 1.17 +++ lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp 17 Mar 2024 19:39:06 -0000 @@ -619,3 +619,10 @@ lp_set_module_stack_alignment_override(L M->setOverrideStackAlignment(align); #endif } + +extern "C" void +lp_set_module_branch_target_enforcement(LLVMModuleRef MRef) +{ + llvm::Module *M = llvm::unwrap(MRef); + M->addModuleFlag(llvm::Module::Override, "branch-target-enforcement", 1); +} Index: lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.h =================================================================== RCS file: /cvs/xenocara/lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.h,v retrieving revision 1.10 diff -u -p -r1.10 lp_bld_misc.h --- lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.h 9 Dec 2021 00:21:07 -0000 1.10 +++ lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.h 17 Mar 2024 19:39:06 -0000 @@ -94,6 +94,10 @@ lp_free_objcache(void *objcache); void lp_set_module_stack_alignment_override(LLVMModuleRef M, unsigned align); + +void +lp_set_module_branch_target_enforcement(LLVMModuleRef M); + #ifdef __cplusplus } #endif