cmd/link: optimize init code, make it generate less asm code and make binary smaller and faster #22387
Labels
Milestone
Comments
What you are suggesting is approximately what gccgo does. There are some subtleties. For example, see #15738. And the improvement overall will be quite small. But I agree that this seems desirable if someone wants to work on it. |
I think this might have happened in d949d0b, targeting 1.13 ? |
Some of this is done in that CL. We now use data structures instead of code to record initialization tasks. It's still using recursive calls, though. The entire initialization sequence has not been serialized by the linker (and it could be, I think). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9 darwin/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/a/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/m9/qtbxkp6s3p96fk54rln7qhj80000gp/T/go-build753370285=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
https://play.golang.org/p/Ia27Pa9Gxs
What did you expect to see?
The init call tree should be ordered and flat.
The empty init functions should be remove.
main.Init direct call all init functions in the correct order(this one can be compute from import tree):
What did you see instead?
main.Init() just call strconv.init() os.init() which are defined in main package.
os.init call io.init, runtime.init, sync.init, time.init, internal/poll.init .
The panic message stack in some deep package like
runtime.init
also complex with os.init and main.Init(I just found why it is from this asm code)ps: This program import tree map from go1.9:
The text was updated successfully, but these errors were encountered: