<?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>273703</bug_id>
          
          <creation_ts>2024-05-03 12:05:26 -0700</creation_ts>
          <short_desc>Crash on WebCore::FrameLoader::effectiveReferrerPolicy() after 274396@main on ARM64 with GCC -O3</short_desc>
          <delta_ts>2024-05-21 11:23: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>WPE WebKit</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=268704</see_also>
    
    <see_also>https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115135</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Carlos Alberto Lopez Perez">clopez</reporter>
          <assigned_to name="Carlos Alberto Lopez Perez">clopez</assigned_to>
          <cc>achristensen</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>pascoe</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2033128</commentid>
    <comment_count>0</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2024-05-03 12:05:26 -0700</bug_when>
    <thetext>The WPE performance test bots running on RPi4 boards (ARM 64-bits) started to crash all the tests after 274396@main

The bots are here: https://build.webkit.org/#/builders/895

I manually bisected this and I confirm that everything was working before 274396@main but after 274396@main and later the browser always crashes as soon as it starts, is not able to even load a very basic page.

The backtrace looks like this:

#0  0x0000007fb24e5c48 in WebCore::FrameLoader::effectiveReferrerPolicy() const () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#1  0x0000007fb1f15b1c in WebCore::Document::initSecurityContext() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#2  0x0000007fb1f1c994 in WebCore::Document::Document(WebCore::LocalFrame*, WebCore::Settings const&amp;, WTF::URL const&amp;, WTF::OptionSet&lt;WebCore::Document::DocumentClass&gt;, WTF::OptionSet&lt;WebCore::Document::ConstructionFlag&gt;, WebCore::ProcessQualified&lt;WTF::UUID&gt;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#3  0x0000007fb217adf0 in WebCore::HTMLDocument::HTMLDocument(WebCore::LocalFrame*, WebCore::Settings const&amp;, WTF::URL const&amp;, WebCore::ProcessQualified&lt;WTF::UUID&gt;, WTF::OptionSet&lt;WebCore::Document::DocumentClass&gt;, WTF::OptionSet&lt;WebCore::Document::ConstructionFlag&gt;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#4  0x0000007fb1ee16c4 in WebCore::DOMImplementation::createDocument(WTF::String const&amp;, WebCore::LocalFrame*, WebCore::Settings const&amp;, WTF::URL const&amp;, WebCore::ProcessQualified&lt;WTF::UUID&gt;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#5  0x0000007fb24b7150 in WebCore::DocumentWriter::createDocument(WTF::URL const&amp;, WebCore::ProcessQualified&lt;WTF::UUID&gt;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#6  0x0000007fb24cfcf4 in WebCore::DocumentWriter::begin(WTF::URL const&amp;, bool, WebCore::Document*, WebCore::ProcessQualified&lt;WTF::UUID&gt;, WebCore::NavigationAction const*) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#7  0x0000007fb24d0d94 in WebCore::DocumentLoader::commitData(WebCore::SharedBuffer const&amp;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#8  0x0000007fb24d17f4 in WebCore::DocumentLoader::finishedLoading() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#9  0x0000007fb24d1ef8 in WebCore::DocumentLoader::maybeLoadEmpty() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#10 0x0000007fb24d5838 in WebCore::DocumentLoader::startLoadingMainResource() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#11 0x0000007fb24ecd88 in WebCore::FrameLoader::init() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#12 0x0000007fb2611a48 in WebCore::LocalFrame::init() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#13 0x0000007faf5379e8 in WebKit::WebPage::WebPage(WTF::ObjectIdentifierGeneric&lt;WebCore::PageIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits&gt;, WebKit::WebPageCreationParameters&amp;&amp;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#14 0x0000007faf538908 in WebKit::WebPage::create(WTF::ObjectIdentifierGeneric&lt;WebCore::PageIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits&gt;, WebKit::WebPageCreationParameters&amp;&amp;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#15 0x0000007faf42b76c in WebKit::WebProcess::createWebPage(WTF::ObjectIdentifierGeneric&lt;WebCore::PageIdentifierType, WTF::ObjectIdentifierMainThreadAccessTraits&gt;, WebKit::WebPageCreationParameters&amp;&amp;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#16 0x0000007faef4b6b4 in WebKit::WebProcess::didReceiveWebProcessMessage(IPC::Connection&amp;, IPC::Decoder&amp;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#17 0x0000007faf1b1480 in IPC::Connection::dispatchMessage(WTF::UniqueRef&lt;IPC::Decoder&gt;) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#18 0x0000007faf1b282c in IPC::Connection::dispatchOneIncomingMessage() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#19 0x0000007fb0a7b59c in WTF::RunLoop::performWork() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#20 0x0000007fb0af5190 in WTF::RunLoop::RunLoop()::{lambda(void*)#1}::_FUN(void*) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#21 0x0000007fb0af609c in WTF::RunLoop::{lambda(_GSource*, int (*)(void*), void*)#1}::_FUN(_GSource*, int (*)(void*), void*) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#22 0x0000007fae0b9c7c in g_main_context_dispatch () from /usr/lib/libglib-2.0.so.0
#23 0x0000007fae0ba070 in ?? () from /usr/lib/libglib-2.0.so.0
#24 0x0000007fae0ba3f8 in g_main_loop_run () from /usr/lib/libglib-2.0.so.0
#25 0x0000007fb0af629c in WTF::RunLoop::run() () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#26 0x0000007faf5683f8 in WebKit::WebProcessMain(int, char**) () from /home/root/webkit/WebKitBuild/WPE/Release/lib/libWPEWebKit-2.0.so.1
#27 0x0000007fad8f6e38 in __libc_start_call_main (main=main@entry=0x55578c0840 &lt;main&gt;, argc=argc@entry=3, argv=argv@entry=0x7fd849a888) at /usr/src/debug/glibc/2.37-r1/sysdeps/nptl/libc_start_call_main.h:58
#28 0x0000007fad8f6f1c in __libc_start_main_impl (main=0x55578c0840 &lt;main&gt;, argc=3, argv=0x7fd849a888, init=&lt;optimized out&gt;, fini=&lt;optimized out&gt;, rtld_fini=&lt;optimized out&gt;, stack_end=&lt;optimized out&gt;) at /usr/src/debug/glibc/2.37-r1/csu/libc-start.c:360
#29 0x00000055578c08b0 in _start () at ../sysdeps/aarch64/start.S:98

And I&apos;m not able to get a better backtrace because if I try to build a Debug build then the crash not longer happens.

The crash also doesn&apos;t happen if you build Release with -O2, only happens with -O3 which is the default for developer release builds.


I compared all the compiler switches that are enabled at -O2 vs -O3 for GCC 12.3.0 and this is the one causing the crash is --param=early-inlining-insns

-O3 enables early-inlining-insns=14 and -O2 enables early-inlining-insns=6

The file causing the crash is Source/WebCore/page/Page.cpp
 * If it gets built with --param=early-inlining-insns=9 or lower it is fine
 * If it gets built with --param=early-inlining-insns=10 or higher it crashes

However that is for a release build. If I build Debug and I set --param=early-inlining-insns=16 on that file then it doesn&apos;t crash anymore.. 🤷

So i&apos;m not sure if this is a compiler bug, or is because some undefined behaviour or there is a valid bug somewhere that only triggers due to very specific timings caused by a race condition or similar.

But the issue is 100% reproducible when it happens.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2033132</commentid>
    <comment_count>1</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2024-05-03 12:14:09 -0700</bug_when>
    <thetext>Some info about the crash that I debugged with a few printfs ...

 - On the backtrace above, the crash inside the function &quot;WebCore::FrameLoader::effectiveReferrerPolicy()&quot; happens exactly when doing the downcast of m_frame-&gt;opener()

In this line exactly:

RefPtr opener = dynamicDowncast&lt;LocalFrame&gt;(m_frame-&gt;opener()))

Note: &quot;m_frame-&gt;opener()&quot; is not null (I checked it)

If I comment out that code and simply return &quot;ReferrerPolicy::Default&quot; there then the same crash happens later at WebCore::Document::initSecurityContext()

exactly here:

    // If we do not obtain a meaningful origin from the URL, then we try to
    // find one via the frame hierarchy.
    RefPtr parentFrame = m_frame-&gt;tree().parent();
    RefPtr openerFrame = dynamicDowncast&lt;LocalFrame&gt;(m_frame-&gt;opener()); // &lt;--- here crashes, again when trying to call &quot;dynamicDowncast&lt;LocalFrame&gt;(m_frame-&gt;opener())&quot; which is basically the same crash than previously (note: I checked that &quot;m_frame-&gt;opener()&quot; is not null)
    RefPtr ownerFrame = dynamicDowncast&lt;LocalFrame&gt;(parentFrame.get());


So not sure what is going on and/or if this is a valid bug or a crash caused by a bug on the compiler itself.



I have a workaround that is ensuring this file does not build with a value of &quot;early-inlining-insns&quot; higher than what its enabled for -O2 ... so I will propose that patch for now</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2033139</commentid>
    <comment_count>2</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2024-05-03 12:28:40 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/28117</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2036036</commentid>
    <comment_count>3</comment_count>
    <who name="Carlos Alberto Lopez Perez">clopez</who>
    <bug_when>2024-05-17 09:58:28 -0700</bug_when>
    <thetext>In the end I managed to create a simplified test case and reported a bug to GCC here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115135

This looks to me like a bug on GCC and not an issue on the WebKit code.

It happens also with newer versions of GCC (13 and 14 tested and affected).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2036773</commentid>
    <comment_count>4</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-05-21 11:23:49 -0700</bug_when>
    <thetext>Committed 279066@main (bc889156b6fb): &lt;https://commits.webkit.org/279066@main&gt;

Reviewed commits have been landed. Closing PR #28117 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>