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

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>1443</bug_id>
          
          <creation_ts>2011-09-01 20:29:56 +0000</creation_ts>
          <short_desc>segfault of lttng-ust applications in qemuarm: caused by prelink: on x86-64 Ubuntu host</short_desc>
          <delta_ts>2012-10-25 15:00:17 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>core</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>arm</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>1.3</target_milestone>
          
          <blocked>2577</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Lianhao Lu">lianhao.lu</reporter>
          <assigned_to name="Mark Hatle">mark.hatle</assigned_to>
          <cc>andrei.adrianx.dinu</cc>
    
    <cc>dexuan.cui</cc>
    
    <cc>jessica.zhang</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>raj.khem</cc>
    
    <cc>richard.purdie</cc>
    
    <cc>sgw</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>---</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>15959</commentid>
    <comment_count>0</comment_count>
      <attachid>223</attachid>
    <who name="Lianhao Lu">lianhao.lu</who>
    <bug_when>2011-09-01 20:29:56 +0000</bug_when>
    <thetext>Created attachment 223
source code of the test application

Tree/Branch: poky/master
Commit: dfce2695b96ab587b8235cfab2859a874e9d2eef

Using the core-image-sato-sdk image of qemuarm, the attached lttng-ust demo application would result a segmentation fault in the target.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16002</commentid>
    <comment_count>1</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2011-09-03 23:01:39 +0000</bug_when>
    <thetext>I can&apos;t reproduce the issue when I built the arm sato-sdk image on Ubuntu 11.04 x86-64 host using 

OE Build Configuration:
BB_VERSION        = &quot;1.13.3&quot;
TARGET_ARCH       = &quot;arm&quot;
TARGET_OS         = &quot;linux-gnueabi&quot;
MACHINE           = &quot;qemuarm&quot;
DISTRO            = &quot;poky&quot;
DISTRO_VERSION    = &quot;1.0+snapshot-20110904&quot;
TUNE_FEATURES     = &quot;armv5 dsp thumb arm926ejs&quot;
TARGET_FPU        = &quot;soft&quot;
meta
meta-yocto        = &quot;master:de5d52711bd810a63a0ad5260b799d6672952c32&quot;


However, autobuilder&apos;s arm sato-sdk image at http://autobuilder.yoctoproject.org/pub/nightly/20110903-1/machines/qemuarm/ does have this bug...

This is somewhat weird...</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16013</commentid>
    <comment_count>2</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2011-09-04 23:47:38 +0000</bug_when>
    <thetext>(In reply to comment #1)
&gt; I can&apos;t reproduce the issue when I built the arm sato-sdk image on Ubuntu 11.04
&gt; x86-64 host using 
&gt; 
Now I can reproduce the issue using x86-64 Ubuntu 10.10 host.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16107</commentid>
    <comment_count>3</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2011-09-08 17:30:50 +0000</bug_when>
    <thetext>(In reply to comment #2)
&gt; (In reply to comment #1)
&gt; &gt; I can&apos;t reproduce the issue when I built the arm sato-sdk image on Ubuntu 11.04
&gt; &gt; x86-64 host using 
&gt; &gt; 
&gt; Now I can reproduce the issue using x86-64 Ubuntu 10.10 host.

Looks the issue only happens on qemuarm.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16207</commentid>
    <comment_count>4</comment_count>
    <who name="Lianhao Lu">lianhao.lu</who>
    <bug_when>2011-09-14 23:23:37 +0000</bug_when>
    <thetext>This seems to be related to prelink. If I remove prelink from USER_CLASSES in local.conf, the problem seems gone.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16209</commentid>
    <comment_count>5</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2011-09-15 00:51:49 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; This seems to be related to prelink. If I remove prelink from USER_CLASSES in
&gt; local.conf, the problem seems gone.

Yes. I&apos;ve the same phenomenon: removing image-prelink from USER_CLASSES makes the segfault go.
(Previously I thought I couldn&apos;t reproduce it with Ubuntu11.04 -- actually it&apos;s because I disabled image-prelink by chance)

So looks Mark could help to look into this bug. :-)


BTW: looks the fix to bug 1473 may not help here since this bug happens to x86-64 host while bug 1473 happens on x86-32 host.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16219</commentid>
    <comment_count>6</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2011-09-15 07:27:58 +0000</bug_when>
    <thetext>I had a report of a similar bug with QT on arm.  The fix for 1473 also resolved the issue w/ QT on arm.

Please try the latest version of prelink and see if it corrects the issue(s) you have had.  If it does not, I can look at investigating it further.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16220</commentid>
    <comment_count>7</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2011-09-15 08:14:25 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; I had a report of a similar bug with QT on arm.  The fix for 1473 also resolved
&gt; the issue w/ QT on arm.
&gt; 
&gt; Please try the latest version of prelink and see if it corrects the issue(s)
&gt; you have had.  If it does not, I can look at investigating it further.

Hi Mark,
I tried the fix for 1743 (http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=90ded12e485657f776fa9dac6567c9c84c28fa63), but still got the this bug. :-(

A simpler way to reproduce the issue:
On x86-64 Ubuntu host(e.g., 11.04 or 10.04), bitbake core-image-sato-sdk with MACHINE ?= &quot;qemuarm&quot; and USER_CLASSES ?= &quot;image-prelink&quot;.
later, run &quot;runqemu qemuarm core-image-sato-sdk&quot; to boot into target; in the target, gcc test.c -l ust &amp;&amp; ./a.out, and you would see a segfault.

The test.c is a simple C program: int main() { return 0; }.


And, removing image-prelink from USER_CLASSES can make the segfault disappear.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16221</commentid>
    <comment_count>8</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2011-09-15 08:16:17 +0000</bug_when>
    <thetext>(In reply to comment #7)
&gt; (In reply to comment #6)
&gt; &gt; I had a report of a similar bug with QT on arm.  The fix for 1473 also resolved
&gt; &gt; the issue w/ QT on arm.
&gt; &gt; 
&gt; &gt; Please try the latest version of prelink and see if it corrects the issue(s)
&gt; &gt; you have had.  If it does not, I can look at investigating it further.
&gt; 
&gt; Hi Mark,
&gt; I tried the fix for 1743
Sorry for the typo: I meant 1473.
&gt; (http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=90ded12e485657f776fa9dac6567c9c84c28fa63),
&gt; but still got the this bug. :-(</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16264</commentid>
    <comment_count>9</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2011-09-16 09:02:13 +0000</bug_when>
    <thetext>From talking with some ust folks at Wind River, they indicated that in past versions there have been issues with ust, linker scripts and prelinking.

I do not know if this has anything to do with the current failure, but it&apos;s something known to be an issue in the past.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>16316</commentid>
    <comment_count>10</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2011-09-20 08:18:54 +0000</bug_when>
    <thetext>We likely need to release with this defect.  In the past problems like this have been in the linker or the linker scripts used by UST.

I doubt we will have the ability to fully diagnose a resolve this issue prior to the release, so the workaround of avoiding the prelinker should be appropriate for the release.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>17929</commentid>
    <comment_count>11</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2012-01-03 10:31:05 +0000</bug_when>
    <thetext>A number of changes have occurred in the prelink which may resolve this issue.  It should be retested.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>17967</commentid>
    <comment_count>12</comment_count>
    <who name="Dexuan Cui">dexuan.cui</who>
    <bug_when>2012-01-04 20:54:47 +0000</bug_when>
    <thetext>(In reply to comment #11)
&gt; A number of changes have occurred in the prelink which may resolve this issue. 
&gt; It should be retested.

Hi Mark,
I re-tested the bug based on today&apos;s poky master (commit 021848be9eeb71de8acfba6c66c11645b01523b8) and still got the same issue... :-(

If I remove &quot;image-prelink&quot; from USER_CLASSES, there is no issue.

So I think the bug is still there.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>21189</commentid>
    <comment_count>13</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2012-05-08 15:38:04 +0000</bug_when>
    <thetext>Estimate assumes significant debugging time is required.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>23537</commentid>
    <comment_count>14</comment_count>
    <who name="Mark Hatle">mark.hatle</who>
    <bug_when>2012-07-26 18:41:16 +0000</bug_when>
    <thetext>Progress has finally been made on this issue.  The following is an explanation of the problem from Donn Seeley:

I spent about a day and a half on this one, and I figured out what&apos;s
going on.  The quick summary:  It&apos;s an ARM libc bug that involves
both TLS (thread-local storage) and prelinking.  It should be extremely
rare.  The fix looks really simple.

The Yocto bug log makes this defect sound like it&apos;s fairly general, but
it&apos;s not.  It&apos;s actually pretty specific to ARM and to the usermode-rcu
package, which ust uses.  Here is what appears to be
happening:

  We build some random program and link it with -lust.  When we run it,
  it dies with a SIGSEGV before reaching main().

  Libust.so depends on liburcu-bp.so from the usermode-rcu package.
  Although libust.so is not prelinked, liburcu-bp.so IS prelinked; this
  is critical.

  Libust.so uses a TLS / __thread variable that is defined in liburcu-
  bp.so.  There are special ARM-specific relocation types that allow two
  shared libraries to share thread-specific data.  This is critical too.

  One more critical issue: although liburcu-bp.so is prelinked, we can&apos;t
  load it at its prelinked address, because we also link against
  librt.so, and librt.so uses that address.

  The dynamic linker is forced to relink liburcu-bp.so at a different
  address.  In the course of relinking, it processes the special ARM
  relocation record mentioned above.  The prelinker has already filled
  in the information, which is a short offset into a table of thread-
  specific data that is allocated per-thread for each library that uses
  TLS.  Because the normal behavior of a relocation is to add the symbol
  value to an addend stored at the address being relocated, we end up
  adding the short offset to itself, doubling it.

  Now we have an awkward situation.  The libust.so library doesn&apos;t know
  about the addend, so its TLS data for this element is correct.  The
  liburcu-bp.so library has a different offset for the element.  When we
  go to initialize the element for the first time in liburcu-bp.so, we
  write the address of the result at the doubled (broken) offset.
  Later, when we refer to the address from libust.so, we check the value
  at the correct offset, but it&apos;s NULL, so we eat hot SIGSEGV.

The fix looks like it would pretty simple.  Instead of doing:

        case R_ARM_TLS_DTPOFF32:
          if (sym != NULL)
            *reloc_addr += sym-&gt;st_value;
          break;

... we really want to do:

        case R_ARM_TLS_DTPOFF32:
          if (sym != NULL)
            *reloc_addr = sym-&gt;st_value;
          break;

This allows us to ignore any addend when we re-link a prelinked library.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>25589</commentid>
    <comment_count>15</comment_count>
    <who name="Andrei Dinu">andrei.adrianx.dinu</who>
    <bug_when>2012-09-24 11:31:44 +0000</bug_when>
    <thetext>The fix suggestion worked for solving bug 2577 on qemuarm-sdk.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>26911</commentid>
    <comment_count>16</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2012-10-25 15:00:17 +0000</bug_when>
    <thetext>Fix applied in http://git.yoctoproject.org/cgit.cgi/poky/commit/?id=e1913fbb01af52feee74bd6ab239678211c7ebb2</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>223</attachid>
            <date>2011-09-01 20:29:56 +0000</date>
            <delta_ts>2011-09-01 20:29:56 +0000</delta_ts>
            <desc>source code of the test application</desc>
            <filename>lttng.c</filename>
            <type>text/plain</type>
            <size>227</size>
            <attacher name="Lianhao Lu">lianhao.lu</attacher>
            
              <data encoding="base64">I2luY2x1ZGUgPHVzdC9tYXJrZXIuaD4KCmludCBtYWluKGludCBhcmdjLCBjaGFyICoqYXJndikK
ewogIGludCB2PTY7CiAgY2hhciAqc3Q9Imx0dG5nIGV4YW1wbGUiOwoKICB0cmFjZV9tYXJrKG1h
aW4sIG15ZXZlbnQsICJmaXJzdGFyZyAlZCBzZWNvbmRhcmcgJXMiLCB2LCBzdCk7CgogIHRyYWNl
X21hcmsobWFpbiwgbXlvdGhlcmV2ZW50LCBNQVJLX05PQVJHUyk7CgogIHJldHVybiAwOwoKfQo=
</data>

          </attachment>
      

    </bug>

</bugzilla>