Skip to content

crossgen2: Add --rtr-header-symbol-name opt-in option for custom ReadyToRun header symbol#126515

Merged
jkoritzinsky merged 4 commits intomainfrom
copilot/add-opt-in-support-readytorun-header
Apr 6, 2026
Merged

crossgen2: Add --rtr-header-symbol-name opt-in option for custom ReadyToRun header symbol#126515
jkoritzinsky merged 4 commits intomainfrom
copilot/add-opt-in-support-readytorun-header

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

Description

Adds an opt-in crossgen2 command-line option --rtr-header-symbol-name to override the exported ReadyToRun header symbol name (default: RTR_HEADER) for composite builds. This supports custom hosts that directly link against multiple R2R images — rather than loading them dynamically via dlopen or equivalent — where each image needs a distinct export symbol name to avoid collisions.

Code changes

  • Introduces --rtr-header-symbol-name <name> in crossgen2, validated to require --composite and to be non-empty/non-whitespace. Works with both PE and Mach-O output formats (Mach-O is the primary scenario).
  • Adds CompositeImageSettings.ReadyToRunHeaderSymbolName to carry the value through compilation.
  • Uses the setting via GetSymbolAlternateName in the base ObjectWriter, which applies to all object format writers (PE and Mach-O).
  • For PE composite builds, also exports the symbol via PEObjectWriter.AddExportedSymbol.
  • Uses string.IsNullOrEmpty / string.IsNullOrWhiteSpace fallback guards to "RTR_HEADER" in ReadyToRunCodegenNodeFactory and ReadyToRunObjectWriter to prevent empty/invalid symbol names.

Documentation changes

  • readytorun-format.md: notes RTR_HEADER is customizable via --rtr-header-symbol-name; adds explanation of the custom-host use case in the Structures section.
  • readytorun-platform-native-envelope.md: notes the symbol name is customizable in the bullet list; adds a dedicated "Customizing the RTR_HEADER symbol name" subsection (without redundant --composite or format constraints, since composite is always required in this context and Mach-O is the primary scenario).
  • readytorun-composite-format-design.md: notes RTR_HEADER customizability in both relevant locations.

…n header symbol name

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/861662d6-3208-41e7-a555-c9e87de7181f

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
@jkoritzinsky
Copy link
Copy Markdown
Member

@rolfbjarne this PR implements the ability to specify the R2R symbol name so dotnet/macios won't have to rewrite the symbol names to support multiple R2R images.

@jkoritzinsky jkoritzinsky marked this pull request as ready for review April 3, 2026 20:57
Copilot AI review requested due to automatic review settings April 3, 2026 20:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an opt-in crossgen2 command-line option to override the exported ReadyToRun header symbol name (default RTR_HEADER) for composite builds, and plumbs that setting through to the R2R object writer and symbol naming.

Changes:

  • Introduces --rtr-header-symbol-name <name> and validates it requires --composite.
  • Adds CompositeImageSettings.ReadyToRunHeaderSymbolName to carry the value through compilation.
  • Uses the setting when naming the R2R header symbol and when exporting the PE symbol.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs Uses CompositeImageSettings.ReadyToRunHeaderSymbolName as the alternate symbol name for the R2R header.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/Compiler/CompositeImageSettings.cs Adds a field to carry the custom header symbol name through the pipeline.
src/coreclr/tools/aot/ILCompiler.ReadyToRun/CodeGen/ReadyToRunObjectWriter.cs Exports the configured header symbol name (PE composite build).
src/coreclr/tools/aot/crossgen2/Properties/Resources.resx Adds option help text and a new error string.
src/coreclr/tools/aot/crossgen2/Program.cs Parses/validates the new option and sets it on CompositeImageSettings.
src/coreclr/tools/aot/crossgen2/Crossgen2RootCommand.cs Registers the new --rtr-header-symbol-name option.

@jkoritzinsky
Copy link
Copy Markdown
Member

@copilot please address the feedback

… and PE format, fix IsNullOrEmpty fallbacks

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/66091b3b-2d80-4df7-bf1a-1a5bb3944465

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 3, 2026

@copilot please address the feedback

Done in 3665b44. The three review items are addressed:

  • Program.cs: validation now rejects empty/whitespace symbol names and non-PE output formats, with proper error messages
  • ReadyToRunCodegenNodeFactory.GetSymbolAlternateName: uses string.IsNullOrEmpty fallback
  • ReadyToRunObjectWriter: uses string.IsNullOrWhiteSpace fallback

…e in R2R docs

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/53565a7b-a2b2-4e0b-8a66-ea67cc354f8c

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/874de5dc-b706-4578-8581-2385601704ab

Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Copy link
Copy Markdown
Member

@rolfbjarne rolfbjarne left a comment

Choose a reason for hiding this comment

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

This is great, thanks!

@jkoritzinsky
Copy link
Copy Markdown
Member

/ba-g build analysis stuck and all lanes green

@jkoritzinsky jkoritzinsky enabled auto-merge (squash) April 6, 2026 18:32
@jkoritzinsky jkoritzinsky merged commit 212023b into main Apr 6, 2026
115 checks passed
@jkoritzinsky jkoritzinsky deleted the copilot/add-opt-in-support-readytorun-header branch April 6, 2026 18:32
@github-project-automation github-project-automation bot moved this to Done in AppModel Apr 6, 2026
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Apr 9, 2026
…yToRun header symbol (dotnet#126515)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jkoritzinsky <1571408+jkoritzinsky@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants