Go 源码学习 引导(二)

Posted on Jun 24, 2022

先附上runtime·rt0_go中检查及初始化的源码

	CALL	runtime·check(SB)

	MOVL	24(SP), AX		// copy argc
	MOVL	AX, 0(SP)
	MOVQ	32(SP), AX		// copy argv
	MOVQ	AX, 8(SP)
	CALL	runtime·args(SB)
	CALL	runtime·osinit(SB)
	CALL	runtime·schedinit(SB)

	// create a new goroutine to start program
	MOVQ	$runtime·mainPC(SB), AX		// entry
	PUSHQ	AX
	CALL	runtime·newproc(SB)
	POPQ	AX

	// start this M
	CALL	runtime·mstart(SB)

	CALL	runtime·abort(SB)	// mstart should never return
	RET

runtime.check()

位于runtime1.go 主要是对内置类型的大小及一些参赛的检查

runtime.agrs()

位于runtime1.go 整理命令行参数

runtime.osinit()

位于os_linux.go

1.设置CPU core数量

2.设置physHugePageSize physHugePageSize是从系统文件中获取的,但是我没有从该路径中找到此文件,此时设置physHugePageSize设置的是0

var sysTHPSizePath = []byte("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size\x00")

runtime.schedinit()

位于proc.go