Skip to content

fix(pclntab): preserve Darwin line sites with DWARF - #2157

Draft
cpunion wants to merge 4 commits into
xgo-dev:mainfrom
cpunion:codex/dwarf-pcln-sites-v2
Draft

fix(pclntab): preserve Darwin line sites with DWARF#2157
cpunion wants to merge 4 commits into
xgo-dev:mainfrom
cpunion:codex/dwarf-pcln-sites-v2

Conversation

@cpunion

@cpunion cpunion commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

Problem

Darwin builds with DWARF currently disable every compiler-emitted funcinfo site record. That avoids an LLDB lexical-scope regression from inline assembly at function entry, but also removes final-PC anchors used for precise runtime line tables. runtime.Caller, runtime.CallersFrames, logging prefixes, and panic locations can then fall back to an earlier address.

Function-entry address records and PC-line anchors have different debugger effects: entry records alter the initial line-table row, while a PC-line anchor is safe when its inline-assembly call has no debug location.

Changes

  • add ssa.Builder.InlineAsmNoDebug, clearing only the emitted call location while preserving the builder location;
  • emit PC-line anchors whenever funcinfo sites are enabled, including Darwin DWARF builds;
  • split runtime policy between PC-line and function-entry address records;
  • suppress only function-entry address records for embedded pclntab + Darwin + DWARF;
  • retain address records for Darwin without DWARF, external pclntab, and ELF targets;
  • add explicit -ldflags=-w=false execution coverage for runtime.Caller, runtime.CallersFrames, and log.Lshortfile;
  • clarify the global site gate and use explicit PC-line naming.

This does not change pclntab mode selection, default -w, runtime table format, or LLDB language behavior.

Fixes #2115.

Dependency update

#2143 and #2215 are merged. This branch is rebased directly onto current main.

Verification

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@cpunion
cpunion force-pushed the codex/dwarf-pcln-sites-v2 branch from e38170d to d9bdbba Compare July 22, 2026 16:31
@cpunion cpunion changed the title fix(pclntab): preserve Darwin line sites with DWARF [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF Jul 22, 2026
@cpunion
cpunion force-pushed the codex/dwarf-pcln-sites-v2 branch from d9bdbba to a0b796a Compare July 23, 2026 05:08
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@cpunion
cpunion force-pushed the codex/dwarf-pcln-sites-v2 branch from a0b796a to 67e2ff5 Compare July 24, 2026 08:14
@cpunion cpunion changed the title [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF fix(pclntab): preserve Darwin line sites with DWARF Jul 24, 2026
@cpunion
cpunion force-pushed the codex/dwarf-pcln-sites-v2 branch from 67e2ff5 to d4df865 Compare July 24, 2026 10:50
@cpunion cpunion changed the title fix(pclntab): preserve Darwin line sites with DWARF [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF Jul 24, 2026
@cpunion
cpunion force-pushed the codex/dwarf-pcln-sites-v2 branch 3 times, most recently from 92925e0 to 6252be4 Compare July 29, 2026 21:29
@cpunion cpunion changed the title [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF [Based on #2215 #2143] fix(pclntab): preserve Darwin line sites with DWARF Jul 29, 2026
@cpunion
cpunion marked this pull request as ready for review July 29, 2026 22:09

@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.

FennoAI Review — PR #2157 (DWARF/pcln runtime line sites)

Overall a careful, well-tested change. The moveInstrmoveInstrsAfter rewrite preserves stable relative order, DebugRefs correctly move with the values they describe (and are excluded from the moveWouldBreakSSA value set since *ssa.DebugRef is not an ssa.Value), the nonDebugReferrers conversion faithfully preserves the prior nil/length/identity checks, and the comment rewrites match the new gating. No correctness, security, or memory-safety defects found. A few items worth confirming, noted inline plus below.

Behavioral change to confirm (highest-impact item in this PR):

  • internal/build/build.go:532passOpt is now shouldRunLLVMPasses(mode) (mode != ModeGen). The previous if emitDebugInfo || mode == ModeGen { passOpt = false } guard is gone, so debug/DWARF builds now run the full LLVM pass pipeline (RunPasses + VerifyModule) where they previously ran none. Because emitDebugInfo and OptLevel are independent, a normal DWARF-producing llgo build still defaults to O2, so the common debug path moves from no passes to full default<O2> per package. This looks intentional (it pairs with the new SetDebugInfoOptimized(passOpt && OptLevel != optlevel.O0) at build.go:540 and the "precise DWARF under optimization" goal), but it is a real per-package compile-time increase on the default path and is not obvious from the diff — please confirm it is the intended tradeoff. If a fast no-pass debug path at -O0 is still desired, note default<O0> is still invoked (verify + minimal passes) rather than skipped.

Stale doc reference (adjacent to edited code):

  • internal/build/build.go:1195 — the rewritePrebuiltFuncTab comment (whose body you edit just below) references doc/design/pclntab-linkphase.md, which does not exist in the repo. The same dangling reference also appears in chore/pclnpost/main.go:19, internal/pclnpost/binary.go:18, and doc/design/stage5-handoff.md. Consider restoring the doc or dropping the references.

Remaining inline notes are minor/latent.

Comment thread internal/build/build.go
Comment thread internal/build/ssa_order_fix.go
Comment thread internal/build/funcinfo_table.go Outdated
Comment thread internal/build/pcln_mode.go
@cpunion
cpunion marked this pull request as draft August 3, 2026 02:50
@cpunion cpunion changed the title [Based on #2215 #2143] fix(pclntab): preserve Darwin line sites with DWARF [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF Aug 4, 2026
@cpunion
cpunion force-pushed the codex/dwarf-pcln-sites-v2 branch from 6252be4 to 56e64ed Compare August 4, 2026 14:11
@cpunion cpunion changed the title [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF fix(pclntab): preserve Darwin line sites with DWARF Aug 4, 2026
@cpunion

cpunion commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

Review follow-up after rebasing onto merged #2143:

  • the DWARF LLVM pass pipeline is intentional and now belongs to main;
  • doc/design/pclntab-linkphase.md is present on current main, so the previously dangling references are valid;
  • PC-line/address-site naming and the global gate wording were updated;
  • the moveInstrsAfter precondition guard and tests are inherited from final debug: keep optimization and SSA rewrites DWARF-safe #2143.

Focused tests and the dependent-stack full test suite pass.

@cpunion

cpunion commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

CI follow-up: the Go workflow and LLGo compatibility shard had the same compile failure: the new acceptance test referenced the obsolete private helper findStringConversionRepoRoot. Commit b63aae8e1 now reuses the shared findRepoRoot helper.

Verified with:

  • go test -vet=off ./test/go -run '^TestDWARFPCLNLineSites$' -count=1
  • complete internal/build coverage run (including the branches previously shown as missing by Codecov).

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

LLGo baseline benchmarks

b63aae8e1408 | workflow run | long-term charts

Program measurements

Platform Workload File size vs base Build vs base Run vs base
Linux cprintf 18456 B +0.0% 298.838 ms -1.9% (better) 1.381 ms +2.3% (worse)
Linux fmtprintf 1829968 B +0.0% 3.001 s +0.1% (worse) 3.539 ms +2.3% (worse)
Linux println 68008 B +0.0% 294.275 ms -1.2% (better) 1.766 ms +2.0% (worse)
macOS cprintf 84672 B +0.0% 558.540 ms +12.4% (worse) 5.614 ms -3.7% (better)
macOS fmtprintf 1869328 B +0.0% 3.523 s -27.8% (better) 14.911 ms -1.7% (better)
macOS println 121200 B +0.0% 483.365 ms +39.1% (worse) 4.999 ms +28.6% (worse)
Core language and compiler benchmarks
Platform Benchmark ns/op vs base
Linux BenchmarkLookupPCRandom 12.250 ns/op +0.1% (worse)
Linux BenchmarkMergeCompilerFlags 143.600 ns/op -0.5% (better)
Linux BenchmarkMergeLinkerFlags 94.420 ns/op +0.4% (worse)
Linux BenchmarkChannelBuffered 37.080 ns/op -0.0% (better)
Linux BenchmarkChannelHandoff 23723 ns/op -0.1% (better)
Linux BenchmarkDefer 49.450 ns/op -0.9% (better)
Linux BenchmarkDirectCall 1.758 ns/op +0.1% (worse)
Linux BenchmarkGlobalRead 1.758 ns/op +0.0%
Linux BenchmarkGlobalWrite 2.810 ns/op +0.1% (worse)
Linux BenchmarkGoroutine 30226 ns/op +1.5% (worse)
Linux BenchmarkInterfaceCall 9.154 ns/op +0.1% (worse)
Linux BenchmarkRuntimeGetG 2.111 ns/op -0.0% (better)
macOS BenchmarkLookupPCRandom 13.430 ns/op -10.9% (better)
macOS BenchmarkMergeCompilerFlags 128.200 ns/op -17.3% (better)
macOS BenchmarkMergeLinkerFlags 77.970 ns/op -19.8% (better)
macOS BenchmarkChannelBuffered 28.460 ns/op +20.4% (worse)
macOS BenchmarkChannelHandoff 9038 ns/op +27.2% (worse)
macOS BenchmarkDefer 40.150 ns/op +36.3% (worse)
macOS BenchmarkDirectCall 1.201 ns/op +15.1% (worse)
macOS BenchmarkGlobalRead 1.204 ns/op +15.4% (worse)
macOS BenchmarkGlobalWrite 1.199 ns/op +12.6% (worse)
macOS BenchmarkGoroutine 61170 ns/op +26.3% (worse)
macOS BenchmarkInterfaceCall 5.389 ns/op +20.0% (worse)
macOS BenchmarkRuntimeGetG 2.767 ns/op +9.6% (worse)

Compared with 6670dae3884d measured in the same runner job.

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.

pclntab: preserve precise statement PCs with Darwin DWARF

1 participant