Skip to content

Fix stack object finalizer liveness#1906

Draft
cpunion wants to merge 3 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-stackobj-coverage
Draft

Fix stack object finalizer liveness#1906
cpunion wants to merge 3 commits into
xgo-dev:mainfrom
cpunion:codex/goroot-stackobj-coverage

Conversation

@cpunion
Copy link
Copy Markdown
Collaborator

@cpunion cpunion commented May 22, 2026

Summary

  • implement runtime.SetFinalizer on top of BDWGC finalizers and run queued Go finalizers during runtime.GC
  • add scoped conservative stack/register cleanup for command-line LLGo programs to address stack object/finalizer liveness cases
  • add stable test/go coverage for finalizer behavior and stack-object liveness, and un-xfail the verified darwin/arm64 goroot cases

Tests

  • go install ./...
  • go test ./test/go -run 'TestRuntimeSetFinalizer' -count=1 -v
  • LLGO_ROOT=/Users/lijie/source/goplus/llgo-wt-goroot-stackobj llgo test -run 'TestRuntimeSetFinalizer' -timeout=20m -count=1 ./test/go
  • go test -v ./test/goroot -run '^TestGoRootRunCases$' -goroot $(go env GOROOT) -case '^(deferfin|tinyfin|stackobj|stackobj3)\.go$' -xfail /tmp/llgo-empty-xfail.yaml -count=1 -build-timeout 5m -run-timeout 20s -progress 20s
  • go test ./cl ./ssa ./test/goroot -run 'Test(ParseDirective|XFail)' -count=1
  • go test ./cl ./ssa -count=1
  • git diff --check

Notes

  • The conservative liveness cleanup is intentionally limited to command-line-arguments; the test/go subprocess probe keeps coverage stable even without the full goroot workflow.
  • Linux goroot xfails for these cases are left in place because this pass was verified locally on darwin/arm64 only.

@cpunion
Copy link
Copy Markdown
Collaborator Author

cpunion commented May 22, 2026

Updated with Linux pthread feature macro fix in runtime/internal/lib/runtime/_wrap/runtime.c so pthread_getattr_np is declared on glibc-based CI.

Local verification:

  • go test ./test/go -run 'TestRuntimeSetFinalizer' -count=1 -v
  • go run -tags=dev ./cmd/llgo test -run 'TestRuntimeSetFinalizer' -timeout=20m -count=1 ./test/go
  • go test ./cl ./ssa -count=1
  • git diff --check

@cpunion
Copy link
Copy Markdown
Collaborator Author

cpunion commented May 22, 2026

Updated again after LLGo shard 2 exposed a link failure from compiler-injected stack liveness helpers.

Fixes in 36044708d:

  • emit calls to the C runtime wrapper symbols directly instead of skipped Go helper wrappers
  • only enable conservative stack liveness clearing for command-line-arguments packages that actually call runtime.SetFinalizer, avoiding unrelated test/go programs pulling in the helper symbol

Local verification:

  • LLGO_BUILD_CACHE=off go test ./test/go -run 'TestRuntimeSetFinalizerStackObjectLiveness|TestStringConversionFromWideIntegers' -count=1 -v
  • go test ./cl ./ssa -count=1
  • git diff --check

Note: LLGO_BUILD_CACHE=off go run -tags=dev ./cmd/llgo test ... reached program execution locally but hit a macOS temp-dir cleanup error (operation not permitted) after the target code path; the plain Go test wrapper passed the same LLGo programs.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 15.86639% with 403 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cl/compile.go 15.57% 375 Missing and 10 partials ⚠️
ssa/memory.go 0.00% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants