Skip to content

[Based on #2159] debug: keep optimization and SSA rewrites DWARF-safe#2143

Open
cpunion wants to merge 7 commits into
xgo-dev:mainfrom
cpunion:codex/dwarf-opt-pipeline
Open

[Based on #2159] debug: keep optimization and SSA rewrites DWARF-safe#2143
cpunion wants to merge 7 commits into
xgo-dev:mainfrom
cpunion:codex/dwarf-opt-pipeline

Conversation

@cpunion

@cpunion cpunion commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Based on #2159.

Problem

DWARF must not change executable semantics. Enabling the normal optimization pipeline for debug builds exposed four independent places where debug metadata affected code generation:

  • linked builds skipped the configured LLVM pass pipeline whenever DWARF was emitted
  • conditional defer lowering created inlinable runtime calls without !dbg, so full LTO verification aborted
  • ssa.DebugRef users blocked LLGo's return-load and single-case-select order repairs
  • ssa.DebugRef users blocked otherwise valid static global slice folding

Running full LTO with DWARF also exposes aggregate Go string values to the reflect MethodByName plugin. The prerequisite #2159 handles that plugin boundary independently and preserves both aggregate and legacy split-string analysis. This PR contains no LTO plugin implementation changes.

Changes

  • run the normal LLVM pass pipeline for linked modes with or without DWARF; keep ModeGen as raw generated IR
  • derive the compile unit's optimized marker from the actual pass decision and optimization level
  • inherit the source builder's location when defer lowering splits the entry block
  • move ssa.DebugRef users together with repaired return loads and select assignment dependencies, while still rejecting executable early uses
  • ignore DebugRef pseudo-users when proving a static slice initializer

This consolidates the changes previously proposed in #2144 and #2146. It does not change the default -w policy, Python-specific debugging, pclntab policy, C ABI variable homes, LLDB language behavior, or non-debug optimization policy.

Fixes #2118.
Fixes #2121.
Fixes #2122.

Verification

  • macOS, Go 1.26.5 / LLVM 19: full ssa and internal/build package tests
  • macOS: DWARF plus full-LTO runtime coverage and return/select semantic acceptance
  • Ubuntu arm64: DWARF plus LTO-plugin runtime coverage and four symbol-pruning cases
  • Ubuntu arm64: focused cl, ssa, internal/build, and test/go coverage run (61.5% aggregate package coverage)
  • changed decision, debug-location, value-ordering, and defer-init helpers are exercised directly

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.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% 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!

@cpunion
cpunion force-pushed the codex/dwarf-opt-pipeline branch from 8817c9d to 6e8d80a Compare July 22, 2026 08:19
@cpunion cpunion changed the title [Based on #2141] debug: run LLVM passes with DWARF debug: run LLVM passes with DWARF Jul 22, 2026
@cpunion
cpunion marked this pull request as ready for review July 22, 2026 09:19
@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 debug: run LLVM passes with DWARF debug: keep optimization and SSA rewrites DWARF-safe Jul 22, 2026
@cpunion
cpunion force-pushed the codex/dwarf-opt-pipeline branch from 31a3bbf to d4f4386 Compare July 23, 2026 00:20
@cpunion cpunion changed the title debug: keep optimization and SSA rewrites DWARF-safe [Based on #2159] debug: keep optimization and SSA rewrites DWARF-safe Jul 23, 2026
@cpunion
cpunion force-pushed the codex/dwarf-opt-pipeline branch from d4f4386 to 1955174 Compare July 23, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant