Skip to content

Handle ILLink origins before first sequence point - #129869

Merged
sbomer merged 2 commits into
dotnet:mainfrom
sbomer:runtime-illink-crash
Jun 26, 2026
Merged

sbomer merged 2 commits into
dotnet:mainfrom
sbomer:runtime-illink-crash

Conversation

@sbomer

@sbomer sbomer commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #129562.

MessageOrigin.ToString() assumed that every diagnostic IL offset has at least one PDB sequence point at or before that offset. Rewritten/generated IL can put a warning origin before the first sequence point, which made Last() throw while ILLink flushed cached warnings.

This changes the lookup to tolerate that shape by falling back to the first available sequence point, and adds a focused regression test that round-trips a Cecil-generated assembly/PDB to reproduce the real offset behavior.

This content was created with assistance from AI.

Avoid throwing while formatting diagnostics whose IL offset precedes the first available PDB sequence point. Fall back to the first sequence point and cover the case with a focused MessageContainer test.

Assisted-by: Copilot:gpt-5.5

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings June 25, 2026 20:42
@github-actions github-actions Bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Jun 25, 2026
@dotnet-policy-service dotnet-policy-service Bot added the linkable-framework Issues associated with delivering a linker friendly framework label Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.

Copilot AI 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.

Pull request overview

This PR updates ILLink’s diagnostic origin formatting to handle method IL offsets that occur before the first available PDB sequence point, preventing MessageOrigin.ToString() from throwing when generating MSBuild-formatted messages. It also adds a regression test that constructs and round-trips a Cecil-generated assembly + Portable PDB to reproduce the offset shape.

Changes:

  • Make MessageOrigin.ToString() tolerate “origin before first sequence point” by falling back to the first available sequence point instead of throwing.
  • Add a targeted xUnit regression test that emits a Portable PDB where the only sequence point is after the first IL instruction, then verifies ToMSBuildString() output.
Show a summary per file
File Description
src/tools/illink/src/linker/Linker/MessageOrigin.cs Adjusts sequence point selection logic to avoid Last() throwing when no sequence point exists at/before the IL offset.
src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs Adds a Cecil-based regression test covering an origin IL offset occurring before the first sequence point.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Keep the existing LINQ-based sequence point lookup but use LastOrDefault so diagnostics whose IL offset precedes the first sequence point fall back to the tool name instead of throwing, matching ILC behavior.

Assisted-by: Copilot:gpt-5.5

Co-authored-by: Copilot <[email protected]>
@sbomer
sbomer requested a review from a team June 26, 2026 17:24
@sbomer
sbomer merged commit 207ffd1 into dotnet:main Jun 26, 2026
87 checks passed
@github-project-automation github-project-automation Bot moved this to Done in AppModel Jun 26, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 28, 2026
@sbomer
sbomer deleted the runtime-illink-crash branch June 30, 2026 22:53
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Fixes #129562.

`MessageOrigin.ToString()` assumed that every diagnostic IL offset has
at least one PDB sequence point at or before that offset.
Rewritten/generated IL can put a warning origin before the first
sequence point, which made `Last()` throw while ILLink flushed cached
warnings.

This changes the lookup to tolerate that shape by falling back to the
first available sequence point, and adds a focused regression test that
round-trips a Cecil-generated assembly/PDB to reproduce the real offset
behavior.

*This content was created with assistance from AI.*

---------

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 31, 2026
@agocke

agocke commented Oct 26, 2026

Copy link
Copy Markdown
Member

/backport to release/10.0

@github-actions github-actions Bot unlocked this conversation Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0 (link to workflow run)

@github-actions

Copy link
Copy Markdown
Contributor

@agocke backporting to release/10.0 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git cherry-pick 207ffd155f96b38be1749584b99f3ac0a505218c

Auto-merging src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs
CONFLICT (content): Merge conflict in src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs
error: could not apply 207ffd155f9... Handle ILLink origins before first sequence point (#129869)
hint: After resolving the conflicts, mark them with
hint: "git add/rm <pathspec>", then run
hint: "git cherry-pick --continue".
hint: You can instead skip this commit with "git cherry-pick --skip".
hint: To abort and get back to the state before "git cherry-pick",
hint: run "git cherry-pick --abort".
hint: Disable this message with "git config set advice.mergeConflict false"


$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Handle ILLink origins before first sequence point
Using index info to reconstruct a base tree...
M	src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs
Falling back to patching base and 3-way merge...
Auto-merging src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs
CONFLICT (content): Merge conflict in src/tools/illink/test/Mono.Linker.Tests/Tests/MessageContainerTests.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Handle ILLink origins before first sequence point
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[area-Tools-ILLink]: Trimmer warnings crash the build

4 participants