Go 1.5
最後更新
Go 1.5 發布於 2015-08-19,目前最新修補版為
go1.5.4,已停止支援,請升級到 go1.27.4。版本介紹
Go 1.5 是架構上的大轉折:編譯器與執行時全部改用 Go 撰寫(只剩少量組合語言),Go 從此「自己編譯自己」(bootstrapping)。同時推出並行垃圾回收器,暫停時間幾乎都壓在 10 毫秒以內;
GOMAXPROCS 預設值也從 1 改為 CPU 核心數,程式預設就能用滿多核心。語言變更
- 映射字面值(map literal)的鍵可以省略型別名稱,和切片字面值的規則一致。
工具
- C 編譯器從發行版移除,編譯器與連結器由原本的 C 程式自動翻譯成 Go;建置 Go 本身需要先有 Go 1.4 工具鏈。
- 編譯器改名為統一的
go tool compile、go tool link、go tool asm,不再依架構區分6g、8g等名稱。 internal套件規則對所有專案生效。- 實驗性支援 vendoring:設定
GO15VENDOREXPERIMENT=1後可從專案的vendor目錄讀取依賴。 - 新增
go tool trace,以視覺化方式追蹤程式執行;新增命令列用的go doc。 - 新增
-buildmode,可建置共享函式庫(shared library)等不同輸出;go test新增-count。
執行時與效能
- 新的並行垃圾回收器大部分工作與程式同時進行,「停止世界(stop the world)」階段通常遠低於 10 毫秒。
GOMAXPROCS預設為可用 CPU 核心數;goroutine 的排程順序也有改變,依賴排程順序的程式可能受影響。- 因編譯器是自動翻譯的 Go 程式碼,此版建置速度約慢了兩倍,後續版本持續改善。
標準庫重點
math/big新增任意精度浮點數型別Float。go/types套件從 x/tools 移入標準庫,提供 Go 程式的型別檢查。net的 DNS 解析在 Unix 上預設使用純 Go 實作,不需要 cgo。flag的PrintDefaults輸出格式改進;reflect新增ArrayOf、FuncOf。- 以 go-fuzz 隨機測試找出並修正了
fmt、archive/zip、html/template等數十個標準庫錯誤。
省略型別的映射字面值
鍵是結構型別時,字面值裡可以直接寫
{...},不必重複寫 Point{...};值是切片或結構時本來就能省略。- package main
- import "fmt"
- type Point struct {
- Lat, Lng float64
- }
- func main() {
- places := map[Point]string{
- {25.0330, 121.5654}: "台北 101",
- {22.6273, 120.3014}: "高雄",
- }
- fmt.Println(places[Point{25.0330, 121.5654}])
- routes := map[string][]Point{
- "north": {{25.0, 121.5}, {25.1, 121.6}},
- }
- fmt.Println(len(routes["north"]))
- }
- 台北 101
- 2
本版新增的棄用 API
以下 API 從 Go 1.5 起標記為棄用(Deprecated),新程式不要再使用;說明欄為官方原文。
| 套件 | 符號 | 官方說明 |
|---|---|---|
archive/zip | FileHeader.CompressedSize | Use CompressedSize64 instead. |
archive/zip | FileHeader.UncompressedSize | Use UncompressedSize64 instead. |
go/doc | Package.Bugs | For backward compatibility Bugs is still populated, but all new code should use Notes instead. |
image/jpeg | Reader | Reader is not used by the [image/jpeg] package and should not be used by others. It is kept for compatibility. |
syscall | FormatMessage | Use FormatMessage from golang.org/x/sys/windows instead. |
syscall | StringBytePtr | Use [BytePtrFromString] instead. |
syscall | StringByteSlice | Use ByteSliceFromString instead. |
syscall | StringSlicePtr | Use [SlicePtrFromStrings] instead. |
syscall | StringToUTF16 | Use [UTF16FromString] instead. |
syscall | StringToUTF16Ptr | Use [UTF16PtrFromString] instead. |
修補版本
| 版本 | 發布日期 | 含安全修補 | 內容(官方原文) |
|---|---|---|---|
go1.5.1 | 2015-09-08 | 否 | includes bug fixes to the compiler, assembler, and the fmt, net/textproto, net/http, and runtime packages. |
go1.5.2 | 2015-12-02 | 否 | includes bug fixes to the compiler, linker, and the mime/multipart, net, and runtime packages. |
go1.5.3 | 2016-01-13 | 是 | includes a security fix to the math/big package affecting the crypto/tls package. |
go1.5.4 | 2016-04-12 | 是 | includes two security fixes. It contains the same fixes as Go 1.6.1 and was released at the same time. |
已知漏洞
在 Go 1.5 系列修補版中修正的漏洞共 3 個;仍影響最新修補版
go1.5.4 的漏洞共 210 個。本系列已修正
| 編號 | CVE | 摘要(官方原文) | 修正於 |
|---|---|---|---|
| GO-2022-0166 | CVE-2016-3959 | Denial of service due to unchecked parameters in crypto/dsa | go1.5.4、go1.6.1 |
| GO-2021-0163 | CVE-2016-3958 | Privilege escalation on Windows via malicious DLL in syscall | go1.5.4、go1.6.1 |
| GO-2021-0160 | CVE-2015-8618 | Incorrect calculation affecting RSA computations in math/big | go1.5.3 |
本版已停止支援,不會再修正這些漏洞;完整清單見 資安漏洞。