<?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>136313</bug_id>
          
          <creation_ts>2014-08-27 14:47:28 -0700</creation_ts>
          <short_desc>ASSERTION FAILED: from.isCell() &amp;&amp; from.asCell()-&gt;JSCell::inherits(std::remove_pointer&lt;To&gt;::type::info()) in JSC::jsCast(JSC::JSValue) [with To = JSC::JSScope*]</short_desc>
          <delta_ts>2014-08-27 18:07:36 -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>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <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="Akos Kiss">akiss</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>commit-queue</cc>
    
    <cc>gyuyoung.kim</cc>
    
    <cc>msaboff</cc>
    
    <cc>ossy</cc>
    
    <cc>zan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1031788</commentid>
    <comment_count>0</comment_count>
    <who name="Akos Kiss">akiss</who>
    <bug_when>2014-08-27 14:47:28 -0700</bug_when>
    <thetext>When running tests on EFL/ARM64 (compiled with gcc), jsc segfaults on scripts containing eval() with &quot;ASSERTION FAILED: from.isCell() &amp;&amp; from.asCell()-&gt;JSCell::inherits(std::remove_pointer&lt;To&gt;::type::info())&quot;. The simplest test case to cause the assertion is:

var c = &quot;&quot;;
eval(c);

The backtrace is always as follows:

Program received signal SIGSEGV, Segmentation fault.
0x0000000001098298 in WTFCrash () at /home/akiss/devel/WebKit/Source/WTF/wtf/Assertions.cpp:329
329	    *(int *)(uintptr_t)0xbbadbeef = 0;
(gdb) bt
#0  0x0000000001098298 in WTFCrash ()
    at /home/akiss/devel/WebKit/Source/WTF/wtf/Assertions.cpp:329
#1  0x0000000000aed314 in JSC::jsCast&lt;JSC::JSScope*&gt; (from=...)
    at /home/akiss/devel/WebKit/Source/JavaScriptCore/runtime/JSCell.h:241
#2  0x0000000000ae8270 in JSC::Register::scope (this=0x7fffffe598)
    at /home/akiss/devel/WebKit/Source/JavaScriptCore/runtime/JSScope.h:236
#3  0x0000000000ae3d38 in JSC::ExecState::scope (this=0x7fffffe580)
    at /home/akiss/devel/WebKit/Source/JavaScriptCore/interpreter/CallFrame.h:50
#4  0x0000000000bdd8dc in JSC::eval (callFrame=0x7fffffe550)
    at /home/akiss/devel/WebKit/Source/JavaScriptCore/interpreter/Interpreter.cpp:108
#5  0x0000000000c24fbc in JSC::operationCallEval (exec=0x7fffffe5a0, execCallee=0x7fffffe550)
    at /home/akiss/devel/WebKit/Source/JavaScriptCore/jit/JITOperations.cpp:619
#6  0x0000007fb4ca3cec in ?? ()
#7  0x0000007fb43ff970 in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

It seems that for JSC:eval the callFrame parameter is not set up properly: its CallerFrameAndPC component is not filled in. A little bit of analysis follows.

The bytecode for the script is:

[   0] enter             
[   1] mov               loc0, Undefined(@k0)
[   4] resolve_scope     loc1, c(@id0), 1&lt;ThrowIfNotFound|GlobalVar&gt;, 0
[  10] put_to_scope      loc1, c(@id0), String (atomic) (identifier): , ID: 5(@k1), 65537&lt;DoNotThrowIfNotFound|GlobalVar&gt;, &lt;structure&gt;, 26182392
[  17] resolve_scope     loc3, eval(@id1), 0&lt;ThrowIfNotFound|GlobalProperty&gt;, 0
[  23] get_from_scope    loc1, loc3, eval(@id1), 0&lt;ThrowIfNotFound|GlobalProperty&gt;, &lt;structure&gt;, 120
[  31] resolve_scope     loc2, c(@id0), 1&lt;ThrowIfNotFound|GlobalVar&gt;, 0
[  37] get_from_scope    loc2, loc2, c(@id0), 1&lt;ThrowIfNotFound|GlobalVar&gt;, &lt;structure&gt;, 26182392
[  45] call_eval         loc0, loc1, 2, 10    Original; predicting None
[  54] end               loc0

The relevant JIT code compiled for the script:

[  45] call_eval         loc0, loc1, 2, 10    Original; predicting None
		0x7fb4ca3ca4:    sub    sp, fp, #64		// fp already points to the current ExecState, this will be exec for operationCallEval; start making space for execCallee on the stack (however, sp does *not* point to execCallee but to &amp;(execCallee + JSStack::CallerFrameAndPCSize) )
		0x7fb4ca3ca8:    mov    w16, #0x2
		0x7fb4ca3cac:    stur   w16, [sp, #24]		// execCallee[JSStack::ArgumentCount] = 2
		0x7fb4ca3cb0:    movk   w16, #45
		0x7fb4ca3cb4:    stur   w16, [fp, #44]
		0x7fb4ca3cb8:    ldur   x0, [fp, #-16]
		0x7fb4ca3cbc:    stur   x0, [sp, #16]		// execCallee[JSStack::Callee] = loc1
		0x7fb4ca3cc0:    sub    x1, sp, #16		// now, x1 *does* point to the right place, i.e., to execCallee
		0x7fb4ca3cc4:    mov    x0, fp			// x0 points to exec
		0x7fb4ca3cc8:    movk   w16, #46
		0x7fb4ca3ccc:    stur   w16, [fp, #44]
		0x7fb4ca3cd0:    movz   x17, #55504
		0x7fb4ca3cd4:    movk   x17, #397, lsl #16
		0x7fb4ca3cd8:    str    fp, [x17, xzr]
		0x7fb4ca3cdc:    movz   x16, #20176		// 20176 = 0x4ed0
		0x7fb4ca3ce0:    movk   x16, #194, lsl #16	// 194 = 0xc2
		0x7fb4ca3ce4:    movk   x16, #0, lsl #32
		0x7fb4ca3ce8:    blr    x16 			// call JSC::operationCallEval (exec=x0, execCallee=x1)

Then, in operationCallEval:

EncodedJSValue JIT_OPERATION operationCallEval(ExecState* exec, ExecState* execCallee)
{
    // ...
    execCallee-&gt;setScope(exec-&gt;scope());
    execCallee-&gt;setCodeBlock(0);
    // ...
    JSValue result = eval(execCallee);

So, the rest of execCallee is set up &quot;below sp&quot;, but CallerFrameAndPC is *not*, because the call to operationCallEval and its prologue is expected to put the return address on top of sp, and the caller frame on top of that, thus making execCallee complete. However, the prologue does not behave as expected (at least on ARM/EFL, and compiled with gcc). The disassembled code starts with:

Dump of assembler code for function JSC::operationCallEval(JSC::ExecState*, JSC::ExecState*):
   0x0000000000c24ed0 &lt;+0&gt;:	stp	x29, x30, [sp,#-64]!
   0x0000000000c24ed4 &lt;+4&gt;:	mov	x29, sp
   0x0000000000c24ed8 &lt;+8&gt;:	str	x0, [x29,#24]
   0x0000000000c24edc &lt;+12&gt;:	str	x1, [x29,#16]
   0x0000000000c24ee0 &lt;+16&gt;:	ldr	x0, [x29,#24]

That is, sp is &quot;hoisted too much&quot; in one step, making space for fp/x29 (the pointer to caller frame) and lr/x30 (the return address), which is good, and for whatever temporary space is needed (which is bad). &quot;stp fp, lr, [sp, #-16]!&quot; would be the expected first step here, it seems. However, this is in the hands of the compiler...

Fortunately, the first parameter of operationCallEval, exec, points to the frame we need, so adding &quot;execCallee-&gt;setCallerFrame(static_cast&lt;CallFrame*&gt;(exec));&quot; to operationCallEval might solve the problem. (If I&apos;m right.) The return address is still not set by this approach, however.

This issue seems to be related to https://bugs.webkit.org/show_bug.cgi?id=127777 , which is fixed (with workaround) in https://bugs.webkit.org/show_bug.cgi?id=127898 and in https://bugs.webkit.org/show_bug.cgi?id=127909 , by passing -fno-omit-frame-pointer to gcc.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031793</commentid>
    <comment_count>1</comment_count>
      <attachid>237257</attachid>
    <who name="Akos Kiss">akiss</who>
    <bug_when>2014-08-27 14:53:12 -0700</bug_when>
    <thetext>Created attachment 237257
Proposed patch.

Since the proposed patch is not ARM64/EFL/GCC-specific, I tested it on x86_64 as well (but still on EFL and with GCC only). 
On ARM64, that assertion did not occur anymore when running run-javascriptcore-tests.
On x86_64, all jsc tests ran correctly before and after applying the patch, both in debug and release builds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031801</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2014-08-27 15:14:33 -0700</bug_when>
    <thetext>If you build with -fno-omit-frame-pointer everywhere, does the crash still happen?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031806</commentid>
    <comment_count>3</comment_count>
    <who name="Csaba Osztrogonác">ossy</who>
    <bug_when>2014-08-27 15:19:16 -0700</bug_when>
    <thetext>(In reply to comment #2)
&gt; If you build with -fno-omit-frame-pointer everywhere, does the crash still happen?

EFL builds with -fno-omit-frame-pointer long time ago ( since http://trac.webkit.org/changeset/163080 ), so the answer must be yes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031808</commentid>
    <comment_count>4</comment_count>
      <attachid>237257</attachid>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2014-08-27 15:25:57 -0700</bug_when>
    <thetext>Comment on attachment 237257
Proposed patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=237257&amp;action=review

r=me

&gt; Source/JavaScriptCore/jit/JITOperations.cpp:614
&gt; +    execCallee-&gt;setCallerFrame(static_cast&lt;CallFrame*&gt;(exec));

The static_cast is not needed.  CallFrame is a typedef of ExecState.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031823</commentid>
    <comment_count>5</comment_count>
      <attachid>237266</attachid>
    <who name="Akos Kiss">akiss</who>
    <bug_when>2014-08-27 15:52:39 -0700</bug_when>
    <thetext>Created attachment 237266
Proposed patch, v2

Static cast removed</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031825</commentid>
    <comment_count>6</comment_count>
      <attachid>237266</attachid>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2014-08-27 15:53:38 -0700</bug_when>
    <thetext>Comment on attachment 237266
Proposed patch, v2

r=me</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031832</commentid>
    <comment_count>7</comment_count>
      <attachid>237266</attachid>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2014-08-27 16:06:17 -0700</bug_when>
    <thetext>Comment on attachment 237266
Proposed patch, v2

Clearing flags on attachment: 237266

Committed r173031: &lt;http://trac.webkit.org/changeset/173031&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031833</commentid>
    <comment_count>8</comment_count>
    <who name="WebKit Commit Bot">commit-queue</who>
    <bug_when>2014-08-27 16:06:21 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1031867</commentid>
    <comment_count>9</comment_count>
    <who name="Akos Kiss">akiss</who>
    <bug_when>2014-08-27 18:07:36 -0700</bug_when>
    <thetext>For the records:

On ARM64/iOS/clang, the prologue of JavaScriptCore`operationCallEval starts like this:

JavaScriptCore[0x256a0c]:  stp    x20, x19, [sp, #-32]!
JavaScriptCore[0x256a10]:  stp    fp, lr, [sp, #16]
JavaScriptCore[0x256a14]:  add    fp, sp, #16

The procedure call standard for ARM64 (http://infocenter.arm.com/help/topic/com.arm.doc.ihi0055b/IHI0055B_aapcs64.pdf) says, in Section 5.4.3, that the location of the frame record within a stack frame is not specified, so both the iOS/clang and EFL/gcc prologues seem to be valid.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="1"
              ispatch="1"
              isprivate="0"
          >
            <attachid>237257</attachid>
            <date>2014-08-27 14:53:12 -0700</date>
            <delta_ts>2014-08-27 15:52:39 -0700</delta_ts>
            <desc>Proposed patch.</desc>
            <filename>arm64-jsc-eval-segfault.patch</filename>
            <type>text/plain</type>
            <size>1430</size>
            <attacher name="Akos Kiss">akiss</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9DaGFuZ2VMb2cgYi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LWdpdCBhL1NvdXJj
ZS9KYXZhU2NyaXB0Q29yZS9qaXQvSklUT3BlcmF0aW9ucy5jcHAgYi9Tb3VyY2UvSmF2YVNjcmlw
dENvcmUvaml0L0pJVE9wZXJhdGlvbnMuY3BwCmluZGV4IDY4MGRkZGUuLjNjZjgyMGIgMTAwNjQ0
Ci0tLSBhL1NvdXJjZS9KYXZhU2NyaXB0Q29yZS9qaXQvSklUT3BlcmF0aW9ucy5jcHAKKysrIGIv
U291cmNlL0phdmFTY3JpcHRDb3JlL2ppdC9KSVRPcGVyYXRpb25zLmNwcApAQCAtNjExLDYgKzYx
MSw3IEBAIEVuY29kZWRKU1ZhbHVlIEpJVF9PUEVSQVRJT04gb3BlcmF0aW9uQ2FsbEV2YWwoRXhl
Y1N0YXRlKiBleGVjLCBFeGVjU3RhdGUqIGV4ZWNDCiAKICAgICBleGVjQ2FsbGVlLT5zZXRTY29w
ZShleGVjLT5zY29wZSgpKTsKICAgICBleGVjQ2FsbGVlLT5zZXRDb2RlQmxvY2soMCk7CisgICAg
ZXhlY0NhbGxlZS0+c2V0Q2FsbGVyRnJhbWUoc3RhdGljX2Nhc3Q8Q2FsbEZyYW1lKj4oZXhlYykp
OwogCiAgICAgaWYgKCFpc0hvc3RGdW5jdGlvbihleGVjQ2FsbGVlLT5jYWxsZWVBc1ZhbHVlKCks
IGdsb2JhbEZ1bmNFdmFsKSkKICAgICAgICAgcmV0dXJuIEpTVmFsdWU6OmVuY29kZShKU1ZhbHVl
KCkpOwo=
</data>
<flag name="review"
          id="261981"
          type_id="1"
          status="+"
          setter="msaboff"
    />
          </attachment>
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>237266</attachid>
            <date>2014-08-27 15:52:39 -0700</date>
            <delta_ts>2014-08-27 16:06:17 -0700</delta_ts>
            <desc>Proposed patch, v2</desc>
            <filename>arm64-jsc-eval-segfault-v2.patch</filename>
            <type>text/plain</type>
            <size>1405</size>
            <attacher name="Akos Kiss">aki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