Skip to content

cl,ssa,runtime: stack-object finalizer liveness#2036

Draft
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/stage5-finalizer-liveness
Draft

cl,ssa,runtime: stack-object finalizer liveness#2036
cpunion wants to merge 2 commits into
xgo-dev:mainfrom
cpunion:codex/stage5-finalizer-liveness

Conversation

@cpunion

@cpunion cpunion commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Re-expresses the surviving value of #1906; its remaining ~11k diff lines were the pre-#2012 funcinfo draft, superseded by the stage-5 chain.

What changes

  • Stack-object liveness for finalizers: cl gains a liveness analysis over stack allocations; once a stack object's last use has passed, its slot is cleared so bdwgc's conservative stack scan stops keeping the dead object (and everything it points to) alive. Around the trigger points, pointer registers are clobbered (llgo_clobber_pointer_regs) and dead stack slots still holding the target are zeroed (llgo_clear_stack_ptr, pthread stack-bounds walk on darwin/linux).
  • runtime.SetFinalizer conformance: mfinal/runtime_gc/bdwgc-binding hook the cleared-slot machinery, so finalizers for dead stack objects actually run (gc semantics).
  • 860-line cl liveness unit suite + test/go finalizer regressions.

goroot conformance

Retired xfails, validated darwin/arm64 (go1.24 + go1.26) and linux/arm64 (go1.24): deferfin.go, stackobj.go, stackobj3.go (stackobj2.go already passed and stays green).

Validation

  • macOS: full ssa (128s) and cl (389s) suites green (no golden drift — the analysis only clears dead slots, existing goldens unchanged); test/go Finalizer set green under llgo test.
  • linux/arm64 container: finalizer set green; all four stackobj/deferfin goroot cases green.

The existing multi-package coverage command is capped at -p 2 to avoid overlapping the heaviest compiler test packages. The current main test matrix and the separate test/go coverage command are otherwise unchanged.

Supersedes #1906.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.77035% with 49 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cl/compile.go 89.25% 27 Missing and 22 partials ⚠️

📢 Thoughts on this report? Let us know!

@cpunion
cpunion force-pushed the codex/stage5-finalizer-liveness branch 2 times, most recently from 831cf7f to 05dc73a Compare July 8, 2026 07:04
@cpunion
cpunion force-pushed the codex/stage5-finalizer-liveness branch 2 times, most recently from d877a90 to 4a23ec7 Compare July 9, 2026 05:31
@cpunion cpunion added go-test-compat Go standard-library and GOROOT test compatibility bug Something isn't working bugfix Fixes an existing bug or regression go1.26 Go 1.26 compatibility and support and removed bug Something isn't working labels Jul 16, 2026
@cpunion
cpunion force-pushed the codex/stage5-finalizer-liveness branch from 4a23ec7 to 4d535b8 Compare July 17, 2026 12:28

@cpunion cpunion left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need full explaination in PR body about how this PR works

*cur = 0;
}
}
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this funcion safe?


func SetFinalizer(obj any, finalizer any) {
objFace := (*eface)(unsafe.Pointer(&obj))
objFace := *(*eface)(unsafe.Pointer(&obj))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why deref and get addr later? How about remove deref here?

Comment thread cl/compile.go
return plans
}

func (p *context) compileLateValue(b llssa.Builder, v ssa.Value) llssa.Expr {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between compileLateValue and compileValue?

@cpunion
cpunion marked this pull request as draft July 21, 2026 01:47
cpunion added 2 commits July 23, 2026 16:36
Re-expresses xgo-dev#1906 on the xgo-dev#2023 base (its remaining ~11k diff lines were
the pre-xgo-dev#2012 funcinfo draft, superseded by the stage-5 chain):

- cl gains a liveness analysis for stack-allocated objects: allocas
  whose last use has passed are cleared so bdwgc's conservative stack
  scan stops keeping dead stack objects (and what they point to) alive;
  pointer registers are clobbered around the trigger points
  (llgo_clobber_pointer_regs) and dead stack slots holding the target
  are zeroed (llgo_clear_stack_ptr, pthread stack-bounds walk).
- runtime.SetFinalizer paths (mfinal, runtime_gc, bdwgc binding) hook
  the cleared-slot machinery so finalizers for dead stack objects run.
- xfail: retire deferfin.go, stackobj.go, stackobj3.go, validated on
  darwin/arm64 go1.24 + go1.26 (stackobj2 already passed).

Carries the xgo-dev#2035 shared-GOCACHE commit temporarily (same patch-id,
auto-dedups when the chain rebases after xgo-dev#2035 merges).

Supersedes xgo-dev#1906.
With the shared go-build cache the four heavy test packages (cl, ssa,
internal/cabi, test/go) no longer stagger naturally on cold caches;
their compile phases overlap fully, and the burst of concurrent
clang/lld children has been killing ubuntu runners mid-run (three
consecutive 'runner received a shutdown signal' deaths on this branch,
each ~8 minutes into the heavy-package phase) and showing up on mac as
go-list WaitDelay expirations. -p 2 caps the concurrent package count;
wall time is dominated by the cl package either way.
@cpunion
cpunion force-pushed the codex/stage5-finalizer-liveness branch from 4d535b8 to 9cc8498 Compare July 23, 2026 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Fixes an existing bug or regression go1.26 Go 1.26 compatibility and support go-test-compat Go standard-library and GOROOT test compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant