# 10.3 导出对象文件

将编译结果导出为对象文件是编译的最后一步，该文件是编译器的输出，链接器的输入。该逻辑在编译器主函数的尾部：

```go
// file: cmd/compile/internal/gc/main.go

func Main() {
    // 忽略之前代码

    // 导出编译结果到磁盘
    base.Timer.Start("be", "dumpobj")
    dumpdata()
    base.Ctxt.NumberSyms()
    dumpobj()
    if base.Flag.AsmHdr != "" {
        dumpasmhdr()
    }
}
```

可以通过编译参数 `-o` 指定导出的文件名，默认情况下与编译的文件名或包名一致。例如将下列内容保存为 `main.go`:

```go
package main

func sum(i, j int) int {
    return i + j
}
```

通过命令 `go tool compile -G=3 main.go` 得到编译输出文件 `main.o`.

对于编译得到的结果，可以通过命令 `go tool objdump` 查看，使用 `go tool objdump main.o` 可以得到如下结果：

> ```
> TEXT “”.sum(SB) 
> main.go:4		0x2fa			488b442410		MOVQ 0x10(SP), AX	
> main.go:4		0x2ff			488b4c2408		MOVQ 0x8(SP), CX	
> main.go:4		0x304			4801c8			ADDQ CX, AX		
> main.go:4		0x307			4889442418		MOVQ AX, 0x18(SP)	
> main.go:4		0x30c			c3			RET
> ```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gocompiler.shizhz.me/10.-golang-bian-yi-qi-han-shu-bian-yi-ji-dao-chu/10.3-dao-chu-dui-xiang-wen-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
