<?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>12592</bug_id>
          
          <creation_ts>2018-03-08 06:20:20 +0000</creation_ts>
          <short_desc>go runtime: abi mismatch with libstd.so</short_desc>
          <delta_ts>2018-03-20 15:10:06 +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>devtools / tool chain</component>
          <version>2.4.1</version>
          <rep_platform>All</rep_platform>
          <op_sys>Multiple</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>major</bug_severity>
          <target_milestone>2.4.2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Liam Kelly">liam</reporter>
          <assigned_to name="Matt Madison">matt</assigned_to>
          <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>stephano</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Yes (doc changes required)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>79751</commentid>
    <comment_count>0</comment_count>
    <who name="Liam Kelly">liam</who>
    <bug_when>2018-03-08 06:20:20 +0000</bug_when>
    <thetext>Summary
Go applications are appearing to be linked to the instance of, not version, of the go-runtime package used during their compilation. If a go package is updated on a target but the runtime is not, then the following error appears:

`abi mismatch detected between the executable and libstd.so
fatal error: abi mismatch
runtime: panic before malloc heap initialized` 

There are two probable causes:
1) We are not version tracking all of the standard libraries and generating a new libstd.so without reflecting it in the yocto package version 
2) Go is incorrectly calculating the ABI Hash

Technical Background
In Rocko there has been a big change to how go applications are compiled. For most systems the default buildmode is now shared(-buildmode=shared). In order to implement this, first the runtime package generates `libstd.so` which contains all the standard packages in go and then the go application is linked against it and other libraries. 

Go check compatibility between the shared libraries and application by examining the ABI hash. These mechanism are detailed here.
ABI HashChecking Machanism:
https://go-review.googlesource.com/c/go/+/8773
ABI Hash GEneration:
https://go-review.googlesource.com/c/go/+/40401

I experienced this problem compiling for an ARMv7 and there is a stack overflow post concerning an x86.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79756</commentid>
    <comment_count>1</comment_count>
      <attachid>4227</attachid>
    <who name="Liam Kelly">liam</who>
    <bug_when>2018-03-08 09:24:30 +0000</bug_when>
    <thetext>Created attachment 4227
Experimental Patch to turn ABI mismatch into a warning, not an error

This patch is meant to help debug, not for production</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79757</commentid>
    <comment_count>2</comment_count>
    <who name="Liam Kelly">liam</who>
    <bug_when>2018-03-08 09:47:51 +0000</bug_when>
    <thetext>I have turned the error into a warning by patching the go-runtime source with the attached patch.

With the patch i can replace a go application and it will run (just with an the warning).

Also the problem appears to be scoped to either time or type of build:
1. I made a new image last night running `core-image-minimal`
2. I loaded the image onto my target this morning
3. I bitbaked my application. The result was the application&apos;s RPM and a go runtime RPM.
4. I installed my application rpm into the target, it ran but the patched warning appeared
5. I installed the new runtime rpm. The application ran now ran without warning, but other existing go application now gave the warning.
6. I re-bitbaked my applciation
7. I installed just the applciation rpm onto the target and there was no warning

This makes me think that
1. Either something different is happening when i compile an image vs just a package, or;
2. In the 12 hours between last night and this afternoon there was a change that was collected by the recipe that caused the ABI hash to change; and, that there was no ABI breaking changes between my two bitbake package builds (hour apart).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79762</commentid>
    <comment_count>3</comment_count>
    <who name="Liam Kelly">liam</who>
    <bug_when>2018-03-08 11:43:36 +0000</bug_when>
    <thetext>As a production work around I am defaulting to:

GO_LINKSHARED = &quot;&quot;

To stop linking against `libstd.so`</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79783</commentid>
    <comment_count>4</comment_count>
    <who name="Matt Madison">matt</who>
    <bug_when>2018-03-11 10:57:56 +0000</bug_when>
    <thetext>The ABI hash of libstd.so is the sum of the ABI hashes of the Go packages contained in the library.  Turns out there was an issue with the hash computation, specifically for cgo-generated objects - full absolute path names were getting encoded in the export data for the package, even if the package resides in GOROOT.  The Go &apos;plugin&apos; package uses cgo, so the hash of that package would change if you ran builds in different directories.

The fix for this went into Go 1.9.2.

Upstream issue: https://github.com/golang/go/issues/21825
Fix: https://go-review.googlesource.com/c/go/+/70975

My testing with this patch cherry-picked on top of the existing Go 1.9 patches we have in rocko shows that it does indeed fix the problem.  Alternatively, we could back port the go 1.9.4 recipe upgrade from master to rocko, since that would also include the fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>79885</commentid>
    <comment_count>5</comment_count>
    <who name="Matt Madison">matt</who>
    <bug_when>2018-03-20 15:10:06 +0000</bug_when>
    <thetext>The update to go 1.9.4 includes the upstream patch that fixes this issue.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>4227</attachid>
            <date>2018-03-08 09:24:30 +0000</date>
            <delta_ts>2018-03-08 09:24:30 +0000</delta_ts>
            <desc>Experimental Patch to turn ABI mismatch into a warning, not an error</desc>
            <filename>0001-allow-replacing-packages.patch</filename>
            <type>text/plain</type>
            <size>837</size>
            <attacher name="Liam Kelly">liam</attacher>
            
              <data encoding="base64">RnJvbSBlMTdkNTBhMGEyM2ZhMTVhZmZjYzc2MmY2NzI3NDRjYTdjZjBjNGZlIE1vbiBTZXAgMTcg
MDA6MDA6MDAgMjAwMQpGcm9tOiBsaWFtIDxsaWFta2VsbHlAY29tbWRldm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