Skip to content

[Based on #2143 #2145 #2157] build: match cmd/link DWARF defaults#2142

Draft
cpunion wants to merge 16 commits into
xgo-dev:mainfrom
cpunion:codex/dwarf-default-go-compatible
Draft

[Based on #2143 #2145 #2157] build: match cmd/link DWARF defaults#2142
cpunion wants to merge 16 commits into
xgo-dev:mainfrom
cpunion:codex/dwarf-default-go-compatible

Conversation

@cpunion

@cpunion cpunion commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Based on #2143, #2145, and #2157.

Problem

LLGo currently omits DWARF from linked binaries unless the caller explicitly passes -w=false. That is the opposite of cmd/link: linked Go binaries preserve DWARF by default, while -w removes it and -s implies -w unless an explicit -w=false overrides that implication.

Changing the default exercises the normal optimized DWARF path. The prerequisite PRs keep that pipeline valid, ignore storage-free Python frontend variables, and preserve precise runtime line sites on Darwin.

The default also exposed existing full-LTO verifier failures in functions with deferred calls. Defer execution blocks are emitted after the frontend instruction walk, so cleanup calls could be generated without !dbg. Range-over-func adds a second case: a defer can be registered in a synthetic yield function but emitted in its outer owner, where retaining the yield function lexical scope creates invalid cross-subprogram metadata.

Generating DWARF for the normal macOS package matrix also makes shard 0 exceed its previous 30-minute job budget. The first complete run reached later standard-library packages with no test failure before GitHub canceled the job at the hard timeout.

Changes

  • preserve DWARF by default for linked executables, tests, installs, and C archives
  • make -s imply -w, while preserving an explicit -s -w=false override
  • match the cmd/link Darwin C-shared default: omit DWARF unless explicitly overridden
  • keep ModeGen conservative because it has no final linker stage
  • remove the temporary OmitDWARFByDefault policy field
  • keep existing executable IR fixtures stable by making the cltest capture helper choose omission locally when the test did not request a DWARF mode
  • resolve anonymous-function debug locations through their lexical function scope
  • retain each defer statement source location while emitting its cleanup block
  • for cross-function DeferTo, preserve line and column but reanchor the location to the outer owner DISubprogram
  • cover ordinary and loop defer lowering at the SSA level, a real conditional-defer full-LTO link, and nested range-over-func defer metadata at O2
  • keep the reduced test matrix unchanged, but allow its macOS shards 45 minutes; non-macOS shards remain capped at 30 minutes

The defer fixes stay inside defer lowering; they do not attach fallback locations to unrelated calls. The cltest helper does not change production defaults or mutate the caller configuration.

This PR does not implement native symbol-table stripping for -s, change pclntab mode selection, or add native LLDB Go-language support. The latter remains proposed in #2154.

Verification

  • PR head adf396b6e: 40 checks passed, zero failed or pending; the conditional release job was skipped
  • CI: Dev LTO GlobalDCE, Ubuntu/macOS platform coverage, all primary and compatibility shards, docs, targets, caches, and artifact tests passed
  • CI: macOS shard 0 completed in 31m46s under the 45-minute platform-specific limit; shard 1 completed in 25m10s
  • CI: Ubuntu, macOS, and full-LTO coverage uploads to Codecov completed successfully
  • local diff-aware coverage for the [Based on #2143 #2145 #2157] build: match cmd/link DWARF defaults #2142 layer (bbe3f3a..adf396b6e): 45/45 coverable changed production-Go lines hit (100%)
  • macOS: linker-option/default-policy tests, SSA debug-scope tests, and the previously completed full cl/cltest package
  • macOS: full ./ssa suite with 91.9% package coverage; deferDebugLocation, deferDebugLocationFor, and setDeferDebugLocation each report 100%
  • macOS: runtime Caller, CallersFrames, logging, panic, stack, statement-line, and explicit-DWARF line-site acceptance tests
  • macOS: conditional-defer full-LTO regression, O2 nested range-over-func LLVM verification, and representative executable IR fixtures
  • Ubuntu arm64 with Go 1.26.5 and LLVM 19: SSA defer-location tests, O2 nested range-over-func LLVM verification, conditional-defer full-LTO regression, explicit-DWARF line-site tests, and LTO plugin symbol matrices
  • Ubuntu arm64: the original failing mkdirdemo passes with -lto=full -globaldce
  • dependency CI: [Based on #2159] debug: keep optimization and SSA rewrites DWARF-safe #2143 and [Based on #2143] fix(pclntab): preserve Darwin line sites with DWARF #2157 each completed with 40 successful checks
  • git diff --check upstream/main...HEAD

Ubuntu validation was limited to 2 CPUs, 15 GiB memory, and 512 PIDs.

@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 changed the title [Based on #2141] build: match cmd/link DWARF defaults [Based on #2141 #2143] build: match cmd/link DWARF defaults Jul 21, 2026
@cpunion
cpunion force-pushed the codex/dwarf-default-go-compatible branch from 4141240 to f227cd8 Compare July 22, 2026 08:00
@cpunion cpunion changed the title [Based on #2141 #2143] build: match cmd/link DWARF defaults [Based on #2141 #2143 #2144 #2145 #2146] build: match cmd/link DWARF defaults Jul 22, 2026
@cpunion cpunion changed the title [Based on #2141 #2143 #2144 #2145 #2146] build: match cmd/link DWARF defaults [Based on #2143 #2144 #2145 #2146] build: match cmd/link DWARF defaults Jul 22, 2026
@cpunion
cpunion force-pushed the codex/dwarf-default-go-compatible branch 3 times, most recently from abf8473 to 703cae6 Compare July 22, 2026 17:01
@cpunion cpunion changed the title [Based on #2143 #2144 #2145 #2146] build: match cmd/link DWARF defaults [Based on #2143 #2145 #2157] build: match cmd/link DWARF defaults Jul 22, 2026
@codecov

codecov Bot commented Jul 22, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
cl/static_init.go 87.50% 0 Missing and 1 partial ⚠️

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

1 participant