CodeVetter · Repo Unpack · Behavior traces
golang/go
Four flows were walked end-to-end. (1) Source bootstrap: make.bash → dist → bootstrapBuildTools → go_bootstrap rebuild. (2) 'go build': main → toolchain.Select → lookupCmd → invoke → load → Builder.Do. (3) Module fetch with integrity checks. (4) Runtime program startup and the scheduler loop. Test orchestration via run.bash → dist test → testdir is a fifth traced path.
- BOOTSTRAP trace: src/make.bash → check env (Windows, gold ld, SELinux) → locate GOROOT_BOOTSTRAP → 'go build -o cmd/dist/dist ./cmd/dist' → 'dist env -p' → 'dist bootstrap -a' → cmdbootstrap() → setup()+writeGeneratedFiles() → checkCC()+bootstrapBuildTools() → go_bootstrap rebuilds std+cmd; the dist binary is deleted afterward.
- 'go build' trace: main() → telemetry.MaybeChild/counter.Open → handleChdirFlag (-C must be first) → toolchain.Select (may download+re-exec newer toolchain) → flag.Parse → lookupCmd(args) → invoke() → buildcfg.Check → envcmd.MkEnv applied → cmd.Run → runBuild → load.PackagesAndTests → Builder.Do(root).
- Compile action trace: Builder.buildObject → resolve inputs → (cgo path: runCgo→processCgoOutputs→ccompile/dynimport) → run 'compile' tool with importcfg → cacheObjdirFile stores outputs under the action ID → link action writes final binary.
- Module download trace: Fetcher.Download → checkCacheDir → downloadCache.Do → DownloadDir probe → download (proxy via GOPROXY or VCS fallback) → checkMod (go.sum + sumdb/dirhash verification) → TooNewError check on module's go directive → extracted dir under GOMODCACHE.
- Runtime startup trace: rt0/schedinit (asm + runtime1) → mstart/mstart0/mstart1 → runtime.main on main goroutine: set maxstacksize (1GB/64-bit) → newm(sysmon) → lockOSThread → nanotime → doInit(runtime_inittasks) → gcenable → defaultGOMAXPROCSUpdateEnable → cgo init checks (_cgo_notify_runtime_init_done, startTemplateThread) → doInit per-module inittasks → unlockOSThread → call main_main (user main) → exit.
- Scheduler loop trace: goready/newproc → runqput (local runnext/runq or global) → wakep if spinning==0 and idle P → M spins in findRunnable (local queue → global → netpoll → steal from other P) → schedule() resets spinning, handles lockedm via startlockedm → execute(gp, inheritTime) → gogo jumps to goroutine.
- GC trigger trace: allocation or force → gcStart → sweep termination STW → gcphase=_GCmark + write barrier enable → start world, mark workers + assists drain grey queue → gcMarkDone distributed termination → mark termination STW → _GCoff, concurrent sweep resumes.
- Test-dir trace: run.bash → 'go tool dist test -rebuild' → tester.run enumerates distTests → for test/ corpus: 'go test cmd/internal/testdir' → Test() reads 'go env -json', iterates dirs=[.,ken,chan,interface,...,codegen,fixedbugs,...], registers each .go file as subtest Test/<rel path> honoring //-directives (run, errorcheck, compile).
- Toolchain switch trace: Select → modload.NewLoader().WillBeEnabled → read go.mod 'toolchain' line → compare with local version → if newer needed: modfetch downloads golang.org/toolchain@v0.0.1-<ver>.<os>-<arch> → exec new go binary with GOTOOLCHAIN_INTERNAL_SWITCH_VERSION set → child verifies and clears it; maxSwitch=100 aborts loops.
- cgo trace: package with import "C" → runCgo generates _cgo_gotypes.go etc → processCgoOutputs compiles generated C via gcc (ccompile with DefaultCFlags='-O2 -g') → dynimport produces dynamic symbols → swig path handles .swig/.swigcxx files → objects linked into the package.