You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is nothing to do in the main. The compiler should be intelligent enough to see that.
So the fmt package related code and the const string should be stripped from the result.
@Codefor Note that the main function is empty. The remaining code is for program initialization, including calling the initialization of "fmt". In general we cannot remove initialization of a package that's correctly imported (even if not called) because the import and associated initialization may have a (desired) side effect.
Note that though we generate the string, the linker will remove it because it is unreferenced. A bit inefficient compile-time-wise, but the generated executable is fine.
I'm going to close this, please reopen if you see something in particular that is actionable.
What version of Go are you using (
go version
)?go version go1.8 linux/amd64
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOHOSTARCH="amd64"
What did you do?
https://play.golang.org/p/lJp4vQ6f0F
What did you expect to see?
go tool compile -S b.go
There is nothing to do in the main. The compiler should be intelligent enough to see that.
So the fmt package related code and the const string should be stripped from the result.
What did you see instead?
"".main t=1 size=1 args=0x0 locals=0x0$0, $ -1
0x0000 00000 (b.go:11) TEXT "".main(SB), $0-0
0x0000 00000 (b.go:11) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (b.go:11) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (b.go:15) RET
0x0000 c3 .
"".init t=1 size=91 args=0x0 locals=0x8
0x0000 00000 (b.go:16) TEXT "".init(SB), $8-0
0x0000 00000 (b.go:16) MOVQ (TLS), CX
0x0009 00009 (b.go:16) CMPQ SP, 16(CX)
0x000d 00013 (b.go:16) JLS 84
0x000f 00015 (b.go:16) SUBQ $8, SP
0x0013 00019 (b.go:16) MOVQ BP, (SP)
0x0017 00023 (b.go:16) LEAQ (SP), BP
0x001b 00027 (b.go:16) FUNCDATA $0, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x001b 00027 (b.go:16) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x001b 00027 (b.go:16) MOVBLZX "".initdone·(SB), AX
0x0022 00034 (b.go:16) CMPB AL, $1
0x0024 00036 (b.go:16) JLS $0, 47
0x0026 00038 (b.go:16) MOVQ (SP), BP
0x002a 00042 (b.go:16) ADDQ $8, SP
0x002e 00046 (b.go:16) RET
0x002f 00047 (b.go:16) JNE $0, 56
0x0031 00049 (b.go:16) PCDATA $0, $0
0x0031 00049 (b.go:16) CALL runtime.throwinit(SB)
0x0036 00054 (b.go:16) UNDEF
0x0038 00056 (b.go:16) MOVB $1, "".initdone·(SB)
0x003f 00063 (b.go:16) PCDATA $0, $0
0x003f 00063 (b.go:16) CALL fmt.init(SB)
0x0044 00068 (b.go:16) MOVB $2, "".initdone·(SB)
0x004b 00075 (b.go:16) MOVQ (SP), BP
0x004f 00079 (b.go:16) ADDQ $8, SP
0x0053 00083 (b.go:16) RET
0x0054 00084 (b.go:16) NOP
0x0054 00084 (b.go:16) PCDATA
0x0054 00084 (b.go:16) CALL runtime.morestack_noctxt(SB)
0x0059 00089 (b.go:16) JMP 0
0x0000 64 48 8b 0c 25 00 00 00 00 48 3b 61 10 76 45 48 dH..%....H;a.vEH
0x0010 83 ec 08 48 89 2c 24 48 8d 2c 24 0f b6 05 00 00 ...H.,$H.,$.....
0x0020 00 00 3c 01 76 09 48 8b 2c 24 48 83 c4 08 c3 75 ..<.v.H.,$H....u
0x0030 07 e8 00 00 00 00 0f 0b c6 05 00 00 00 00 01 e8 ................
0x0040 00 00 00 00 c6 05 00 00 00 00 02 48 8b 2c 24 48 ...........H.,$H
0x0050 83 c4 08 c3 e8 00 00 00 00 eb a5 ...........
rel 5+4 t=16 TLS+0
rel 30+4 t=15 "".initdone·+0
rel 50+4 t=8 runtime.throwinit+0
rel 58+4 t=15 "".initdone·+-1
rel 64+4 t=8 fmt.init+0
rel 70+4 t=15 "".initdone·+-1
rel 85+4 t=8 runtime.morestack_noctxt+0
go.string."compiler should strip the code" t=8 dupok size=30
0x0000 63 6f 6d 70 69 6c 65 72 20 73 68 6f 75 6c 64 20 compiler should
0x0010 73 74 72 69 70 20 74 68 65 20 63 6f 64 65 strip the code
gclocals·33cdeccccebe80329f1fdbee7f5874cb t=8 dupok size=8
0x0000 01 00 00 00 00 00 00 00 ........
go.info."".main t=45 size=27
0x0000 02 22 22 2e 6d 61 69 6e 00 00 00 00 00 00 00 00 ."".main........
0x0010 00 00 00 00 00 00 00 00 00 01 00 ...........
rel 9+8 t=1 "".main+0
rel 17+8 t=1 "".main+1
go.info."".init t=45 size=27
0x0000 02 22 22 2e 69 6e 69 74 00 00 00 00 00 00 00 00 ."".init........
0x0010 00 00 00 00 00 00 00 00 00 01 00 ...........
rel 9+8 t=1 "".init+0
rel 17+8 t=1 "".init+91
"".initdone· t=32 size=1
type..importpath.fmt. t=8 dupok size=6
0x0000 00 00 03 66 6d 74 ...fmt
The text was updated successfully, but these errors were encountered: