Who prepares argc and argv?

Hi dear friends!

I am very interested in the starting up process of a go program. I just copied the code of the startup function of any go program for the 386 family processor and Windows operating system, _rt0_386:

// _rt0_386 is common startup code for most 386 systems when using
// internal linking. This is the entry point for the program from the
// kernel for an ordinary -buildmode=exe program. The stack holds the
// number of arguments and the C-style argv.
TEXT _rt0_386(SB),NOSPLIT,$8
	MOVL	8(SP), AX	// argc
	LEAL	12(SP), BX	// argv
	JMP	runtime·rt0_go(SB)

But I just can’t understand why 8(SP) now contains a valid argc. In C, I know how argc and argv are prepared. It is the mainCRTStartup function that prepares argc and argv, and then calls main(argc, argv). But for go, now since _rt0_386 is the entry function, meaning that no other function calls _rt0_386 and therefore argc and argv are not yet prepared at this time.

Can anyone resolve my puzzle? Thank you!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.