Skip to content

cmd/compile: support building runtime with LLVM - #128

Closed
zhouguangyuan0718 wants to merge 8 commits into
codex/abi0-name-contractfrom
codex/runtime-compile-support
Closed

cmd/compile: support building runtime with LLVM#128
zhouguangyuan0718 wants to merge 8 commits into
codex/abi0-name-contractfrom
codex/runtime-compile-support

Conversation

@zhouguangyuan0718

@zhouguangyuan0718 zhouguangyuan0718 commented Aug 12, 2026

Copy link
Copy Markdown

Summary

  • support compiling runtime and its dependency closure with LLVM while leaving runtime tests on the native Go backend
  • preserve named ABI aggregates through function signatures and bridge promoted values at call boundaries
  • use the <ABI0> symbol suffix contract from cmd/compile: encode LLVM ABI0 in function names #130
  • emit one function-level entry argument map (map 0) for every GoObj Go function
  • use go-nosplit as the only opt-out from the target morestack prologue
  • emit raw ABI0 runtime.morestack* calls without statepoints
  • derive map-0 regions from Machine CFG/PCSP entry-depth transitions rather than recognizing the morestack symbol
  • exclude unused pointer arguments from the entry GC map while retaining their ABI homes for stack-growth retry
  • preserve runtime metadata, write-barrier call-graph rules, recover frames, and required traceback sites
  • make G0StackOverflow non-tail-recursive so LLVM may still optimize normally

Dependency

LLVM-PR: goallc/llvm-project#71

Testing

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/runtime-compile-support branch from cfe24fb to e1fc98e Compare August 13, 2026 13:04
@zhouguangyuan0718
zhouguangyuan0718 changed the base branch from go1.27.master to codex/abi0-name-contract August 13, 2026 13:04
Treat the function-level entry map as map zero and expect GoObj PCDATA to return to it whenever CFG-derived PCSP reaches the entry stack depth.

Verify that morestack is a raw ABI0 call rather than a statepoint, and update GoObj/plugin fixtures for the new initial map and slow-path range.
@zhouguangyuan0718

Copy link
Copy Markdown
Author

Superseded by the reviewable stack: #131 runtime-specific lowering; #132 named ABI call boundaries; #133 traceback/defer frame semantics; #134 entry argument maps and stack-growth policy; #135 runtime dependency-closure qualification. The stack is rebased on merged #130 and LLVM #78.

zhouguangyuan0718 added a commit that referenced this pull request Aug 14, 2026
This is 1/5 of the remaining runtime LLVM support stack after the
runtime-lowering and builtin foundation merged in #136.

Stack: #136 (merged) -> this PR -> #132 -> #133 -> #134 -> #135.

This layer completes the Go producer side of the name-only GoObj
reference contract already consumed by merged LLVM #79:

- external source linkname pulls use the `<linkname>` LLVM declaration
suffix
- a one-time `name+ABI` definition set keeps local function and data
pushes on canonical names
- both ordinary `linkname` and standard-library `linknamestd` references
are handled
- builtin lookup takes precedence, so builtin and linkname encodings
remain mutually exclusive
- `<ABI0>` stays the outer ABI suffix
- suffixed references do not receive ordinary imported-package symbol
metadata
- local `linknamestd` data definitions retain the standard-library
authorization flag

The Go IR, SSA, AuxCall, and LSym models are unchanged; no linkname
metadata table is added. This PR also does not reintroduce eager
full-table builtin declarations, provisional `any` signatures, closure
provenance checks, a second cgo parameter-home mechanism, or
named-aggregate ABI reshaping.

Validation:

- `go test -tags="llvm23 dynamicllvm" cmd/internal/goobj
cmd/compile/internal/ssa`
- raw and O2 LLVM FileCheck for external pulls, local definitions, and
ABI0 wrappers
- IR -> O2 -> llc -> GoObj smoke: the external symbol is a
`nonpackage_reference` with `linkname`; local ABIInternal and ABI0
definitions remain canonical
- full stacked joint `make.bash` and downstream focused tests

Supersedes only the linkname portion of #128 and the previous mixed
implementation in this PR.
zhouguangyuan0718 added a commit that referenced this pull request Aug 15, 2026
This is 2/5 of the remaining runtime LLVM support stack. It depends on
the pure linkname contract in #131; the runtime-lowering and builtin
foundation is merged in #136.

Stack: #136 (merged) -> #131 -> this PR -> #133 -> #134 -> #135.

Keep named aggregate types in ABIInternal declarations and definitions.
When a caller and callee describe the same physical Go ABI carrier with
different nominal types, the caller rebuilds the value at the call
boundary. This includes compiler-generated runtime calls, promoted
method receivers, results, and open-defer result carriers.

The callee signature is recovered from the current-package definition;
the caller AuxCall remains authoritative for physical ABI assignment.
The differential ABI tests run the normal O2 pipeline before checking
fixed stack homes.

Focused unit and codegen tests cover named runtime aggregates,
caller-side carrier reshaping, promoted receivers, current-package
callee signatures, defined aggregate conversions, and named open-defer
results.

Rebased validation:

- joint `make.bash` with the LLVM #79 payload
- `cmd/compile/internal/ssa` unit tests
- LLVM ABI differential and `llvm_opendefer.go` codegen tests

Supersedes the named-ABI and promoted-receiver portions of #128.
zhouguangyuan0718 added a commit that referenced this pull request Aug 15, 2026
This is the traceback/inline layer of the remaining runtime LLVM
support. PR #132 is merged.

