<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>245697</bug_id>
          
          <creation_ts>2022-09-26 14:55:46 -0700</creation_ts>
          <short_desc>[Linux] Support branch target identification on aarch64</short_desc>
          <delta_ts>2026-04-05 03:16:52 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugzilla.redhat.com/show_bug.cgi?id=2130009</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Catanzaro">mcatanzaro</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>aperez</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mcatanzaro</cc>
    
    <cc>mitz</cc>
    
    <cc>oliver</cc>
    
    <cc>teohhanhui</cc>
    
    <cc>val</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1901301</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-09-26 14:55:46 -0700</bug_when>
    <thetext>It seems JSC crashes immediately if run using a Linux kernel built with CONFIG_ARM64_BTI=y, when using hardware that actually supports BTI (e.g. Apple M2 Macbook Air running Linux). Backtrace from the downstream bug:

   Module libvulkan.so.1 with build-id
67d50cfbcd9385a604b088608e38177128818e19
   Stack trace of thread 2:
   #0  0x0000ffff5711b8b0 llint_program_prologue
(libjavascriptcoregtk-4.0.so.18 + 0x13b8b0)
   #1  0x0000ffff5711844c vmEntryToJavaScript
(libjavascriptcoregtk-4.0.so.18 + 0x13844c)
   #2  0x0000ffff57dcf7d8
_ZN3JSC11Interpreter14executeProgramERKNS_10SourceCodeEPNS_14JSGlobalObje$
   #3  0x0000ffff11600000 n/a (n/a + 0x0)

I found some documentation from ARM here:

https://developer.arm.com/documentation/ddi0596/2020-12/Base-Instructions/BTI--Branch-Target-Identification-

And here:

https://developer.arm.com/documentation/102433/0100/Jump-oriented-programming</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1901333</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-09-26 16:14:30 -0700</bug_when>
    <thetext>Yusuke says the implementation will be Linux-specific, not something shared with Apple. Alas, I had been hoping it would be standard for everyone using aarch64....</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1901423</commentid>
    <comment_count>2</comment_count>
    <who name="Oliver Hunt">oliver</who>
    <bug_when>2022-09-27 00:09:59 -0700</bug_when>
    <thetext>CC&apos;ing Mark and Yusuke.

I&apos;m curious why we believe BTI work will be linux specific vs. gating on something like ENABLE(BTI) (e.g. this is simply a matter of linux using BTI vs our reliance on PAC?)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1901466</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-09-27 06:11:06 -0700</bug_when>
    <thetext>Some more info on PAC and BTI: https://fedoraproject.org/wiki/Changes/Aarch64_PointerAuthentication</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1901467</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-09-27 06:24:46 -0700</bug_when>
    <thetext>One of the upstream patches says &quot;creation of a BTI-enabled binary requires _everything_ linked in to be BTI-enabled.&quot; If that&apos;s still true, then forcing cloop is the only option.

If that has changed, then some lightly-edited hints from Yusuke on Slack:

&quot;&quot;&quot;
Probably, all WebKitGTK and JIT code should be marked as Legacy code, which probably relies on linker control on Linux toolchain etc.

quite likely, linker has an option to emit ELF data structure saying this is &quot;Legacy&quot; code so do not apply BTI. https://reviews.llvm.org/D62609

GNU_PROPERTY_AARCH64_FEATURE_1_BTI and GNU_PROPERTY_AARCH64_FEATURE_1_PAC

And the loader will load these binaries with appropriate page table entry bits on OS, and that&apos;s it, I guess.

And also need to check mmap option to disable these configuration explicitly for JIT code. Probably Linux should have that kind of thing, and you should ensure that JIT code is mapped with that appropriate bits.
&quot;&quot;&quot;

More likely, we&apos;d have to either disable it or really add the BTI instructions everywhere required. I don&apos;t know how hard that would be, but I assume it would not be easy.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1901563</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Catanzaro">mcatanzaro</who>
    <bug_when>2022-09-27 10:33:53 -0700</bug_when>
    <thetext>Mark Lam has confirmed on Slack that this is not something Apple plans to implement, but he&apos;s around to offer tips for anyone who wants to try. Mark&apos;s suggestions from Slack:

&quot;&quot;&quot;
For starters, if you just want to get the asm llint (with no JIT) working, try adding &quot;bti jc \n&quot; to the definition of OFFLINE_ASM_GLOBAL_LABEL in LowLevelInterpreter.cpp.  As the name implies, you’re basically making every global label a viable jump/call target.  That should get you a long way.

Getting the JIT to work will take a lot more work, but is not insurmountable.
&quot;&quot;&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1902941</commentid>
    <comment_count>6</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-10-03 14:56:19 -0700</bug_when>
    <thetext>&lt;rdar://problem/100735511&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197014</commentid>
    <comment_count>7</comment_count>
    <who name="Val Packett">val</who>
    <bug_when>2026-04-05 03:16:52 -0700</bug_when>
    <thetext>This has been showing up in the wild a lot as more hardware with BTI became available…

&lt;https://bugs.launchpad.net/ubuntu/+source/webkit2gtk/+bug/2107619&gt;
&lt;https://bugzilla.redhat.com/show_bug.cgi?id=2130009&gt;
&lt;https://gitlab.gnome.org/GNOME/gnome-build-meta/-/issues/1240&gt;

So far the packagers have been replacing `-mbranch-protection=standard` with `-mbranch-protection=pac-ret`. (But they themselves add `-mbranch-protection=standard` in global flags in the first place…)</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>