golang 从源码编译记录

下载golang 源码

git clone https://github.com/golang/go.git

笔者写此博客的时候最新是go 1.10.1 版本。 源码目录 /root/source_bk/go_source/go

基本编译流程解释

go 语言编译器自1.5版本开始自举 ( 使用go编译器编译go编译器 ) 。所以最新的源码编译其实是直接使用go 编译器来编译。

嗯 所以为了编译go编译器你要先有go 编译器

所以从源码起步,编译的go编译器的方式是

  • 先编译go 1.4+版本 ( 没有自举, 使用c编译器编译)
  • 然后使用编译好的go 1.4+编译器来编译最新的源码。

编译 go 1.4.3版本

  • 切换源码到1.4.3版本

git checkout -b go143 go1.4.3

  • 编译 1.4.3 版本

cd src && ./all.bash

  • 保存go 1.4.3 版本并维护全局变量

cp -r /root/source_bk/go_source/go ~/go1.4
export GOROOT_BOOTSTRAP=~/go1.4

编译 go 1.10.1 版本

  • 切换源码到最新

git checkout master

  • 清理刚刚编译的残余

git status # 然后将新增的文件一一删除

  • 编译

cd src && ./all.bash

输出日志

从编译日志可以清晰的看出两个版本的编译区别 :)

1.4.3

输出日志如下:

# Building C bootstrap tool.
cmd/dist

# Building compilers and Go bootstrap tool for host, linux/amd64.
lib9
libbio
liblink
cmd/cc
cmd/gc
cmd/6l
cmd/6a
cmd/6c
cmd/6g
runtime
errors
sync/atomic
sync
io
unicode
unicode/utf8
unicode/utf16
bytes
math
strings
strconv
bufio
sort
container/heap
encoding/base64
syscall
time
os
reflect
fmt
encoding
encoding/json
flag
path/filepath
path
io/ioutil
log
regexp/syntax
regexp
go/token
go/scanner
go/ast
go/parser
os/exec
os/signal
net/url
text/template/parse
text/template
go/doc
go/build
cmd/go

# Building packages and commands for linux/amd64.
runtime
errors
sync/atomic
sync
io
unicode
unicode/utf8
bytes
bufio
math
syscall
time
os
strconv
reflect
fmt
strings
cmd/internal/goobj
encoding/binary
cmd/internal/rsc.io/arm/armasm
cmd/internal/rsc.io/x86/x86asm
debug/dwarf
debug/elf
debug/gosym
debug/macho
debug/pe
debug/plan9obj
sort
regexp/syntax
regexp
text/tabwriter
cmd/internal/objfile
flag
log
cmd/addr2line
hash
crypto
crypto/md5
go/token
path/filepath
go/scanner
go/ast
io/ioutil
go/parser
go/printer
os/exec
cmd/cgo
go/format
path
cmd/fix
container/heap
encoding
encoding/base64
unicode/utf16
encoding/json
encoding/xml
net/url
text/template/parse
text/template
go/doc
go/build
compress/flate
hash/crc32
compress/gzip
container/list
crypto/subtle
crypto/cipher
crypto/aes
crypto/des
math/rand
math/big
crypto/elliptic
encoding/asn1
crypto/ecdsa
crypto/hmac
internal/syscall
crypto/rand
crypto/rc4
crypto/rsa
crypto/sha1
crypto/sha256
crypto/dsa
crypto/sha512
crypto/x509/pkix
encoding/hex
encoding/pem
runtime/cgo
net
crypto/x509
crypto/tls
mime
net/textproto
mime/multipart
net/http/internal
net/http
os/signal
cmd/go
runtime/pprof
cmd/gofmt
cmd/nm
cmd/objdump
cmd/pack
cmd/pprof/internal/profile
cmd/pprof/internal/plugin
html
html/template
cmd/pprof/internal/report
cmd/pprof/internal/svg
cmd/pprof/internal/tempfile
cmd/pprof/internal/commands
cmd/pprof/internal/driver
cmd/pprof/internal/fetch
cmd/pprof/internal/symbolizer
cmd/pprof/internal/symbolz
cmd/pprof
cmd/yacc
archive/tar
archive/zip
compress/bzip2
compress/lzw
hash/adler32
compress/zlib
container/ring
database/sql/driver
database/sql
encoding/ascii85
encoding/base32
encoding/csv
encoding/gob
expvar
hash/crc64
hash/fnv
image/color
image
image/color/palette
image/draw
image/gif
image/jpeg
image/png
index/suffixarray
log/syslog
math/cmplx
net/http/cgi
net/http/cookiejar
net/http/fcgi
net/http/httptest
net/http/httputil
net/http/pprof
net/mail
net/rpc
net/rpc/jsonrpc
net/smtp
os/user
runtime/debug
runtime/race
testing
testing/iotest
testing/quick
text/scanner

# Testing packages.
ok      cmd/addr2line   0.460s
?       cmd/cgo [no test files]
ok      cmd/fix 0.013s
ok      cmd/go  0.010s
ok      cmd/gofmt   0.061s
ok      cmd/nm  0.483s
ok      cmd/objdump 1.249s
ok      cmd/pack    2.324s
?       cmd/pprof   [no test files]
?       cmd/yacc    [no test files]
ok      archive/tar 0.012s
ok      archive/zip 0.373s
ok      bufio   0.108s
ok      bytes   0.075s
ok      cmd/internal/goobj  0.003s
?       cmd/internal/objfile    [no test files]
?       cmd/pprof/internal/commands [no test files]
?       cmd/pprof/internal/driver   [no test files]
?       cmd/pprof/internal/fetch    [no test files]
?       cmd/pprof/internal/plugin   [no test files]
?       cmd/pprof/internal/profile  [no test files]
?       cmd/pprof/internal/report   [no test files]
?       cmd/pprof/internal/svg  [no test files]
?       cmd/pprof/internal/symbolizer   [no test files]
?       cmd/pprof/internal/symbolz  [no test files]
?       cmd/pprof/internal/tempfile [no test files]
ok      compress/bzip2  0.063s
ok      compress/flate  0.453s
ok      compress/gzip   0.009s
ok      compress/lzw    0.086s
ok      compress/zlib   0.967s
ok      container/heap  0.003s
ok      container/list  0.003s
ok      container/ring  0.014s
?       crypto  [no test files]
ok      crypto/aes  0.026s
ok      crypto/cipher   0.004s
ok      crypto/des  0.010s
ok      crypto/dsa  0.006s
ok      crypto/ecdsa    0.017s
ok      crypto/elliptic 0.033s
ok      crypto/hmac 0.003s
ok      crypto/md5  0.005s
ok      crypto/rand 0.024s
ok      crypto/rc4  0.087s
ok      crypto/rsa  0.139s
ok      crypto/sha1 0.004s
ok      crypto/sha256   0.004s
ok      crypto/sha512   0.004s
ok      crypto/subtle   0.005s
ok      crypto/tls  1.032s
ok      crypto/x509 0.951s
?       crypto/x509/pkix    [no test files]
ok      database/sql    0.028s
ok      database/sql/driver 0.003s
ok      debug/dwarf 0.008s
ok      debug/elf   0.021s
ok      debug/gosym 0.189s
ok      debug/macho 0.006s
ok      debug/pe    0.014s
ok      debug/plan9obj  0.003s
?       encoding    [no test files]
ok      encoding/ascii85    0.004s
ok      encoding/asn1   0.004s
ok      encoding/base32 0.004s
ok      encoding/base64 0.004s
ok      encoding/binary 0.004s
ok      encoding/csv    0.004s
ok      encoding/gob    0.048s
ok      encoding/hex    0.003s
ok      encoding/json   0.131s
ok      encoding/pem    0.003s
ok      encoding/xml    0.012s
ok      errors  0.003s
ok      expvar  0.006s
ok      flag    0.003s
ok      fmt 0.032s
ok      go/ast  0.005s
ok      go/build    0.101s
ok      go/doc  0.058s
ok      go/format   0.008s
ok      go/parser   0.027s
ok      go/printer  0.278s
ok      go/scanner  0.004s
ok      go/token    0.025s
?       hash    [no test files]
ok      hash/adler32    0.007s
ok      hash/crc32  0.003s
ok      hash/crc64  0.003s
ok      hash/fnv    0.003s
ok      html    0.004s
ok      html/template   0.031s
ok      image   0.079s
ok      image/color 0.006s
?       image/color/palette [no test files]
ok      image/draw  0.058s
ok      image/gif   0.050s
ok      image/jpeg  0.169s
ok      image/png   0.041s
ok      index/suffixarray   0.008s
?       internal/syscall    [no test files]
ok      io  0.018s
ok      io/ioutil   0.003s
ok      log 0.006s
ok      log/syslog  2.020s
ok      math    0.004s
ok      math/big    0.235s
ok      math/cmplx  0.003s
ok      math/rand   0.217s
ok      mime    0.009s
ok      mime/multipart  0.185s
ok      net 2.407s
ok      net/http    7.229s
ok      net/http/cgi    0.216s
ok      net/http/cookiejar  0.008s
ok      net/http/fcgi   0.007s
ok      net/http/httptest   0.007s
ok      net/http/httputil   0.014s
ok      net/http/internal   0.003s
?       net/http/pprof  [no test files]
ok      net/mail    0.006s
ok      net/rpc 0.016s
ok      net/rpc/jsonrpc 0.009s
ok      net/smtp    0.028s
ok      net/textproto   0.006s
ok      net/url 0.008s
ok      os  0.494s
ok      os/exec 0.163s
ok      os/signal   2.730s
ok      os/user 0.003s
ok      path    0.003s
ok      path/filepath   0.018s
ok      reflect 0.061s
ok      regexp  0.138s
ok      regexp/syntax   0.458s
ok      runtime 9.411s
?       runtime/cgo [no test files]
ok      runtime/debug   0.006s
ok      runtime/pprof   6.231s
?       runtime/race    [no test files]
ok      sort    0.063s
ok      strconv 0.234s
ok      strings 0.083s
ok      sync    0.100s
ok      sync/atomic 0.210s
ok      syscall 0.010s
ok      testing 1.109s
?       testing/iotest  [no test files]
ok      testing/quick   0.024s
ok      text/scanner    0.005s
ok      text/tabwriter  0.004s
ok      text/template   0.024s
ok      text/template/parse 0.007s
ok      time    2.456s
ok      unicode 0.004s
ok      unicode/utf16   0.003s
ok      unicode/utf8    0.005s
?       unsafe  [no test files]

real    1m51.313s
user    1m18.866s
sys 0m14.912s

# GOMAXPROCS=2 runtime -cpu=1,2,4
ok      runtime 26.290s

# sync -cpu=10
ok      sync    0.107s

# ../misc/cgo/stdio

# ../misc/cgo/life

# ../misc/cgo/test
scatter = 0x405ec0
hello from C
sqrt is: 0
PASS
ok      _/root/source_bk/go_source/go/misc/cgo/test 1.638s
scatter = 0x554650
hello from C
sqrt is: 0
PASS
ok      _/root/source_bk/go_source/go/misc/cgo/test 1.625s
scatter = 0x405ec0
hello from C
sqrt is: 0
PASS
ok      _/root/source_bk/go_source/go/misc/cgo/test 1.629s
ok      _/root/source_bk/go_source/go/misc/cgo/testtls  0.004s
ok      _/root/source_bk/go_source/go/misc/cgo/testtls  0.002s
No support for static linking found (lacks libc.a?), skip cgo static linking test.

# Testing race detector.
ok      runtime/race    0.318s
ok      flag    0.011s
ok      os/exec 0.529s

# ../misc/cgo/testgodefs

# ../misc/cgo/testso

# ../misc/cgo/testasan

# ../misc/cgo/errors

# ../doc/progs

real    0m7.386s
user    0m5.817s
sys 0m1.292s

# ../doc/articles/wiki
PASS

# ../doc/codewalk

real    0m1.413s
user    0m1.246s
sys 0m0.150s

# ../test/bench/shootout
fasta
reverse-complement
nbody
binary-tree
binary-tree-freelist
fannkuch
fannkuch-parallel
Package libpcre was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpcre.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpcre' found
regex-dna
regex-dna-parallel
spectral-norm
k-nucleotide
k-nucleotide-parallel
mandelbrot
meteor-contest
pidigits
threadring
chameneosredux

real    0m6.403s
user    0m4.665s
sys 0m0.741s

# ../test/bench/go1
ok      _/root/source_bk/go_source/go/test/bench/go1    2.316s

# ../test

real    1m18.223s
user    0m54.582s
sys 0m15.495s

# Checking API compatibility.
Skipping cmd/api checks; hg not available

real    0m0.593s
user    0m0.494s
sys 0m0.090s

ALL TESTS PASSED

---
Installed Go for linux/amd64 in /root/source_bk/go_source/go
Installed commands in /root/source_bk/go_source/go/bin
*** You need to add /root/source_bk/go_source/go/bin to your PATH.

1.10.1

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      archive/tar 0.024s
ok      archive/zip 1.350s
ok      bufio   0.041s
ok      bytes   0.581s
ok      compress/bzip2  0.050s
ok      compress/flate  0.664s
ok      compress/gzip   0.008s
ok      compress/lzw    0.006s
ok      compress/zlib   0.018s
ok      container/heap  0.006s
ok      container/list  0.001s
ok      container/ring  0.012s
ok      context 0.973s
ok      crypto  0.002s
ok      crypto/aes  0.027s
ok      crypto/cipher   0.023s
ok      crypto/des  0.006s
ok      crypto/dsa  0.003s
ok      crypto/ecdsa    0.118s
ok      crypto/elliptic 0.026s
ok      crypto/hmac 0.002s
ok      crypto/md5  0.003s
ok      crypto/rand 0.037s
ok      crypto/rc4  0.064s
ok      crypto/rsa  0.066s
ok      crypto/sha1 0.020s
ok      crypto/sha256   0.003s
ok      crypto/sha512   0.003s
ok      crypto/subtle   0.003s
ok      crypto/tls  0.784s
ok      crypto/x509 0.795s
ok      database/sql    0.545s
ok      database/sql/driver 0.001s
ok      debug/dwarf 0.012s
ok      debug/elf   0.014s
ok      debug/gosym 0.107s
ok      debug/macho 0.015s
ok      debug/pe    0.008s
ok      debug/plan9obj  0.001s
ok      encoding/ascii85    0.004s
ok      encoding/asn1   0.003s
ok      encoding/base32 0.003s
ok      encoding/base64 0.004s
ok      encoding/binary 0.002s
ok      encoding/csv    0.003s
ok      encoding/gob    0.027s
ok      encoding/hex    0.002s
ok      encoding/json   0.342s
ok      encoding/pem    0.011s
ok      encoding/xml    0.014s
ok      errors  0.001s
ok      expvar  0.003s
ok      flag    0.002s
ok      fmt 0.095s
ok      go/ast  0.003s
ok      go/build    0.084s
ok      go/constant 0.002s
ok      go/doc  0.039s
ok      go/format   0.006s
ok      go/importer 0.056s
ok      go/internal/gccgoimporter   0.007s
ok      go/internal/gcimporter  0.124s
ok      go/internal/srcimporter 0.840s
ok      go/parser   0.019s
ok      go/printer  0.270s
ok      go/scanner  0.002s
ok      go/token    0.015s
ok      go/types    0.569s
ok      hash    0.002s
ok      hash/adler32    0.005s
ok      hash/crc32  0.005s
ok      hash/crc64  0.002s
ok      hash/fnv    0.002s
ok      html    0.002s
ok      html/template   0.024s
ok      image   0.070s
ok      image/color 0.018s
ok      image/draw  0.040s
ok      image/gif   0.210s
ok      image/jpeg  0.180s
ok      image/png   0.024s
ok      index/suffixarray   0.006s
ok      internal/cpu    0.001s
ok      internal/poll   0.006s
ok      internal/singleflight   0.011s
ok      internal/trace  0.804s
ok      io  0.021s
ok      io/ioutil   0.002s
ok      log 0.003s
ok      log/syslog  2.013s
ok      math    0.003s
ok      math/big    1.538s
ok      math/bits   0.002s
ok      math/cmplx  0.002s
ok      math/rand   0.200s
ok      mime    0.004s
ok      mime/multipart  0.401s
ok      mime/quotedprintable    0.064s
ok      net 1.953s
ok      net/http    11.688s
ok      net/http/cgi    0.197s
ok      net/http/cookiejar  0.005s
ok      net/http/fcgi   0.004s
ok      net/http/httptest   0.016s
ok      net/http/httptrace  0.003s
ok      net/http/httputil   0.024s
ok      net/http/internal   0.002s
ok      net/http/pprof  2.012s
ok      net/internal/socktest   0.014s
ok      net/mail    0.004s
ok      net/rpc 0.022s
ok      net/rpc/jsonrpc 0.005s
ok      net/smtp    0.008s
ok      net/textproto   0.003s
ok      net/url 0.004s
ok      os  0.796s
ok      os/exec 0.451s
ok      os/signal   4.532s
ok      os/user 0.002s
ok      path    0.002s
ok      path/filepath   0.009s
ok      reflect 0.098s
ok      regexp  0.068s
ok      regexp/syntax   0.323s
ok      runtime 23.528s
ok      runtime/debug   0.004s
ok      runtime/internal/atomic 0.063s
ok      runtime/internal/sys    0.001s
ok      runtime/pprof   3.814s
ok      runtime/pprof/internal/profile  0.002s
ok      runtime/trace   2.628s
ok      sort    0.056s
ok      strconv 0.409s
ok      strings 0.130s
ok      sync    0.157s
ok      sync/atomic 0.015s
ok      syscall 2.283s
ok      testing 0.768s
ok      testing/quick   0.149s
ok      text/scanner    0.002s
ok      text/tabwriter  0.003s
ok      text/template   0.372s
ok      text/template/parse 0.005s
ok      time    2.534s
ok      unicode 0.002s
ok      unicode/utf16   0.001s
ok      unicode/utf8    0.003s
ok      vendor/golang_org/x/crypto/chacha20poly1305 0.282s
ok      vendor/golang_org/x/crypto/chacha20poly1305/internal/chacha20   0.001s
ok      vendor/golang_org/x/crypto/cryptobyte   0.002s
ok      vendor/golang_org/x/crypto/curve25519   0.014s
ok      vendor/golang_org/x/crypto/poly1305 0.001s
ok      vendor/golang_org/x/net/http2/hpack 0.003s
ok      vendor/golang_org/x/net/idna    0.002s
ok      vendor/golang_org/x/net/lex/httplex 0.002s
ok      vendor/golang_org/x/net/nettest 0.989s
ok      vendor/golang_org/x/net/proxy   0.003s
ok      vendor/golang_org/x/text/transform  0.001s
ok      vendor/golang_org/x/text/unicode/norm   0.002s
ok      cmd/addr2line   1.163s
ok      cmd/api 0.004s
ok      cmd/asm/internal/asm    0.220s
ok      cmd/asm/internal/lex    0.002s
ok      cmd/compile 6.203s
ok      cmd/compile/internal/gc 41.599s
ok      cmd/compile/internal/ssa    0.082s
ok      cmd/compile/internal/syntax 0.006s
ok      cmd/compile/internal/test   0.001s [no tests to run]
ok      cmd/compile/internal/types  0.002s
ok      cmd/cover   0.969s
ok      cmd/doc 0.047s
ok      cmd/fix 1.216s
ok      cmd/go  51.354s
ok      cmd/go/internal/cache   0.147s
ok      cmd/go/internal/generate    0.003s
ok      cmd/go/internal/get 0.006s
ok      cmd/go/internal/load    0.003s
ok      cmd/go/internal/work    0.007s
ok      cmd/gofmt   0.036s
ok      cmd/internal/buildid    0.146s
ok      cmd/internal/dwarf  0.002s
ok      cmd/internal/edit   0.001s
ok      cmd/internal/goobj  0.247s
ok      cmd/internal/obj    0.002s
ok      cmd/internal/obj/arm64  0.002s
ok      cmd/internal/obj/x86    0.157s
ok      cmd/internal/objabi 0.001s
ok      cmd/internal/src    0.001s
ok      cmd/internal/test2json  0.083s
ok      cmd/link    1.138s
ok      cmd/link/internal/ld    47.780s
ok      cmd/nm  1.877s
ok      cmd/objdump 1.249s
ok      cmd/pack    1.183s
ok      cmd/trace   0.006s
--- 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.016s
ok      cmd/vendor/github.com/google/pprof/internal/driver  12.494s
ok      cmd/vendor/github.com/google/pprof/internal/elfexec 0.001s
ok      cmd/vendor/github.com/google/pprof/internal/graph   0.005s
ok      cmd/vendor/github.com/google/pprof/internal/measurement 0.002s
ok      cmd/vendor/github.com/google/pprof/internal/report  0.063s
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.062s
ok      cmd/vendor/github.com/ianlancetaylor/demangle   0.014s
ok      cmd/vendor/golang.org/x/arch/arm/armasm 0.008s
ok      cmd/vendor/golang.org/x/arch/arm64/arm64asm 0.053s
ok      cmd/vendor/golang.org/x/arch/ppc64/ppc64asm 0.002s
ok      cmd/vendor/golang.org/x/arch/x86/x86asm 0.067s
ok      cmd/vet 1.872s
ok      cmd/vet/internal/cfg    0.002s
2018/04/09 23:05:31 Failed: exit status 1

你可能感兴趣的:(Golang)