-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Reduce the number of sections in R2R PE files #122511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Use ObjectNodePhase.Ordered + ObjectNodeOrder to identify "well-known" nodes that need to go into PE data directory entries. Also provide a mechanism to fold together sections in the ObjectWriter so we can fold rdata into text and use the "managed code" section for managed code in general and only fold to text in emit. In the process, fix some implicit dependencies that were hidden by "good" ClassCode choices.
There was a problem hiding this comment.
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 reduces the number of sections in R2R PE files by implementing a section folding mechanism and using ObjectNodePhase.Ordered with ObjectNodeOrder to identify well-known nodes that need to be referenced in PE data directory entries.
Key changes:
- Introduces
GetEmitSectionmethod inObjectWriterto allow PE files to foldrdataintotextand use generic managed code sections that get mapped totextat emit time - Implements
RecordWellKnownSymbolmechanism to track symbols that correspond to PE directory entries (Win32 resources, debug directory, CLR header, exception table) - Simplifies node section assignments by removing format-specific logic and relying on emit-time section folding
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Win32ResourcesNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| RuntimeFunctionsTableNode.cs | Changed to return TextSection and added Phase/ClassCode to mark as well-known symbol |
| RuntimeFunctionsGCInfoNode.cs | Simplified to return ReadOnlyDataSection and added Phase/ClassCode for ordering |
| MethodWithGCInfo.cs | Updated to return ManagedCodeWindowsContentSection for PE (gets folded to TextSection at emit) |
| MethodColdCodeNode.cs | Updated to return ManagedCodeWindowsContentSection for PE (gets folded to TextSection at emit) |
| DebugDirectoryNode.cs | Changed to return TextSection and updated ClassCode to use enum value |
| CopiedStrongNameSignatureNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| CopiedMethodILNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| CopiedMetadataBlobNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| CopiedManagedResourcesNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| CopiedFieldRvaNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| CopiedCorHeaderNode.cs | Simplified to always return ReadOnlyDataSection, removing PE-specific logic |
| CoffObjectWriter.Aot.cs | Defined local XDataSection and PDataSection constants to replace removed global constants |
| PEObjectWriter.cs | Implemented GetEmitSection to fold sections and RecordWellKnownSymbol to track PE directory entries; refactored directory population to use symbol-based lookup |
| ObjectWriter.cs | Added GetEmitSection virtual method and RecordWellKnownSymbol callback mechanism |
| CoffObjectWriter.cs | Added handling for SectionType.UnwindData; removed special DebugDirectorySection handling |
| ObjectNodeSection.cs | Removed unused section constants (XDataSection, DebugDirectorySection, CorMetaSection, Win32ResourcesSection, PDataSection) |
| SortableDependencyNode.cs | Made ObjectNodePhase and ObjectNodeOrder enums internal; added new entries for DebugDirectoryNode, RuntimeFunctionsGCInfoNode, and RuntimeFunctionsTableNode |
src/coreclr/tools/Common/Compiler/ObjectWriter/PEObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/PEObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/PEObjectWriter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Remove now-invalid assert
|
I think we may have just pushed some reloc out of range on riscv. @am11 any ideas? |
|
This diff fixes the issue: On riscv64, RuyJIT primarily emits PC-relative call and address-materialization sequences using RISC-V’s design separates address materialization from control transfer and treats linker relaxation as a first-class concept, which allows these generic PC-relative sequences to be reused across symbol classes and code models and adapted by the linker as needed. The main trade-off is that these sequences remain fundamentally limited to a ±2 GB PC-relative range. |
LGTM, thanks :) |
…scv or loongarch64 to avoid issues with relative jump distance.
…ntime into less-pe-sections
src/coreclr/tools/Common/Compiler/ObjectWriter/PEObjectWriter.cs
Outdated
Show resolved
Hide resolved
src/coreclr/tools/Common/Compiler/ObjectWriter/PEObjectWriter.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Adeel Mujahid <[email protected]>
Use
ObjectNodePhase.Ordered+ObjectNodeOrderto identify "well-known" nodes that need to go into PE data directory entries.Also provide a mechanism to fold together sections in the
ObjectWriterso we can foldrdataintotextand use the "managed code" section for managed code in general and only fold to text in emit.In the process, fix some implicit dependencies that were hidden by "good"
ClassCodechoices.Fixes #121416