Centos 6.x 上升级go 1.10.3

前提

目前本地Linux (Centos 6.x) 编译环境还滞留在1.8.x上,为了提升go性能,想将go升级到最新版,但在升级过程中遇到如下问题,故此记录下!忘后续的go友能跳过此坑!

问题描述

在Centos 6.x 升级go 1.10.x过程中遇到如下问题:

  • step1. 下载go 1.10.x 源码
  • step2. 解压,进入go/src
  • step3. 执行./all.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Building Go cmd/dist using /root/go1.4.
Building Go toolchain1 using /root/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.

##### Testing packages.
.... 过程略长,特此省略
ok cmd/internal/src 0.001s
ok cmd/internal/test2json 0.097s
ok cmd/link 1.988s
ok cmd/link/internal/ld 43.529s
ok cmd/nm 3.417s
ok cmd/objdump 1.588s
ok cmd/pack 1.217s
ok cmd/trace 0.007s
--- FAIL: TestObjFile (0.01s)
binutils_test.go:231: SourceLine: unexpected error write |1: broken pipe
FAIL
FAIL cmd/vendor/github.com/google/pprof/internal/binutils 0.018s
ok cmd/vendor/github.com/google/pprof/internal/driver 12.194s
ok cmd/vendor/github.com/google/pprof/internal/elfexec 0.002s
ok cmd/vendor/github.com/google/pprof/internal/graph 0.002s
ok cmd/vendor/github.com/google/pprof/internal/measurement 0.002s
ok cmd/vendor/github.com/google/pprof/internal/report 0.048s
ok cmd/vendor/github.com/google/pprof/internal/symbolizer 0.004s
ok cmd/vendor/github.com/google/pprof/internal/symbolz 0.004s
ok cmd/vendor/github.com/google/pprof/profile 0.045s
ok cmd/vendor/github.com/ianlancetaylor/demangle 0.012s
ok cmd/vendor/golang.org/x/arch/arm/armasm 0.007s
ok cmd/vendor/golang.org/x/arch/arm64/arm64asm 0.043s
ok cmd/vendor/golang.org/x/arch/ppc64/ppc64asm 0.003s
ok cmd/vendor/golang.org/x/arch/x86/x86asm 0.064s
ok cmd/vet 1.205s
ok cmd/vet/internal/cfg 0.002s
2018/07/18 17:59:22 Failed: exit status 1

问题分析

为什么在执行binutils_test.go 会Failed,最终查看代码原因是因为如下命令引起:

1
120807 3650  execve("/usr/bin/addr2line", ["/usr/bin/addr2line", "-aif", "-e", "testdata/exe_linux_64"], [/* 15 vars */] <unfinished ...>

有关生成此命令的源代码可查看如下地址:addr2line

add2line文件来自于包:binutils

执行命令失败,是因为在CentOS 6.x上,binutils的版本是2.20,参考文献 ,然后addr2line命令中的-a参数在binutils 2.21版中才添加

因此,为了解决这个问题,我从源码重新进行编译binutils并将其构建的二进制文件添加到PATH中,然后运行测试,并成功通过。

编译安装binutils过程如下:

1
2
3
4
5
6
wget https://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.gz
tar zxvf binutils-2.27.tar.gz
cd binutils-2.27
./configure --prefix=/usr
make
make install

特此说明,在Centos 7.x 上能成功避免此坑!!

-------------本文结束感谢您的阅读-------------