Skip to content

cmd/compile: preserve newproc pointer argument in LLVM IR - #34

Merged
zhouguangyuan0718 merged 1 commit into
go1.27.masterfrom
codex/newproc-pointer-arg
Aug 1, 2026
Merged

cmd/compile: preserve newproc pointer argument in LLVM IR#34
zhouguangyuan0718 merged 1 commit into
go1.27.masterfrom
codex/newproc-pointer-arg

Conversation

@zhouguangyuan0718

@zhouguangyuan0718 zhouguangyuan0718 commented Aug 1, 2026

Copy link
Copy Markdown

Summary

  • special-case only the compiler-generated runtime.newproc call in LLVM lowering
  • keep native Go SSA and ABI construction unchanged: AuxCall continues to use uintptr solely for the physical ABI assignment
  • declare the single LLVM parameter as ptr, matching the actual pointer-shaped closure SSA operand
  • reject unexpected ABI, argument/result counts, physical placeholder types, and non-pointer SSA operands

Rationale

The compiler lowers a go statement as a raw runtime call rather than a normally typed CallExpr. Native ssagen records the closure as uintptr in AuxCall to allocate one integer ABI word, while the actual SSA operand and runtime.newproc(fn *funcval) parameter are pointers. Native machine lowering can keep those physical and semantic views separate; LLVM needs the declaration and operand to have the same IR type and statepoint processing must retain the pointer type.

This PR handles that one established mismatch. It does not introduce a general runtime signature resolver, inspect compiler builtin models, change AuxCall, or adapt defer/runtime helper calls.

Evidence

The focused fixture produces:

  • call goabiinternal void @runtime.newproc(ptr %closure)
  • after O2, tail call goabiinternal void @runtime.newproc(ptr nonnull %closure)
  • declare goabiinternal void @runtime.newproc(ptr)
  • no runtime.newproc(i64)
  • AArch64 GoObj R_CALLARM64:runtime.newproc at an ordinary safepoint, with a distinct morestack safepoint

The runtime fixture grows the caller stack, launches an escaping closure, and runs GC in both caller and goroutine for eight rounds.

Validation

Validated after rebasing onto #35:

  • clean make.bash toolchain rebuild
  • go test -count=1 -tags="llvm23 dynamicllvm" cmd/compile/internal/ssa cmd/llvmtoolexec
  • go test -count=1 cmd/internal/testdir -run "^Test/LLVM$": 48/48 codegen, ABI differential, alloca-statepoint, 46/46 runtime, and 2/2 fail-closed
  • plugin CTest: 47/47
  • direct IR opt -passes="default<O2>,verify" followed by a second verifier pass
  • optimized IR through llc -verify-machineinstrs -filetype=obj
  • objview JSON/text confirms the runtime.newproc relocation and ordinary safepoint
  • gofmt and git diff --check

Boundaries

  • only runtime.newproc is changed
  • ordinary modeled runtime functions, raw defer calls, ABI0, special assembly calls, and write-barrier helpers retain their previous behavior
  • no LLVM repository change is required
  • no native Go lowering/model file is modified
  • the broader superseded implementations remain available only as backup branches:

@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/newproc-pointer-arg branch from 7bb9e20 to c6b672e Compare August 1, 2026 11:20
@zhouguangyuan0718 zhouguangyuan0718 changed the title cmd/compile: preserve newproc pointer arguments in LLVM IR cmd/compile: preserve compiler runtime signatures in LLVM IR Aug 1, 2026
@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/newproc-pointer-arg branch from c6b672e to 4bce9b7 Compare August 1, 2026 11:52
@zhouguangyuan0718 zhouguangyuan0718 changed the title cmd/compile: preserve compiler runtime signatures in LLVM IR cmd/compile: model runtime signatures in LLVM lowering Aug 1, 2026
@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/newproc-pointer-arg branch from 4bce9b7 to b5eb872 Compare August 1, 2026 13:40
@zhouguangyuan0718 zhouguangyuan0718 changed the title cmd/compile: model runtime signatures in LLVM lowering cmd/compile: preserve newproc pointer argument in LLVM IR Aug 1, 2026
@zhouguangyuan0718
zhouguangyuan0718 force-pushed the codex/newproc-pointer-arg branch from b5eb872 to fb377b4 Compare August 1, 2026 13:44
@zhouguangyuan0718
zhouguangyuan0718 merged commit 249fa53 into go1.27.master Aug 1, 2026
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