New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/link: optimize init code, make it generate less asm code and make binary smaller and faster #22387

bronze1man opened this Issue Oct 23, 2017 · 1 comment


None yet
2 participants

bronze1man commented Oct 23, 2017

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?


What operating system and processor architecture are you using (go env)?

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"

What did you do?

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)

TEXT os.init(SB) <autogenerated>
  <autogenerated>:1		0x1063dc0		65488b0c25a0080000	MOVQ GS:0x8a0, CX			
  <autogenerated>:1		0x1063dc9		483b6110		CMPQ 0x10(CX), SP			
  <autogenerated>:1		0x1063dcd		0f861a040000		JBE 0x10641ed				
  <autogenerated>:1		0x1063dd3		4883ec38		SUBQ $0x38, SP				
  <autogenerated>:1		0x1063dd7		48896c2430		MOVQ BP, 0x30(SP)			
  <autogenerated>:1		0x1063ddc		488d6c2430		LEAQ 0x30(SP), BP			
  <autogenerated>:1		0x1063de1		0fb605dec50800		MOVZX 0x8c5de(IP), AX			
  <autogenerated>:1		0x1063de8		3c01			CMPL $0x1, AL				
  <autogenerated>:1		0x1063dea		760a			JBE 0x1063df6				
  <autogenerated>:1		0x1063dec		488b6c2430		MOVQ 0x30(SP), BP			
  <autogenerated>:1		0x1063df1		4883c438		ADDQ $0x38, SP				
  <autogenerated>:1		0x1063df5		c3			RET					
  <autogenerated>:1		0x1063df6		7507			JNE 0x1063dff				
  <autogenerated>:1		0x1063df8		e803fafbff		CALL runtime.throwinit(SB)		
  <autogenerated>:1		0x1063dfd		0f0b			UD2					
  <autogenerated>:1		0x1063dff		c605c0c5080001		MOVB $0x1, 0x8c5c0(IP)			
  <autogenerated>:1		0x1063e06		e8e503ffff		CALL io.init(SB)			
  <autogenerated>:1		0x1063e0b		e86069feff		CALL runtime.init(SB)			
  <autogenerated>:1		0x1063e10		e86b31ffff		CALL syscall.init(SB)			
  <autogenerated>:1		0x1063e15		e82603ffff		CALL sync.init(SB)			
  <autogenerated>:1		0x1063e1a		e8f1abffff		CALL time.init(SB)			
  <autogenerated>:1		0x1063e1f		e81cccffff		CALL internal/poll.init(SB)		
  <autogenerated>:1		0x1063e24		488d054c410200		LEAQ 0x2414c(IP), AX			
  error.go:13			0x1063e2b		48890424		MOVQ AX, 0(SP)				
  error.go:13			0x1063e2f		48c744240810000000	MOVQ $0x10, 0x8(SP)			
  error.go:13			0x1063e38		e8a3f1feff		CALL errors.New(SB)			
  error.go:13			0x1063e3d		488b442418		MOVQ 0x18(SP), AX			
  error.go:13			0x1063e42		488b4c2410		MOVQ 0x10(SP), CX			
  error.go:13			0x1063e47		48890d52e20600		MOVQ CX, 0x6e252(IP)			
  error.go:13			0x1063e4e		8b0dacc70800		MOVL 0x8c7ac(IP), CX			
  error.go:13			0x1063e54		85c9			TESTL CX, CX				
  error.go:13			0x1063e56		0f8577030000		JNE 0x10641d3				
  error.go:13			0x1063e5c		48890545e20600		MOVQ AX, 0x6e245(IP)			
  error.go:13			0x1063e63		488d058f430200		LEAQ 0x2438f(IP), AX			
  error.go:14			0x1063e6a		48890424		MOVQ AX, 0(SP)				
  error.go:14			0x1063e6e		48c744240811000000	MOVQ $0x11, 0x8(SP)			
  error.go:14			0x1063e77		e864f1feff		CALL errors.New(SB)			
  error.go:14			0x1063e7c		488b442418		MOVQ 0x18(SP), AX			
  error.go:14			0x1063e81		488b4c2410		MOVQ 0x10(SP), CX			
  error.go:14			0x1063e86		48890d33e20600		MOVQ CX, 0x6e233(IP)			
  error.go:14			0x1063e8d		8b0d6dc70800		MOVL 0x8c76d(IP), CX			
  error.go:14			0x1063e93		85c9			TESTL CX, CX				
  error.go:14			0x1063e95		0f851e030000		JNE 0x10641b9				
  error.go:14			0x1063e9b		48890526e20600		MOVQ AX, 0x6e226(IP)			
  error.go:14			0x1063ea2		488d05cd460200		LEAQ 0x246cd(IP), AX			
  error.go:15			0x1063ea9		48890424		MOVQ AX, 0(SP)				
  error.go:15			0x1063ead		48c744240813000000	MOVQ $0x13, 0x8(SP)			
  error.go:15			0x1063eb6		e825f1feff		CALL errors.New(SB)			
  error.go:15			0x1063ebb		488b442410		MOVQ 0x10(SP), AX			
  error.go:15			0x1063ec0		488b4c2418		MOVQ 0x18(SP), CX			
  error.go:15			0x1063ec5		488905c4e10600		MOVQ AX, 0x6e1c4(IP)			
  error.go:15			0x1063ecc		8b052ec70800		MOVL 0x8c72e(IP), AX			
  error.go:15			0x1063ed2		85c0			TESTL AX, AX				
  error.go:15			0x1063ed4		0f85c5020000		JNE 0x106419f				
  error.go:15			0x1063eda		48890db7e10600		MOVQ CX, 0x6e1b7(IP)			
  error.go:15			0x1063ee1		488d05a1460200		LEAQ 0x246a1(IP), AX			
  error.go:16			0x1063ee8		48890424		MOVQ AX, 0(SP)				
  error.go:16			0x1063eec		48c744240813000000	MOVQ $0x13, 0x8(SP)			
  error.go:16			0x1063ef5		e8e6f0feff		CALL errors.New(SB)			
  error.go:16			0x1063efa		488b442410		MOVQ 0x10(SP), AX			
  error.go:16			0x1063eff		488b4c2418		MOVQ 0x18(SP), CX			
  error.go:16			0x1063f04		488905a5e10600		MOVQ AX, 0x6e1a5(IP)			
  error.go:16			0x1063f0b		8b05efc60800		MOVL 0x8c6ef(IP), AX			
  error.go:16			0x1063f11		85c0			TESTL AX, AX				
  error.go:16			0x1063f13		0f856c020000		JNE 0x1064185				
  error.go:16			0x1063f19		48890d98e10600		MOVQ CX, 0x6e198(IP)			
  error.go:16			0x1063f20		488d053c460200		LEAQ 0x2463c(IP), AX			
  error.go:17			0x1063f27		48890424		MOVQ AX, 0(SP)				
  error.go:17			0x1063f2b		48c744240813000000	MOVQ $0x13, 0x8(SP)			
  error.go:17			0x1063f34		e8a7f0feff		CALL errors.New(SB)			
  error.go:17			0x1063f39		488b442410		MOVQ 0x10(SP), AX			
  error.go:17			0x1063f3e		488b4c2418		MOVQ 0x18(SP), CX			
  error.go:17			0x1063f43		48890536e10600		MOVQ AX, 0x6e136(IP)			
  error.go:17			0x1063f4a		8b05b0c60800		MOVL 0x8c6b0(IP), AX			
  error.go:17			0x1063f50		85c0			TESTL AX, AX				
  error.go:17			0x1063f52		0f8513020000		JNE 0x106416b				
  error.go:17			0x1063f58		48890d29e10600		MOVQ CX, 0x6e129(IP)			
  error.go:17			0x1063f5f		488d05a55d0200		LEAQ 0x25da5(IP), AX			
  exec_unix.go:53		0x1063f66		48890424		MOVQ AX, 0(SP)				
  exec_unix.go:53		0x1063f6a		48c74424081c000000	MOVQ $0x1c, 0x8(SP)			
  exec_unix.go:53		0x1063f73		e868f0feff		CALL errors.New(SB)			
  exec_unix.go:53		0x1063f78		488b442410		MOVQ 0x10(SP), AX			
  exec_unix.go:53		0x1063f7d		488b4c2418		MOVQ 0x18(SP), CX			
  exec_unix.go:53		0x1063f82		48890547e10600		MOVQ AX, 0x6e147(IP)			
  exec_unix.go:53		0x1063f89		8b0571c60800		MOVL 0x8c671(IP), AX			
  exec_unix.go:53		0x1063f8f		85c0			TESTL AX, AX				
  exec_unix.go:53		0x1063f91		0f85ba010000		JNE 0x1064151				
  exec_unix.go:53		0x1063f97		48890d3ae10600		MOVQ CX, 0x6e13a(IP)			
  executable_darwin.go:9	0x1063f9e		e80de6ffff		CALL os.Getwd(SB)			
  executable_darwin.go:9	0x1063fa3		488b0424		MOVQ 0(SP), AX				
  executable_darwin.go:9	0x1063fa7		488b4c2408		MOVQ 0x8(SP), CX			
  executable_darwin.go:9	0x1063fac		488b542410		MOVQ 0x10(SP), DX			
  executable_darwin.go:9	0x1063fb1		488b5c2418		MOVQ 0x18(SP), BX			
  executable_darwin.go:9	0x1063fb6		48890d3be10600		MOVQ CX, 0x6e13b(IP)			
  executable_darwin.go:9	0x1063fbd		8b0d3dc60800		MOVL 0x8c63d(IP), CX			
  executable_darwin.go:9	0x1063fc3		85c9			TESTL CX, CX				
  executable_darwin.go:9	0x1063fc5		0f8558010000		JNE 0x1064123				
  executable_darwin.go:9	0x1063fcb		4889051ee10600		MOVQ AX, 0x6e11e(IP)			
  executable_darwin.go:9	0x1063fd2		48891527e10600		MOVQ DX, 0x6e127(IP)			
  executable_darwin.go:9	0x1063fd9		8b0521c60800		MOVL 0x8c621(IP), AX			
  executable_darwin.go:9	0x1063fdf		85c0			TESTL AX, AX				
  executable_darwin.go:9	0x1063fe1		0f8522010000		JNE 0x1064109				
  executable_darwin.go:9	0x1063fe7		48891d1ae10600		MOVQ BX, 0x6e11a(IP)			
  file.go:56			0x1063fee		488b05bbc50800		MOVQ 0x8c5bb(IP), AX			
  file.go:56			0x1063ff5		48890424		MOVQ AX, 0(SP)				
  file.go:56			0x1063ff9		488d0524350200		LEAQ 0x23524(IP), AX			
  file.go:56			0x1064000		4889442408		MOVQ AX, 0x8(SP)			
  file.go:56			0x1064005		48c74424100a000000	MOVQ $0xa, 0x10(SP)			
  file.go:56			0x106400e		e8eddcffff		CALL os.NewFile(SB)			
  file.go:56			0x1064013		488b442418		MOVQ 0x18(SP), AX			
  file.go:56			0x1064018		8b0de2c50800		MOVL 0x8c5e2(IP), CX			
  file.go:56			0x106401e		85c9			TESTL CX, CX				
  file.go:56			0x1064020		0f85c9000000		JNE 0x10640ef				
  file.go:56			0x1064026		488905fbde0600		MOVQ AX, 0x6defb(IP)			
  file.go:57			0x106402d		488b0524c00600		MOVQ 0x6c024(IP), AX			
  file.go:57			0x1064034		48890424		MOVQ AX, 0(SP)				
  file.go:57			0x1064038		488d0547360200		LEAQ 0x23647(IP), AX			
  file.go:57			0x106403f		4889442408		MOVQ AX, 0x8(SP)			
  file.go:57			0x1064044		48c74424100b000000	MOVQ $0xb, 0x10(SP)			
  file.go:57			0x106404d		e8aedcffff		CALL os.NewFile(SB)			
  file.go:57			0x1064052		488b442418		MOVQ 0x18(SP), AX			
  file.go:57			0x1064057		8b0da3c50800		MOVL 0x8c5a3(IP), CX			
  file.go:57			0x106405d		85c9			TESTL CX, CX				
  file.go:57			0x106405f		7574			JNE 0x10640d5				
  file.go:57			0x1064061		488905c8de0600		MOVQ AX, 0x6dec8(IP)			
  file.go:58			0x1064068		488b05e1bf0600		MOVQ 0x6bfe1(IP), AX			
  file.go:58			0x106406f		48890424		MOVQ AX, 0(SP)				
  file.go:58			0x1064073		488d0501360200		LEAQ 0x23601(IP), AX			
  file.go:58			0x106407a		4889442408		MOVQ AX, 0x8(SP)			
  file.go:58			0x106407f		48c74424100b000000	MOVQ $0xb, 0x10(SP)			
  file.go:58			0x1064088		e873dcffff		CALL os.NewFile(SB)			
  file.go:58			0x106408d		488b442418		MOVQ 0x18(SP), AX			
  file.go:58			0x1064092		8b0d68c50800		MOVL 0x8c568(IP), CX			
  file.go:58			0x1064098		85c9			TESTL CX, CX				
  file.go:58			0x106409a		7522			JNE 0x10640be				
  file.go:58			0x106409c		4889057dde0600		MOVQ AX, 0x6de7d(IP)			
  <autogenerated>:1		0x10640a3		e808f0ffff		CALL os.init.0(SB)			
  <autogenerated>:1		0x10640a8		e853f1ffff		CALL os.init.1(SB)			
  <autogenerated>:1		0x10640ad		c60512c3080002		MOVB $0x2, 0x8c312(IP)			
  <autogenerated>:1		0x10640b4		488b6c2430		MOVQ 0x30(SP), BP			
  <autogenerated>:1		0x10640b9		4883c438		ADDQ $0x38, SP				
  <autogenerated>:1		0x10640bd		c3			RET					
  <autogenerated>:1		0x10640be		488d0d5bde0600		LEAQ 0x6de5b(IP), CX			
  file.go:58			0x10640c5		48890c24		MOVQ CX, 0(SP)				
  file.go:58			0x10640c9		4889442408		MOVQ AX, 0x8(SP)			
  file.go:58			0x10640ce		e8ed95faff		CALL runtime.writebarrierptr(SB)	
  file.go:58			0x10640d3		ebce			JMP 0x10640a3				
  file.go:58			0x10640d5		488d0d54de0600		LEAQ 0x6de54(IP), CX			
  file.go:57			0x10640dc		48890c24		MOVQ CX, 0(SP)				
  file.go:57			0x10640e0		4889442408		MOVQ AX, 0x8(SP)			
  file.go:57			0x10640e5		e8d695faff		CALL runtime.writebarrierptr(SB)	
  file.go:57			0x10640ea		e979ffffff		JMP 0x1064068				
  file.go:57			0x10640ef		488d0d32de0600		LEAQ 0x6de32(IP), CX			
  file.go:56			0x10640f6		48890c24		MOVQ CX, 0(SP)				
  file.go:56			0x10640fa		4889442408		MOVQ AX, 0x8(SP)			
  file.go:56			0x10640ff		e8bc95faff		CALL runtime.writebarrierptr(SB)	
  file.go:56			0x1064104		e924ffffff		JMP 0x106402d				
  file.go:56			0x1064109		488d05f8df0600		LEAQ 0x6dff8(IP), AX			
  executable_darwin.go:9	0x1064110		48890424		MOVQ AX, 0(SP)				
  executable_darwin.go:9	0x1064114		48895c2408		MOVQ BX, 0x8(SP)			
  executable_darwin.go:9	0x1064119		e8a295faff		CALL runtime.writebarrierptr(SB)	
  executable_darwin.go:9	0x106411e		e9cbfeffff		JMP 0x1063fee				
  executable_darwin.go:9	0x1064123		4889542428		MOVQ DX, 0x28(SP)			
  executable_darwin.go:9	0x1064128		48895c2420		MOVQ BX, 0x20(SP)			
  executable_darwin.go:9	0x106412d		488d0dbcdf0600		LEAQ 0x6dfbc(IP), CX			
  executable_darwin.go:9	0x1064134		48890c24		MOVQ CX, 0(SP)				
  executable_darwin.go:9	0x1064138		4889442408		MOVQ AX, 0x8(SP)			
  executable_darwin.go:9	0x106413d		e87e95faff		CALL runtime.writebarrierptr(SB)	
  executable_darwin.go:9	0x1064142		488b542428		MOVQ 0x28(SP), DX			
  executable_darwin.go:9	0x1064147		488b5c2420		MOVQ 0x20(SP), BX			
  executable_darwin.go:9	0x106414c		e981feffff		JMP 0x1063fd2				
  executable_darwin.go:9	0x1064151		488d0580df0600		LEAQ 0x6df80(IP), AX			
  exec_unix.go:53		0x1064158		48890424		MOVQ AX, 0(SP)				
  exec_unix.go:53		0x106415c		48894c2408		MOVQ CX, 0x8(SP)			
  exec_unix.go:53		0x1064161		e85a95faff		CALL runtime.writebarrierptr(SB)	
  exec_unix.go:53		0x1064166		e933feffff		JMP 0x1063f9e				
  exec_unix.go:53		0x106416b		488d0516df0600		LEAQ 0x6df16(IP), AX			
  error.go:17			0x1064172		48890424		MOVQ AX, 0(SP)				
  error.go:17			0x1064176		48894c2408		MOVQ CX, 0x8(SP)			
  error.go:17			0x106417b		e84095faff		CALL runtime.writebarrierptr(SB)	
  error.go:17			0x1064180		e9dafdffff		JMP 0x1063f5f				
  error.go:17			0x1064185		488d052cdf0600		LEAQ 0x6df2c(IP), AX			
  error.go:16			0x106418c		48890424		MOVQ AX, 0(SP)				
  error.go:16			0x1064190		48894c2408		MOVQ CX, 0x8(SP)			
  error.go:16			0x1064195		e82695faff		CALL runtime.writebarrierptr(SB)	
  error.go:16			0x106419a		e981fdffff		JMP 0x1063f20				
  error.go:16			0x106419f		488d05f2de0600		LEAQ 0x6def2(IP), AX			
  error.go:15			0x10641a6		48890424		MOVQ AX, 0(SP)				
  error.go:15			0x10641aa		48894c2408		MOVQ CX, 0x8(SP)			
  error.go:15			0x10641af		e80c95faff		CALL runtime.writebarrierptr(SB)	
  error.go:15			0x10641b4		e928fdffff		JMP 0x1063ee1				
  error.go:15			0x10641b9		488d0d08df0600		LEAQ 0x6df08(IP), CX			
  error.go:14			0x10641c0		48890c24		MOVQ CX, 0(SP)				
  error.go:14			0x10641c4		4889442408		MOVQ AX, 0x8(SP)			
  error.go:14			0x10641c9		e8f294faff		CALL runtime.writebarrierptr(SB)	
  error.go:14			0x10641ce		e9cffcffff		JMP 0x1063ea2				
  error.go:14			0x10641d3		488d0dcede0600		LEAQ 0x6dece(IP), CX			
  error.go:13			0x10641da		48890c24		MOVQ CX, 0(SP)				
  error.go:13			0x10641de		4889442408		MOVQ AX, 0x8(SP)			
  error.go:13			0x10641e3		e8d894faff		CALL runtime.writebarrierptr(SB)	
  error.go:13			0x10641e8		e976fcffff		JMP 0x1063e63				
  <autogenerated>:1		0x10641ed		e82e6cfeff		CALL runtime.morestack_noctxt(SB)	
  <autogenerated>:1		0x10641f2		e9c9fbffff		JMP os.init(SB)				

TEXT strconv.init(SB) <autogenerated>
  <autogenerated>:1	0x1053770		65488b0c25a0080000	MOVQ GS:0x8a0, CX			
  <autogenerated>:1	0x1053779		483b6110		CMPQ 0x10(CX), SP			
  <autogenerated>:1	0x105377d		0f86ed000000		JBE 0x1053870				
  <autogenerated>:1	0x1053783		4883ec28		SUBQ $0x28, SP				
  <autogenerated>:1	0x1053787		48896c2420		MOVQ BP, 0x20(SP)			
  <autogenerated>:1	0x105378c		488d6c2420		LEAQ 0x20(SP), BP			
  <autogenerated>:1	0x1053791		0fb6054bcc0900		MOVZX 0x9cc4b(IP), AX			
  <autogenerated>:1	0x1053798		3c01			CMPL $0x1, AL				
  <autogenerated>:1	0x105379a		760a			JBE 0x10537a6				
  <autogenerated>:1	0x105379c		488b6c2420		MOVQ 0x20(SP), BP			
  <autogenerated>:1	0x10537a1		4883c428		ADDQ $0x28, SP				
  <autogenerated>:1	0x10537a5		c3			RET					
  <autogenerated>:1	0x10537a6		7507			JNE 0x10537af				
  <autogenerated>:1	0x10537a8		e85300fdff		CALL runtime.throwinit(SB)		
  <autogenerated>:1	0x10537ad		0f0b			UD2					
  <autogenerated>:1	0x10537af		c6052dcc090001		MOVB $0x1, 0x9cc2d(IP)			
  <autogenerated>:1	0x10537b6		e8b5f7ffff		CALL math.init(SB)			
  <autogenerated>:1	0x10537bb		488d05394c0300		LEAQ 0x34c39(IP), AX			
  atoi.go:10		0x10537c2		48890424		MOVQ AX, 0(SP)				
  atoi.go:10		0x10537c6		48c744240812000000	MOVQ $0x12, 0x8(SP)			
  atoi.go:10		0x10537cf		e80cf8ffff		CALL errors.New(SB)			
  atoi.go:10		0x10537d4		488b442410		MOVQ 0x10(SP), AX			
  atoi.go:10		0x10537d9		488b4c2418		MOVQ 0x18(SP), CX			
  atoi.go:10		0x10537de		4889053be90700		MOVQ AX, 0x7e93b(IP)			
  atoi.go:10		0x10537e5		8b0515ce0900		MOVL 0x9ce15(IP), AX			
  atoi.go:10		0x10537eb		85c0			TESTL AX, AX				
  atoi.go:10		0x10537ed		756a			JNE 0x1053859				
  atoi.go:10		0x10537ef		48890d32e90700		MOVQ CX, 0x7e932(IP)			
  atoi.go:10		0x10537f6		488d0550440300		LEAQ 0x34450(IP), AX			
  atoi.go:13		0x10537fd		48890424		MOVQ AX, 0(SP)				
  atoi.go:13		0x1053801		48c74424080e000000	MOVQ $0xe, 0x8(SP)			
  atoi.go:13		0x105380a		e8d1f7ffff		CALL errors.New(SB)			
  atoi.go:13		0x105380f		488b442410		MOVQ 0x10(SP), AX			
  atoi.go:13		0x1053814		488b4c2418		MOVQ 0x18(SP), CX			
  atoi.go:13		0x1053819		48890510e90700		MOVQ AX, 0x7e910(IP)			
  atoi.go:13		0x1053820		8b05dacd0900		MOVL 0x9cdda(IP), AX			
  atoi.go:13		0x1053826		85c0			TESTL AX, AX				
  atoi.go:13		0x1053828		7518			JNE 0x1053842				
  atoi.go:13		0x105382a		48890d07e90700		MOVQ CX, 0x7e907(IP)			
  <autogenerated>:1	0x1053831		c605abcb090002		MOVB $0x2, 0x9cbab(IP)			
  <autogenerated>:1	0x1053838		488b6c2420		MOVQ 0x20(SP), BP			
  <autogenerated>:1	0x105383d		4883c428		ADDQ $0x28, SP				
  <autogenerated>:1	0x1053841		c3			RET					
  <autogenerated>:1	0x1053842		488d05efe80700		LEAQ 0x7e8ef(IP), AX			
  atoi.go:13		0x1053849		48890424		MOVQ AX, 0(SP)				
  atoi.go:13		0x105384d		48894c2408		MOVQ CX, 0x8(SP)			
  atoi.go:13		0x1053852		e8699efbff		CALL runtime.writebarrierptr(SB)	
  atoi.go:13		0x1053857		ebd8			JMP 0x1053831				
  atoi.go:13		0x1053859		488d05c8e80700		LEAQ 0x7e8c8(IP), AX			
  atoi.go:10		0x1053860		48890424		MOVQ AX, 0(SP)				
  atoi.go:10		0x1053864		48894c2408		MOVQ CX, 0x8(SP)			
  atoi.go:10		0x1053869		e8529efbff		CALL runtime.writebarrierptr(SB)	
  atoi.go:10		0x105386e		eb86			JMP 0x10537f6				
  <autogenerated>:1	0x1053870		e8ab75ffff		CALL runtime.morestack_noctxt(SB)	
  <autogenerated>:1	0x1053875		e9f6feffff		JMP strconv.init(SB)			

TEXT main.init(SB) <autogenerated>
  <autogenerated>:1	0x1064c90		65488b0c25a0080000	MOVQ GS:0x8a0, CX			
  <autogenerated>:1	0x1064c99		483b6110		CMPQ 0x10(CX), SP			
  <autogenerated>:1	0x1064c9d		764a			JBE 0x1064ce9				
  <autogenerated>:1	0x1064c9f		4883ec08		SUBQ $0x8, SP				
  <autogenerated>:1	0x1064ca3		48892c24		MOVQ BP, 0(SP)				
  <autogenerated>:1	0x1064ca7		488d2c24		LEAQ 0(SP), BP				
  <autogenerated>:1	0x1064cab		0fb60511b70800		MOVZX 0x8b711(IP), AX			
  <autogenerated>:1	0x1064cb2		3c01			CMPL $0x1, AL				
  <autogenerated>:1	0x1064cb4		7609			JBE 0x1064cbf				
  <autogenerated>:1	0x1064cb6		488b2c24		MOVQ 0(SP), BP				
  <autogenerated>:1	0x1064cba		4883c408		ADDQ $0x8, SP				
  <autogenerated>:1	0x1064cbe		c3			RET					
  <autogenerated>:1	0x1064cbf		7507			JNE 0x1064cc8				
  <autogenerated>:1	0x1064cc1		e83aebfbff		CALL runtime.throwinit(SB)		
  <autogenerated>:1	0x1064cc6		0f0b			UD2					
  <autogenerated>:1	0x1064cc8		c605f4b6080001		MOVB $0x1, 0x8b6f4(IP)			
  <autogenerated>:1	0x1064ccf		e89ceafeff		CALL strconv.init(SB)			
  <autogenerated>:1	0x1064cd4		e8e7f0ffff		CALL os.init(SB)			
  <autogenerated>:1	0x1064cd9		c605e3b6080002		MOVB $0x2, 0x8b6e3(IP)			
  <autogenerated>:1	0x1064ce0		488b2c24		MOVQ 0(SP), BP				
  <autogenerated>:1	0x1064ce4		4883c408		ADDQ $0x8, SP				
  <autogenerated>:1	0x1064ce8		c3			RET					
  <autogenerated>:1	0x1064ce9		e83261feff		CALL runtime.morestack_noctxt(SB)	
  <autogenerated>:1	0x1064cee		eba0			JMP main.init(SB)	

ps: This program import tree map from go1.9:

  "ImportPathMap": {
    "errors": null,
    "internal/cpu": null,
    "internal/poll": [
    "internal/race": [
    "io": [
    "main": [
    "math": [
    "os": [
    "runtime": [
    "runtime/internal/atomic": [
    "runtime/internal/sys": null,
    "strconv": [
    "sync": [
    "sync/atomic": [
    "syscall": [
    "time": [
    "unicode/utf8": null,
    "unsafe": null

@bronze1man bronze1man changed the title from cmd/link: optimize init code ,make it generate less asm code and make binary smaller. to cmd/link: optimize init code ,make it generate less asm code and make binary smaller and faster. Oct 23, 2017

@ianlancetaylor ianlancetaylor changed the title from cmd/link: optimize init code ,make it generate less asm code and make binary smaller and faster. to cmd/link: optimize init code, make it generate less asm code and make binary smaller and faster Oct 23, 2017

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 23, 2017


This comment has been minimized.


ianlancetaylor commented Oct 23, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment