How shogo82148/std works
Purpose and entry points
This is a Go source-tree distribution: standard-library packages, runtime, compiler/toolchain, and developer commands. Primary user-facing executables are go (cmd/go/main.go), compiler (cmd/compile/main.go), linker (cmd/link/main.go), assembler (cmd/asm/main.go), and bootstrap/build orchestrator (cmd/dist/main.go). The root module files, go.mod and go.sum, establish repository-level module dependencies.
Build and command orchestration
cmd/go parses user commands and coordinates package loading, module resolution, caching, compilation, linking, testing, formatting, and tool invocation. Its execution engine constructs dependency/action graphs and invokes compiler-family tools.
Paths: cmd/go/main.go, cmd/go/internal/work/action.go, cmd/go/internal/work/build.go.
Module-aware resolution is a boundary between local source/module state and remote repositories, proxies, checksum databases, and VCS clients.
Paths: cmd/go/internal/modload/load.go, cmd/go/internal/modfetch/fetch.go, cmd/go/internal/modfetch/sumdb.go.
Compiler pipeline
The Go compiler turns source into object/export data through parsing, IR construction/type checking, lowering and optimization, architecture-specific code generation, then object emission. Compiler-internal packages are deliberately encapsulated under cmd/compile/internal.
Paths: cmd/compile/main.go, cmd/compile/internal/noder/irgen.go, cmd/compile/internal/ssa/compile.go.
The shared IR/type boundary separates frontend semantics from optimization and target lowering; SSA has target-specific rewrite/backend implementations for supported architectures.
Paths: cmd/compile/internal/ir/ir.go, cmd/compile/internal/typecheck/typecheck.go, cmd/compile/internal/ssagen/ssa.go.
Linking and binary formats
The linker consumes compiler/assembler object inputs, resolves symbols and relocations, performs dead-code elimination, emits debug metadata, and writes platform executables/libraries. It supports ELF, Mach-O, PE, XCOFF, and architecture-specific backends.
Paths: cmd/link/main.go, cmd/link/internal/ld/link.go, cmd/link/internal/loader/loader.go.
Assembly source follows a parallel route through lexical parsing and architecture-specific encoding to object output.
Paths: cmd/asm/main.go, cmd/asm/internal/asm/parse.go, cmd/internal/obj/link.go.
Runtime and standard-library boundary
runtime implements goroutine scheduling, memory allocation/GC, synchronization, networking pollers, signal handling, profiling, and OS/architecture bindings. It is the execution substrate generated programs depend on.
Paths: runtime/proc.go, runtime/mgc.go, runtime/netpoll.go.
Public packages provide the application-facing API layer, while internal contains compiler/runtime/shared implementation contracts not importable by external modules.
Paths: net/http/server.go, crypto/tls/conn.go, internal/abi/abi.go.
Platform, native, and security integration
The tree is cross-platform and cross-architecture via build-constrained source variants across runtime, syscall, compiler, and linker. Native integration includes cgo and external C toolchains.
Paths: cmd/cgo/main.go, runtime/cgocall.go, syscall/syscall_linux.go.
External integration is primarily filesystem/process execution, OS syscalls, DNS/networking, Git/SVN/VCS, Go module proxies/checksum services, and optional telemetry. CI is GitHub Actions.
Paths: cmd/go/internal/vcs/vcs.go, cmd/go/internal/telemetrycmd/telemetry.go, .github/workflows/sync.yml.
Main entry points: action.go Action graph engine · proc.go Go runtime · fetch.go Module fetch & sums · link.go Object representation
Components 20
Developer Commands
- go command · Builds, tests, formats, and manages packages.
cmd/go/main.go - Action graph engine · Constructs dependency actions and invokes tools.
cmd/go/internal/work/action.go - Module resolution · Resolves local module and package state.
cmd/go/internal/modload/load.go - Module fetch & sums · Fetches modules and verifies checksums.
cmd/go/internal/modfetch/fetch.go - VCS integration
cmd/go/internal/vcs/vcs.go
Compilation Pipeline
- compile
cmd/compile/main.go - Frontend & type checking · Parses source and constructs typed IR.
cmd/compile/internal/noder/irgen.go - IR & type boundary
cmd/compile/internal/ir/ir.go - SSA optimization & codegen · Optimizes and lowers IR for target architectures.
cmd/compile/internal/ssa/compile.go - asm
cmd/asm/main.go - Assembly parser
cmd/asm/internal/asm/parse.go - Object representation · Shared object emission contract.
cmd/internal/obj/link.go - link
cmd/link/main.go - Link loader & emitter · Resolves symbols and relocations into binaries.
cmd/link/internal/ld/link.go
Runtime & Platform
- Go runtime · Provides scheduling, GC, synchronization, and OS bindings.
runtime/proc.go - cgo
cmd/cgo/main.go
Library Boundaries
- Public standard library
net/http/server.go - Internal ABI
internal/abi/abi.go
Other components
- Module proxies & sumdb
- OS & C toolchains
Connections 21
- go command → Action graph engine: build actions
- go command → Module resolution: resolves modules
- Module resolution → Module fetch & sums: requests dependencies
- Module fetch & sums → Module proxies & sumdb: fetches and verifies
- Module fetch & sums → VCS integration: falls back to
- Action graph engine → compile: compiles Go
- Action graph engine → asm: assembles sources
- Action graph engine → link: links outputs
- compile → Frontend & type checking: parses and types
- Frontend & type checking → IR & type boundary: produces typed IR
- IR & type boundary → SSA optimization & codegen: lowered to
- SSA optimization & codegen → Object representation: emits objects
- asm → Assembly parser: parses assembly
- Assembly parser → Object representation: encodes objects
- Object representation → Link loader & emitter: object inputs
- link → Link loader & emitter: drives
- Link loader & emitter → Go runtime: links runtime
- Public standard library → Go runtime: executes on
- Go runtime → Internal ABI: uses contract
- cgo → OS & C toolchains: invokes
- Go runtime → OS & C toolchains: syscalls and native calls