On Tue, Jun 24, 2025 at 03:14:33PM +0200, Mark Kettenis wrote:
> > Date: Tue, 24 Jun 2025 12:01:45 +0200
> > From: Mark Kettenis <[email protected]>
> > 
> > > Date: Tue, 24 Jun 2025 10:04:24 +1000
> > > From: Jonathan Gray <[email protected]>
> > > 
> > > On Tue, Jun 24, 2025 at 08:53:03AM +1000, Jonathan Gray wrote:
> > > > On Mon, Jun 23, 2025 at 08:31:45PM +0200, Mark Kettenis wrote:
> > > > > > Date: Mon, 23 Jun 2025 18:25:17 +0200
> > > > > > From: Moritz Buhl <[email protected]>
> > > > > > 
> > > > > > Dear bugs@,
> > > > > > 
> > > > > > for about two weeks I am having trouble running x11/alacritty on
> > > > > > my Apple MacBook Air M2 from 2022.
> > > > > > I suspect there is a missing BTI instruction in libmesas jit.
> > > > > 
> > > > > Yup!
> > > > > 
> > > > > So the big question is whether it is the Mesa update or the LLVM
> > > > > update that broke it.  The LLVM update was committed 12 days ago, so
> > > > > "about two weeks" could mean it is or it isn't :(.
> > > > 
> > > > Mesa still has the local change to add and call
> > > > 
> > > > extern "C" void
> > > > lp_set_module_branch_protection(LLVMModuleRef MRef)
> > > > {
> > > >    /* Enable standard (bti+pac-ret) branch protection */
> > > >    llvm::Module *M = llvm::unwrap(MRef);
> > > >    M->addModuleFlag(llvm::Module::Override, 
> > > > "branch-target-enforcement", 1);
> > > >    M->addModuleFlag(llvm::Module::Override, "sign-return-address", 1);
> > > > }
> > > 
> > > It seems LLVM 19 needs it set for function attributes after
> > > https://github.com/llvm/llvm-project/commit/e15d67cfc2e5775cc79281aa860f3ad3be628f39
> > 
> > Yes, I came to the same conclusion.  I think I found a suitable place
> > to add the function attributes, but I need to do some testing.  Stay
> > tuned.
> 
> This seems to fix the issue.

thanks for looking into this

> 
> ok?

ok jsg@

I'm curious why it doesn't need
LLVMAddTargetDependentFunctionAttr(func, "sign-return-address-key", "a_key");
to match clang/lib/Driver/ToolChains/Clang.cpp CollectARMPACBTIOptions()
a_key is the default?

> 
> 
> 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
> diff -u -p -r1.20 lp_bld_init.c
> --- lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_init.c      5 Jun 2025 
> 14:19:08 -0000       1.20
> +++ lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_init.c      24 Jun 2025 
> 13:13:09 -0000
> @@ -234,10 +234,6 @@ init_gallivm_state(struct gallivm_state 
>     lp_set_module_stack_alignment_override(gallivm->module, 4);
>  #endif
>  
> -#if DETECT_ARCH_AARCH64
> -   lp_set_module_branch_protection(gallivm->module);
> -#endif
> -
>     gallivm->builder = LLVMCreateBuilderInContext(gallivm->context);
>     if (!gallivm->builder)
>        goto fail;
> @@ -404,6 +400,16 @@ gallivm_compile_module(struct gallivm_st
>                     "[-mcpu=<-mcpu option>] ",
>                     "[-mattr=<-mattr option(s)>]");
>     }
> +
> +#if DETECT_ARCH_AARCH64
> +   LLVMValueRef func = LLVMGetFirstFunction(gallivm->module);
> +
> +   while (func) {
> +      LLVMAddTargetDependentFunctionAttr(func, "branch-target-enforcement", 
> "true");
> +      LLVMAddTargetDependentFunctionAttr(func, "sign-return-address", 
> "non-leaf");
> +      func = LLVMGetNextFunction(func);
> +   }
> +#endif
>  
>     lp_passmgr_run(gallivm->passmgr,
>                    gallivm->module,
> 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
> diff -u -p -r1.22 lp_bld_misc.cpp
> --- lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp    5 Jun 2025 
> 14:19:08 -0000       1.22
> +++ lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.cpp    24 Jun 2025 
> 13:13:09 -0000
> @@ -675,15 +675,6 @@ lp_set_module_stack_alignment_override(L
>  #endif
>  }
>  
> -extern "C" void
> -lp_set_module_branch_protection(LLVMModuleRef MRef)
> -{
> -   /* Enable standard (bti+pac-ret) branch protection */
> -   llvm::Module *M = llvm::unwrap(MRef);
> -   M->addModuleFlag(llvm::Module::Override, "branch-target-enforcement", 1);
> -   M->addModuleFlag(llvm::Module::Override, "sign-return-address", 1);
> -}
> -
>  using namespace llvm;
>  
>  class GallivmRunAtExitForStaticDestructors : public SDNode
> 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
> diff -u -p -r1.13 lp_bld_misc.h
> --- lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.h      5 Jun 2025 
> 14:19:08 -0000       1.13
> +++ lib/mesa/src/gallium/auxiliary/gallivm/lp_bld_misc.h      24 Jun 2025 
> 13:13:09 -0000
> @@ -96,10 +96,6 @@ lp_free_objcache(void *objcache);
>  
>  void
>  lp_set_module_stack_alignment_override(LLVMModuleRef M, unsigned align);
> -
> -void
> -lp_set_module_branch_protection(LLVMModuleRef M);
> -
>  #ifdef __cplusplus
>  
>  void
> 
> 

Reply via email to