Skip to content

Support TLS data sections in managed ilasm - #136404

Merged
jkoritzinsky merged 4 commits into
mainfrom
dev/jkoritzinsky/managed-ilasm-tls
Oct 27, 2026
Merged

jkoritzinsky merged 4 commits into
mainfrom
dev/jkoritzinsky/managed-ilasm-tls

Conversation

@jkoritzinsky

Copy link
Copy Markdown
Member

Managed ilasm rejects .data tls declarations and currently moves .data cil into .sdata when emitting vtable fixups. Preserve each declaration's section so TLS data can be emitted correctly and CIL data stays in .text.

  • Track section-relative data locations through parsing, field metadata, and label references.
  • Emit .tls data with a TLS directory, writable index, empty callback list, architecture-appropriate relocations, and the required COR flags.
  • Extend the existing post-layout patching approach to field RVAs, cross-section references, vtable fixups, and export stubs.
  • Keep .data cil in .text, including images containing vtable fixups and TLS data.

Validation

  • .\.dotnet\dotnet.exe test src\tools\ilasm\tests\ILAssembler.Tests\ILAssembler.Tests.csproj --no-restore - passed: 5,425 tests, 3 existing platform-specific skips.
  • .\.dotnet\dotnet.exe test src\tools\ilasm\tests\ILAssembler.Tests\ILAssembler.Tests.csproj --no-restore -c Release - passed: 5,425 tests, 3 existing platform-specific skips.

The new TLS/CIL regression cases failed against the original implementation. Coverage checks x86, x64, and ARM64 PE output, mixed data sections, TLS directories and relocations, cross-section references, exports, large data blocks, and empty declarations.

Note

This pull request was created with GitHub Copilot; its code and description include AI-generated content.

Preserve data section kinds through parsing and patch field RVAs, data references, and native artifacts after section layout. Emit TLS directories and relocations while retaining CIL data in .text.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

Select the custom PE builder for non-CIL data declarations and reserve the standard builder for CIL-only data without native fixups. Keep regular data in .sdata and update section-placement coverage.

Co-authored-by: Copilot App <[email protected]>

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also undo the rewrite of IL tests to C++/CLI so that we have real E2E coverage. I've not looked at the tests, but I'm pretty sure this is just testing how the AI thought this should operate but we need coverage that it actually works.

jkoritzinsky and others added 2 commits October 26, 2026 14:27
Consolidate section patching and debug-directory handling into ILAssemblerPEBuilder. Match native flag-pair semantics for TLS, data references, exports, and Prefer32Bit, while preserving flags for vtable-only images.

Co-authored-by: Copilot App <[email protected]>
Replace string discriminators with ImageKind in the theory data and source-selection switch.

Co-authored-by: Copilot App <[email protected]>
@jkoritzinsky
jkoritzinsky enabled auto-merge (squash) October 27, 2026 00:00
@jkoritzinsky

Copy link
Copy Markdown
Member Author

We should also undo the rewrite of IL tests to C++/CLI so that we have real E2E coverage. I've not looked at the tests, but I'm pretty sure this is just testing how the AI thought this should operate but we need coverage that it actually works.

I'll try to add new IL tests. The C++/CLI tests continue to be more interesting for me as they're the real customer scenario. It should be possible to construct IL tests that will work (I think I can make it work with a netstandard or mscorlib core library).

@MichalStrehovsky

Copy link
Copy Markdown
Member

The C++/CLI tests continue to be more interesting for me as they're the real customer scenario

Is C++/CLI with disabled optimizations really the most interesting real customer scenario?

@jkoritzinsky

Copy link
Copy Markdown
Member Author

Yes. The only supported way to use this feature is C++/CLI. We only disable optimizations so we can validate load and store instructions in a simple manner. I'm fine enabling optimizations, but I was making sure to match the IL instructions from the previous non-working tests.

@jkoritzinsky

Copy link
Copy Markdown
Member Author

/ba-g BA stuck

@jkoritzinsky
jkoritzinsky disabled auto-merge October 27, 2026 17:50
@jkoritzinsky
jkoritzinsky merged commit 138fd3f into main Oct 27, 2026
64 checks passed
@jkoritzinsky
jkoritzinsky deleted the dev/jkoritzinsky/managed-ilasm-tls branch October 27, 2026 17:50
@github-project-automation github-project-automation Bot moved this to Done in AppModel Oct 27, 2026
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 28, 2026
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.

3 participants