go runtime walkthrough - modrpc/info GitHub Wiki

Table of Contents

Main main() call

runtime/rt0_linux_amd64.s

  • main(SB),NOSPLIT,$-8
    • jump to $runtime.rt0_go(SB), AX
    • SB: Static base pointer: global symbols.
    • see Go assembler guide] for basic

runtime/rt0_go(SB)

  • entry point
  • copy arguments on an even stack
  • create istack out of the given OS stack.
  • needtls
    • if tls needed jump to runtime.settls(SB)
  • set the per-goroutine and per-mach "registers"
    • get_tls(BX)
    • LEAQ runtime.g0(SB), CX
    • MOVQ CX, g(BX)
    • LEAQ runtime.m0(SB), AX]

initialization

  • 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
  • CALL runtime.newproc(SB)

start this M

  • CALL runtime.mstart(SB)

Function call

⚠️ **GitHub.com Fallback** ⚠️