# Go 1.3

Go 1.3 發布於 2014-06-18，目前最新修補版為 `go1.3.3`，**已停止支援**，請升級到 `go1.27.4`。

## 版本介紹

Go 1.3 沒有語言變更，重心在實作：goroutine 堆疊改為連續堆疊（contiguous stack），垃圾回收器對堆疊上的值也變得精確，編譯器工具鏈重構讓大型專案建置更快。標準庫則新增了至今仍常用的 `sync.Pool`。

### 工具

- 連結器的指令選擇階段移到編譯器（liblink），大型專案的建置速度明顯提升。
- `go test` 搭配 `-race` 時，覆蓋率模式自動設為 `atomic`；沒有測試檔的套件也會被建置。
- 支援啟用 cgo 的交叉編譯，`go run`、`go test` 新增 `-exec` 選項。
- `godoc` 新增 `-analysis` 靜態分析功能。

### 執行時與效能

- goroutine 堆疊從「分段」改為「連續」：空間不夠時整段搬到更大的記憶體，消除在分段邊界反覆切換的效能熱點。
- 垃圾回收器在掃描堆疊時也變精確，整數不會再被誤認為指標而讓記憶體無法回收。
- 小映射（8 個元素以下）的走訪順序重新隨機化，揪出依賴走訪順序的錯誤程式。
- 垃圾回收改用並行清掃（concurrent sweep），暫停時間可減少 50%–70%；`defer` 的記憶體開銷降低。
- 記憶體模型（memory model）補充說明：有緩衝的通道（channel）可以當作簡單的號誌（semaphore）使用。

### 標準庫重點

- 新增 `sync.Pool`，可重複利用暫時物件、減輕垃圾回收負擔。
- `testing.B` 新增 `RunParallel`，方便撰寫多 CPU 並行的基準測試。
- `crypto/tls` 修正可能意外略過憑證驗證的錯誤：必須設定 `ServerName` 或 `InsecureSkipVerify`。
- `regexp` 對簡單的表達式加入一次通過（one-pass）引擎，速度明顯提升。

### sync.Pool

`sync.Pool` 像一個「暫存物件回收箱」：用完的物件放回去，下次 `Get` 時可能直接拿到它，省下重新配置。池裡的物件可能隨時被垃圾回收清掉，所以只適合放可以隨時重建的暫存物件，取出後也要先重設狀態。範例中的 `any` 是 Go 1.18 起 `interface{}` 的別名。

```go
package main

import (
	"bytes"
	"fmt"
	"sync"
)

var bufPool = sync.Pool{
	New: func() any {
		return new(bytes.Buffer)
	},
}

func render(name string) string {
	buf := bufPool.Get().(*bytes.Buffer)
	buf.Reset()
	defer bufPool.Put(buf)

	buf.WriteString("hello, ")
	buf.WriteString(name)
	return buf.String()
}

func main() {
	fmt.Println(render("gopher"))
	fmt.Println(render("pool"))
}
```

```text
hello, gopher
hello, pool
```

## 本版新增的棄用 API

本版沒有新增棄用 API。

## 修補版本

| 版本 | 發布日期 | 含安全修補 | 內容（官方原文） |
| --- | --- | --- | --- |
| `go1.3.1` | 2014-08-13 | 否 | includes bug fixes to the compiler and the runtime, net, and crypto/rsa packages. |
| `go1.3.2` | 2014-09-25 | 是 | includes security fixes to the crypto/tls package and bug fixes to cgo. |
| `go1.3.3` | 2014-09-30 | 否 | includes further bug fixes to cgo, the runtime package, and the nacl port. |

## 已知漏洞

在 Go 1.3 系列修補版中修正的漏洞共 1 個；仍影響最新修補版 `go1.3.3` 的漏洞共 213 個。

### 本系列已修正

| 編號 | CVE | 摘要（官方原文） | 修正於 |
| --- | --- | --- | --- |
| [GO-2021-0154](https://pkg.go.dev/vuln/GO-2021-0154) | CVE-2014-7189 | Man-in-the-middle attack with SessionTicketsDisabled in crypto/tls | go1.3.2 |

本版已停止支援，不會再修正這些漏洞；完整清單見 [資安漏洞](/security)。


## 資料來源

- [Go 1.3 Release Notes](https://go.dev/doc/go1.3)
- [Go 發版歷史](https://go.dev/doc/devel/release#go1.3)
- [Go 漏洞資料庫](https://vuln.go.dev)
- [golang/go 原始碼 go1.3](https://github.com/golang/go/tree/go1.3)