Stack: #136 (merged) -> #131 (merged) -> #132 (merged) -> this PR ->
#134 -> #135.

Preserve runtime traceback and defer semantics across LLVM optimization:

- record required frontend inline edges independently of surviving
instructions
- materialize machine-level inline anchors only when optimization
removed an edge
- attach the native function-end source position to the synthetic
deferreturn recovery call
- keep runtime.gorecover itself as a physical frame, while allowing its
direct callers to be represented by Go inline frames
- conservatively keep nosplit functions out of LLVM inlining so the
runtime callRet chain stays within the linker-enforced final GoObj stack
limit

The nosplit fence is intentionally temporary: native Go permits nosplit
inlining, and the linker checks the final PCSP tables and call
relocations. The source now carries a TODO to replace the blanket fence
with a targeted policy after the callRet frame growth is understood.

The debug fixture uses the final machine layout after LLVM #78,
including small-leaf stack-check elision.

Validation after rebasing onto b79bf4b:

- joint make.bash
- full cmd/compile/internal/ssa tests with LLVM enabled
- focused gorecover identity test
- 90/90 plugin CTest, including X86 and AArch64 debug-inline GoObj
checks
- open-defer codegen through LLVM O2, checking the recover caller
attribute group has no noinline
- recover1.go passed three consecutive LLVM O2 runs
- optimized IR confirms LLVM actually inlined direct recover callers and
retained their inlinedAt locations; direct, nested, recursive, and no-op
recover semantics still pass
- runtime and its 28 dependencies through LLVM O2 with test dependencies
native: runtime.test links successfully and the previous callRet nosplit
overflow is gone

Executing that runtime.test reaches a separate LLVM late stack-check
issue before test enumeration: runtime.tlsinit.abi0 receives a
stack-growth prologue although the native Go ABI0 wrapper does not. This
is after successful linking and is not a symbol-resolution or
inline-budget failure in this PR.

Supersedes the traceback/defer portion of #128.
zhouguangyuan0718 added a commit that referenced this pull request Aug 15, 2026
This is the entry-argument-map and stack-growth layer of the remaining
runtime LLVM support. PR #133 is merged.


Stack: #136 (merged) -> #131 (merged) -> #132 (merged) -> #133 (merged)
-> this PR -> #135.

Implement the final entry-map and stack-growth contract agreed with LLVM
#78:

- every GoObj Go function keeps entry ArgsPointerMaps map 0
- entry and entry-depth PCDATA_StackMapIndex ranges use the native -1
sentinel
- runtime stack-map lookup interprets that sentinel as entry map 0
- nosplit and systemstack are explicit function policies; the obsolete
stack-growth statepoint attribute is removed
- morestack remains a raw call, while LLVM decides from final frame size
and leafness whether a split prologue is needed
- GoObj derives entry map ranges from CFG state rather than a dedicated
morestack marker

The Machine StackMaps bridge remains Go-owned: `GoALLCStackMapPrinter`
distinguishes the function-entry `STACKMAP` from ordinary statepoint
records and passes their raw locations through `MCContext`; LLVM only
provides generic metadata-printer dispatch and final GoObj
serialization. Object-level `objview` checks cover entry PCDATA=-1,
entry ArgsPointerMaps map 0, ordinary statepoint map 1, returning to
entry depth, and the morestack map-0 path.

The pinned payload is `goallc-llvm23.1.0-20260815T055258Z`, revision
`ce1ede9c622755eeeb0ea695d5bffad3bac32dcc`, released after LLVM #81
merged.

Validation after rebasing onto #133 merge `24581b9a69`:

- coordinated Release+assertions X86/AArch64 LLVM build
- 42 focused LLVM GoObj CodeGen tests
- 91/91 plugin CTest with structured objview checks
- prior joint `make.bash` and linux amd64/arm64 CI on the fallback
payload
- full `cmd/compile/internal/ssa` tests with LLVM enabled
- ABI differential source and machine ArgsPointerMaps tests
- caller-state and nosplit GoObj tests
- statepoint codegen through LLVM O2

The stale LLVM `nowritebarrierrec` propagation test from the old stack
was removed: finalized-IR enforcement remains the existing explicit TODO
and is outside this entry-map PR.

Supersedes the entry-argmap and stack-growth portion of #128.
zhouguangyuan0718 added a commit that referenced this pull request Aug 15, 2026
Supersedes #135, which GitHub automatically closed when its dependent
base branch from #134 was merged and deleted. This version is rebased on
go1.27.master.\n\nQualify LLVM-built standard-library dependency
closures:\n\n- compile every whitelisted package and its
standard-library dependency closure with LLVM O2 by default\n- remove
the old entry-package-only mode and the per-package dependency_closure
opt-in\n- execute each whitelisted package test once\n- compile
runtime_test and the generated runtime.test main with the native Go
backend\n- link runtime tests with -w because complete LLVM DWARF
emission is not yet in scope\n- keep G0StackOverflow as real recursion
so LLVM tail-call optimization cannot erase the intended stack growth\n-
keep archive/zip, compress/gzip, and compress/zlib blacklisted because
their closures include the unresolved compress/flate SelectionDAG
failure\n\nThe runtime qualification baseline passed Linux amd64 and
arm64 in GoALLC run 31874637309 before the policy was generalized.
Focused llvmtoolexec and stdlib-policy tests also pass locally. The
updated full-closure policy is validated by this PR CI.\n\nThis is the
final runtime and stdlib dependency-closure qualification layer split
from #128.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant