Skip to content

[WIP] cl: preserve linknames for main test variants - #2365

Closed
visualfc wants to merge 2 commits into
xgo-dev:mainfrom
visualfc:codex/fix-main-test-linkname
Closed

[WIP] cl: preserve linknames for main test variants#2365
visualfc wants to merge 2 commits into
xgo-dev:mainfrom
visualfc:codex/fix-main-test-linkname

Conversation

@visualfc

@visualfc visualfc commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Preserve preloaded //go:linkname entries for package main test variants.

Behavior

  • A main.* target declared in ordinary package source is rewritten to the package import path when llgo builds the test variant.
  • A main.* target declared in a _test.go source file is intentionally left unchanged. Test variants do not define main.* symbols, so this remains unsupported.
  • Package-scoped linkname directives follow the same source-file distinction.

Tests

  • GOCACHE=/tmp/llgo-bug-gocache go test ./cl -run TestParsePkgSyntaxCollectsLinknames -count=1
  • GOCACHE=/tmp/llgo-bug-gocache go run ./cmd/llgo test -v ./cmd/demo/bug

History

The branch is a single commit: c7a592c59 cl: preserve linknames for main test variants.

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: fix main test linkname

This is a small, focused change that records an extra go:linkname alias under the raw import path for main packages compiled as test variants (go test emits symbols under the import path rather than the canonical main. prefix). The logic is correct, and the main.-prefix rewrite in testMainLinkname is safely anchored (targets like C.foo, example.com/pkg.X, or mainfoo.bar are untouched). No security or performance concerns — the added work is guarded so non-main packages short-circuit before any map access.

The findings below are maintainability and documentation/test-clarity suggestions; none block merge.

Comment thread cl/import.go Outdated
Comment thread cl/import_coverage_test.go Outdated
Comment thread cl/import.go Outdated
Comment thread cl/import.go Outdated
@visualfc

Copy link
Copy Markdown
Collaborator Author

Addressed the review suggestions in c7c50dd:

  • centralized the raw-main-path predicate in rawMainPathOf
  • renamed and documented the target rewrite helper
  • split coverage between declaration-attached and cross-file floating //go:linkname directives

Verified with:

  • GOCACHE=/tmp/llgo-bug-gocache go test ./cl -run TestParsePkgSyntaxCollectsLinknames -count=1
  • GOCACHE=/tmp/llgo-bug-gocache go run ./cmd/llgo test -v ./cmd/demo/bug

@visualfc
visualfc force-pushed the codex/fix-main-test-linkname branch from efe7b81 to c7a592c Compare August 19, 2026 08:40
@visualfc visualfc changed the title cl: preserve linknames for main test variants [WIP] cl: preserve linknames for main test variants Aug 19, 2026
@github-actions

github-actions Bot commented Aug 19, 2026

Copy link
Copy Markdown

LLGo baseline benchmarks

f093bba768e4 | workflow run | long-term charts

Program measurements

Platform Workload File size vs base Build vs base Run vs base
Linux cprintf 19288 B 0 B / +0.0% 356.137 ms -28.03 ms / -7.3% (better) 1.318 ms +31.13 us / +2.4% (worse)
Linux fmtprintf 1859320 B 0 B / +0.0% 2.853 s +66.16 ms / +2.4% (worse) 3.261 ms -131.9 us / -3.9% (better)
Linux println 68776 B 0 B / +0.0% 356.535 ms +4.079 ms / +1.2% (worse) 1.634 ms -116.7 us / -6.7% (better)
macOS cprintf 84672 B 0 B / +0.0% 628.239 ms +34.5 ms / +5.8% (worse) 5.003 ms -841.3 us / -14.4% (better)
macOS fmtprintf 1892448 B 0 B / +0.0% 3.500 s +98.56 ms / +2.9% (worse) 14.667 ms -298.3 us / -2.0% (better)
macOS println 121360 B 0 B / +0.0% 560.880 ms -4.808 ms / -0.8% (better) 5.364 ms -1.119 ms / -17.3% (better)
Core language and compiler benchmarks
Platform Benchmark ns/op vs base
Linux BenchmarkLookupPCRandom 13.240 ns/op -0.01 ns/op / -0.1% (better)
Linux BenchmarkMergeCompilerFlags 153.800 ns/op +2 ns/op / +1.3% (worse)
Linux BenchmarkMergeLinkerFlags 96.170 ns/op +1.07 ns/op / +1.1% (worse)
Linux BenchmarkChannelBuffered 33.980 ns/op -0.03 ns/op / -0.1% (better)
Linux BenchmarkChannelHandoff 30003 ns/op +1181 ns/op / +4.1% (worse)
Linux BenchmarkDefer 48.840 ns/op +0.42 ns/op / +0.9% (worse)
Linux BenchmarkDirectCall 1.557 ns/op -0.001 ns/op / -0.1% (better)
Linux BenchmarkGlobalRead 1.557 ns/op -0.001 ns/op / -0.1% (better)
Linux BenchmarkGlobalWrite 2.481 ns/op +0.001 ns/op / +0.04032% (worse)
Linux BenchmarkGoroutine 34787 ns/op -682 ns/op / -1.9% (better)
Linux BenchmarkInterfaceCall 8.141 ns/op +0.042 ns/op / +0.5% (worse)
Linux BenchmarkRuntimeGetG 2.180 ns/op -0.001 ns/op / -0.04585% (better)
macOS BenchmarkLookupPCRandom 13.540 ns/op -4.23 ns/op / -23.8% (better)
macOS BenchmarkMergeCompilerFlags 135.900 ns/op -39.2 ns/op / -22.4% (better)
macOS BenchmarkMergeLinkerFlags 97.610 ns/op -44.29 ns/op / -31.2% (better)
macOS BenchmarkChannelBuffered 25.350 ns/op -7.93 ns/op / -23.8% (better)
macOS BenchmarkChannelHandoff 8357 ns/op -1198 ns/op / -12.5% (better)
macOS BenchmarkDefer 39.440 ns/op -7.46 ns/op / -15.9% (better)
macOS BenchmarkDirectCall 1.149 ns/op -0.106 ns/op / -8.4% (better)
macOS BenchmarkGlobalRead 1.162 ns/op -0.164 ns/op / -12.4% (better)
macOS BenchmarkGlobalWrite 1.197 ns/op -0.181 ns/op / -13.1% (better)
macOS BenchmarkGoroutine 66942 ns/op +898 ns/op / +1.4% (worse)
macOS BenchmarkInterfaceCall 5.124 ns/op -0.596 ns/op / -10.4% (better)
macOS BenchmarkRuntimeGetG 2.707 ns/op -0.643 ns/op / -19.2% (better)

Compared with cf91afb98fca measured in the same runner job.

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/build/build.go 66.66% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@visualfc visualfc closed this Aug 20, 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