<?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>14554</bug_id>
          
          <creation_ts>2021-09-17 08:06:10 +0000</creation_ts>
          <short_desc>Enhancement: go.bbclass: allow appending to -ldflags flag</short_desc>
          <delta_ts>2021-11-01 17:39:09 +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>oe-core other</component>
          <version>3.4</version>
          <rep_platform>x86</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>enhancement</bug_severity>
          <target_milestone>4.0</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ahmed Hossam">Ahmed.Hossam</reporter>
          <assigned_to name="Ahmed Hossam">Ahmed.Hossam</assigned_to>
          <cc>randy.macleod</cc>
    
    <cc>richard.purdie</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>91466</commentid>
    <comment_count>0</comment_count>
    <who name="Ahmed Hossam">Ahmed.Hossam</who>
    <bug_when>2021-09-17 08:06:10 +0000</bug_when>
    <thetext>Add a variable to allow adding extra parameters to -ldflags in the GO_LDFLAGS variable, the main usecase is setting the application version similar to https://www.digitalocean.com/community/tutorials/using-ldflags-to-set-version-information-for-go-applications

http://git.yoctoproject.org/cgit/cgit.cgi/poky/tree/meta/classes/go.bbclass?id=be665a79831c3dab7623e75d112bb35d72e39a82#n44
Current implementation:
GO_LDFLAGS ?= &apos;-ldflags=&quot;${GO_RPATH} ${GO_LINKMODE} -extldflags &apos;${GO_EXTLDFLAGS}&apos;&quot;&apos;
Suggestion:
GO_LDFLAGS ?= &apos;-ldflags=&quot;${GO_RPATH} ${GO_LINKMODE} ${GO_EXTRA_LDFLAGS} -extldflags &apos;${GO_EXTLDFLAGS}&apos;&quot;&apos;

Then in the recipe something like GO_EXTRA_LDFLAGS=&quot;-X main.Version=v1.0.0&quot; or GO_EXTRA_LDFLAGS=&quot;-X main.Version=${PV}&quot; can be used


Current workaround: append the flag to GO_LINKMODE</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91511</commentid>
    <comment_count>1</comment_count>
    <who name="Richard Purdie">richard.purdie</who>
    <bug_when>2021-09-23 13:38:20 +0000</bug_when>
    <thetext>Can&apos;t you use GO_LDFLAGS:append = &quot;xxx&quot; for this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91522</commentid>
    <comment_count>2</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2021-09-23 14:39:02 +0000</bug_when>
    <thetext>Ahmen, does Richard&apos;s suggestion work for you? If so please close this enhancement.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91525</commentid>
    <comment_count>3</comment_count>
    <who name="Ahmed Hossam">Ahmed.Hossam</who>
    <bug_when>2021-09-23 14:49:57 +0000</bug_when>
    <thetext>Unfortunately it doesn&apos;t work.

The goal is to add parameters inside the &apos;-ldflags&apos; quote, I tried using your suggestion using:
GO_LDFLAGS:append = &apos; -ldflags=&quot;-X main.Version=v1.0.0&quot;&apos;
Which would result in
GO_LDFLAGS = &apos;-ldflags=&quot;${GO_RPATH} ${GO_LINKMODE} -extldflags &apos;${GO_EXTLDFLAGS}&apos;&quot; -ldflags=&quot;-X main.Version=v1.0.0&quot;&apos;
But that overrode the previous &apos;-ldflags&apos; content, breaking qa

You can try this by adding
GO_LDFLAGS:append = &apos; -ldflags=&quot;-X main.Version=v1.0.0&quot;&apos;
to the end of poky/meta/recipes-extended/go-examples/go-helloworld_0.1.bb and building &quot;bitbake go-helloworld&quot;, it will result in qa failures (do_package_qa)

That is why I am suggesting to add a variable *inside* the &apos;-ldflags&apos; quote, i.e. to result in:
GO_LDFLAGS = &apos;-ldflags=&quot;${GO_RPATH} ${GO_LINKMODE} -X main.Version=v1.0.0 -extldflags &apos;${GO_EXTLDFLAGS}&apos;&quot;&apos;
with one occurence of &apos;-ldflags&apos;
Maybe someone with better go linker understanding can share a better solution.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91637</commentid>
    <comment_count>4</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2021-09-30 15:17:17 +0000</bug_when>
    <thetext>Ahmed, can you send the patch to the list?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91827</commentid>
    <comment_count>5</comment_count>
    <who name="Ahmed Hossam">Ahmed.Hossam</who>
    <bug_when>2021-10-26 19:07:05 +0000</bug_when>
    <thetext>Sent: https://lists.openembedded.org/g/openembedded-core/message/157449</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91870</commentid>
    <comment_count>6</comment_count>
    <who name="Ahmed Hossam">Ahmed.Hossam</who>
    <bug_when>2021-11-01 10:50:06 +0000</bug_when>
    <thetext>Hey Randy, do I need to assign the bug to someone for integration?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91871</commentid>
    <comment_count>7</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2021-11-01 17:39:09 +0000</bug_when>
    <thetext>Hi Ahmen,

Thanks for sending the patch to the list. It can take a while for changes to make it through our QA process and when we are doing a release for 3.4 which was going on last week, it can take even longer. 

You patch is merged now though:

https://git.openembedded.org/openembedded-core/commit/?id=eaa7a61dab9a1d7bb039f16abdd9aacb44faa595

so I&apos;ve marked this issue as resolved/fixed.

Thanks!</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>