<p>I recently posted a question on stack overflow, but haven't gotten an answer.</p>
<p>The question is, given a simple Go program like this:</p>
<pre><code>package main
func add(a, b int) int {
return a + b
}
func main () {
add(1,2)
}
</code></pre>
<p>How would I translate it to assembly using the command line tools?</p>
<p>So far, I found two possible commands. Namely:</p>
<pre><code>go tool compile -S file.go > file.S
</code></pre>
<p>And</p>
<pre><code>go tool objdump executable > disassembly
</code></pre>
<p>But both of them produce different outputs so I'm not sure If I'm doing this right.</p>
<p>Is there a better way to do this?</p>
<p>EDIT:</p>
<p>I found this command on the Go website which prints out assembly when compiling (for the same architecture):</p>
<pre><code>go build -gcflags -S file.go
</code></pre>
<p>This seems to do the trick.</p>
<hr/>**评论:**<br/><br/>Shepsauce: <pre><p>My understanding of why the outputs are different would be:
1. The compile -S will show you the assembly of that particular file all by itself.
2. The objdump tool shows references to the line numbers of the original code for what is executing.
3. You have to create an object file for objdump to work on, and that has everything you've imported linked into the file, so the total assembly should be longer.</p></pre>Ptcdln: <pre><p>Thanks, it does seem like using the <code>objdump</code> command on an executable prints out everything that was compiled. Including the built-in functions and libraries used.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传