Can 32-bit Go build 64-bit ports?

blov · · 595 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Does <code>GOARCH=amd64 go build</code> build the same binary when using a 32-bit port of the Go compiler, at least for pure Go programs?</p> <hr/>**评论:**<br/><br/>rmn87: <pre><p>Yep.</p></pre>jeffrallen: <pre><p>Here is the same binary built two ways. The host machine is amd64 in this case, but it wouldn&#39;t matter, you&#39;d see the same thing if the host machine was 386:</p> <pre><code>$ GOARCH=amd64 go build -o amd64 $ GOARCH=386 go build -o 386 $ ls -l 386 amd64 -rwxrwxr-x 1 jra jra 2281296 Mar 20 08:39 386 -rwxrwxr-x 1 jra jra 2814120 Mar 20 08:39 amd64 $ file 386 amd64 386: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), statically linked, not stripped amd64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped </code></pre> <p>They are not &#34;the same binary&#34;, because they are the 2 different binaries for the 2 different architectures that you are asking about. However, they are semantically the same binary, in that they are built from the same code, and are expected to implement the same semantics, even if the byte stream of instructions to the CPU differs. If they show different semantic behavior, that&#39;s a defect you can file an issue on.</p> <p>-jeff</p> <p>BTW: Remember that you can run &#34;GOARCH=xxx go install&#34; in your $GOROOT/src directory in order to speed up future builds. Otherwise, your cross-arch builds will always build the entire standard library from scratch. Same is true for cross-OS builds (i.e. using a Linux host to make Windows binaries.)</p></pre>THEHIPP0: <pre><blockquote> <p>BTW: Remember that you can run &#34;GOARCH=xxx go install&#34; in your $GOROOT/src directory in order to speed up future builds. Otherwise, your cross-arch builds will always build the entire standard library from scratch. Same is true for cross-OS builds (i.e. using a Linux host to make Windows binaries.)</p> </blockquote> <p>Or you build with <code>go build -i</code> which will cache all compiled packages until they change.</p></pre>ChristophBerger: <pre><p>I haven&#39;t tried this myself, but unless there is an open issue preventing this, it should be possible. The Go documentation <a href="https://golang.org/doc/install/source#environment" rel="nofollow">does not mention restrictions on the combination of GOOS and GOARCH values</a>. </p></pre>4ad: <pre><p>Yes, the toolchain is always a cross compiler. For pure Go packages it doesn&#39;t matter what your build system is. Only the target.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

595 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传