Bug 224

Summary: [Netbook/emenlow] matchbox-panel segfault after X startup
Product: [Build System, Metadata & Runtime] Meta-yocto Reporter: Jiajun Xu <jiajun.xu>
Component: meta-yoctoAssignee: Edwin Zhai <edwin.zhai>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: Medium CC: dongxiao.xu, jessica.zhang, josh, kevin.tian, poky.bs.watcher, poky.watcher, richard.purdie, sgw
Version: 0.9   
Target Milestone: 0.9 M3   
Hardware: Netbook   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Program Management Documentation change: ---

Description Jiajun Xu 2010-08-23 23:22:45 UTC
Testing Env:    
Hardware: netbook/emenlow
Images from weekly build (20100818) on autobuilder,
http://autobuilder.pokylinux.org/nightly/20100818-1.
poky tree commit: efadb43d671666d70a2a374e33fe9deca44f3e84

With the netbook/emenlow images from autobuilder, matchbox-panel meets segfault after Xserver start up.

#######
[    6.520630] [drm] Big FIFO is enabled
[    9.894403] matchbox-panel[556]: segfault at 137 ip 4f08fd6d sp bfb3fb20 error 4 in libgdk-x11-2.0.so.0.2000.1[4f02a000+90000]
[   10.056766] nm-applet[495]: segfault at 0 ip 4e8d75cd sp bfee3400 error 4 in libglib-2.0.so.0.2400.1[4e8b1000+c7000]
[ 1228.723953] [drm] Big FIFO is enabled
[ 2009.032007] [drm] Big FIFO is enabled
#######
Comment 1 Joshua Lock - Disabled 2010-08-25 07:07:37 UTC
I can't reproduce this with a build from recent master. Saul, can we close this bug?
Comment 2 Joshua Lock - Disabled 2010-08-25 07:09:50 UTC
Sorry, that should have been addressed at Jiajun ... I'm going to close this unless someone can tell me how to repro?
Comment 3 Jiajun Xu 2010-08-25 08:31:48 UTC
(In reply to comment #2)
> Sorry, that should have been addressed at Jiajun ... I'm going to close this
> unless someone can tell me how to repro?

OK. I will check the issue with next weekly build.
Comment 4 Dongxiao Xu 2010-08-26 18:29:46 UTC
I can reproduce this bug on netbook against the latest poky master commit e10703aa5b008e5bd4ba00606e633281759496fe.
So reopen it.
Comment 5 Jiajun Xu 2010-09-01 20:22:32 UTC
The bug still exists with 20100831 image built from autobuilder.
Comment 6 Edwin Zhai 2010-09-07 23:07:55 UTC
This bug is root caused as a bug of gcc 4.5.0, whose optimization make some code missing. 
seg fault happened @ tmp_reset_bg (gtk+-2.20.1/gdk/x11/gdkwindow-x11.c), which is inline function extended inside _gdk_x11_window_tmp_unset_bg.

This macro is the culprit:
xpixmap = GDK_DRAWABLE_XID (bg_pixmap)

and can be extended as following:

if ( GDK_IS_WINDOW (obj->bg_pixmap) )
    xpixmap =  GDK_WINDOW_XID (obj->bg_pixmap);
else 
{
    GdkDrawable *drawimpl;
    GdkDrawableImplX11 *implx11;
    Window xid;

+    __asm__ __volatile__ ("nop");

    drawimpl = ((GdkPixmapObject *)(obj->bg_pixmap))->impl;
    implx11 = GDK_DRAWABLE_IMPL_X11(drawimpl);
    xid = implx11->xid;

    xpixmap = xid;
}


We can avoid this by any of following: 1. change the "march=core2" to "march=i586" in the netbook config. 2. change tmp_reset_bg as normal function instead of static. 3. add a simple "nop" like above

The root cause is: the function call of GDK_IS_WINDOW, and some stack handling is missing after gcc's optimization. Pls. see the difference after adding a simple "nop"

   669a1:       74 2e                   je     669d1 <_gdk_x11_window_tmp_reset_bg+0x131>
   669a3:       85 d2                   test   %edx,%edx
   669a5:       74 23                   je     669ca <_gdk_x11_window_tmp_reset_bg+0x12a>
   669a7:       8b 02                   mov    (%edx),%eax
   669a9:       85 c0                   test   %eax,%eax
   669ab:       74 05                   je     669b2 <_gdk_x11_window_tmp_reset_bg+0x112>
   669ad:       3b 38                   cmp    (%eax),%edi
+  669af:       90                      nop
   669b0:       74 19                   je     669cb <_gdk_x11_window_tmp_reset_bg+0x12b>
+  669b2:       89 14 24                mov    %edx,(%esp)
+  669b5:       89 54 24 18             mov    %edx,0x18(%esp)
+  669b9:       89 7c 24 04             mov    %edi,0x4(%esp)
+  669bd:       e8 76 ce fa ff          call   13838 <g_type_check_instance_is_a@plt>
   669c2:       8b 54 24 18             mov    0x18(%esp),%edx
+  669c6:       85 c0                   test   %eax,%eax
+  669c8:       75 01                   jne    669cb <_gdk_x11_window_tmp_reset_bg+0x12b>
+  669ca:       90                      nop
   669cb:       8b 42 0c                mov    0xc(%edx),%eax
!=>669ce:       8b 68 14                mov    0x14(%eax),%ebp
   669d1:       8b 16                   mov    (%esi),%edx

"+" stands for new added instruction after "nop", and "!=>" is the instruction introduce seg fault.

We can see with "nop", $edx is saved to stack, call GDK_IS_WINDOW (<g_type_check_instance_is_a@plt>), restore $edx from stack. Then deduced $edx=>$eax=>$ebp to get the right reference.

Without "nop", the $edx is not saved to stack, but still restore it from stack with wrong value. Then $eax get the wrong value, thus seg fault...
Comment 7 Edwin Zhai 2010-09-07 23:12:12 UTC
Regarding the solution, fixing on gcc side is hard. For the following workaround:
1. change the "march=core2" to "march=i586" in the netbook config.
2. change tmp_reset_bg as normal function instead of static.
3. add a simple "nop" like above

1 is not feasible as we need core2 to support some C++ package compilation.
Both 2 & 3 seems to be ugly, but we can still use it as tmp solution for M3.
Comment 8 Saul Wold 2010-09-10 16:22:33 UTC
Fixed in Master and M3 dc29f661c3c7b95fdb875532a803a1612f46a1a1
Comment 9 Jiajun Xu 2010-09-21 09:53:25 UTC
The bug is verified as fixed in M3 testing.