Skip to content

Deduplicate assembly macros between CoreCLR and NativeAOT - #136638

Merged
jkotas merged 12 commits into
dotnet:mainfrom
am11:chore/dedup-asm-macros
Oct 30, 2026
Merged

jkotas merged 12 commits into
dotnet:mainfrom
am11:chore/dedup-asm-macros

Conversation

@am11

@am11 am11 commented Oct 29, 2026

Copy link
Copy Markdown
Member

Split out of #136626 per review feedback.

  • Moved the macros duplicated between the PAL and NativeAOT unixasmmacros*.inc into runtime/<arch>/UnixAsmMacros.inc (amd64, arm, arm64, loongarch64, riscv64).
  • Moved the common Windows macros into runtime/amd64/AsmMacros_Common.inc, runtime/arm64/AsmMacros_Common.h (SETALIAS, INLINE_GET_TLS_VAR) and runtime/i386/AsmMacros_Common.inc (ALTERNATE_ENTRY).
  • NativeAOT GcProbe/UniversalTransition now use the shared argument register save/restore macros.
  • Deleted the unused runtime/<arch>/StubDispatch.* files.

Validated by building linux-x64 CoreCLR + NativeAOT and running P/Invoke, stack probe/GC poll and EH tests. I also cross-assembled all Unix .S files for amd64/arm/arm64/loongarch64/riscv64 (+ Apple, release and emulated TLS variants) before and after, and the objects are byte-identical except NativeAOT amd64 GcProbe.S, where the xmm save slots are now in register order. The Windows MASM parts were checked with llvm-ml/preprocessor comparisons (real ml64/armasm64 are not available locally).

- Move the common Unix macros into runtime/<arch>/UnixAsmMacros.inc.
- Move the common Windows macros into runtime/amd64/AsmMacros_Common.inc,
  runtime/arm64/AsmMacros_Common.h and runtime/i386/AsmMacros_Common.inc.
- Use the shared argument register save/restore macros in NativeAOT GcProbe
  and UniversalTransition.
- Delete the unused runtime/<arch>/StubDispatch files.
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 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: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

am11 added 2 commits October 29, 2026 19:50
Move the general-purpose macros that only one runtime defined (prolog and
epilog helpers, register save and restore helpers, entry/end/label macros,
barriers, PREPARE_EXTERNAL_VAR variants, nop and return encodings) into the
shared per-architecture macro files, including the identical MOVL64,
PREPARE_EXTERNAL_VAR_INDIRECT(_W) and InterlockedOperationBarrier copies in
CoreCLR's AsmMacros_Shared.h.

The shared Windows arm64 INLINE_GET_TLS_VAR declares the TLS variable as
EXTERN itself again, so its callers no longer need to.
am11 added 2 commits October 29, 2026 21:48
Drop the unused NativeAOT-only '.global _Name' on amd64, and use .hidden for LEAF_ENTRY in both runtimes on arm64 and loongarch64 (matching ALTERNATE_ENTRY).

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.

🟡 Changes recommended

The shared ARM64 macro changes NativeAOT’s breakpoint encoding, so its objects cannot be byte-identical to the previous ones as claimed.

1 open issue
What changed in this PR

This PR separates assembly-macro deduplication from #136626, moving common definitions into CoreCLR’s shared runtime directory so CoreCLR and NativeAOT use the same implementations.

Changes:

  • Consolidates Unix and Windows assembly macros and updates their consumers.
  • Reuses argument-register save/restore macros in NativeAOT helpers, with related unwind and label adjustments.
  • Removes unused dispatch-stub files and their build entry.
File Description
src/​coreclr/​vm/​i386/​AsmMacros.inc Uses shared Windows x86 macros.
src/​coreclr/​vm/​arm64/​asmmacros.h Uses shared Windows ARM64 macros.
src/​coreclr/​vm/​arm64/​AsmMacros_Shared.h Removes definitions moved into shared includes.
src/​coreclr/​vm/​amd64/​AsmMacros.inc Uses shared Windows AMD64 macros.
src/​coreclr/​runtime/​s390x/​StubDispatch.S Removes unused stub file.
src/​coreclr/​runtime/​riscv64/​StubDispatch.S Removes unused dispatch implementation.
src/​coreclr/​runtime/​riscv64/​InlineTls.inc Moves TLS macro into the shared architecture include.
src/​coreclr/​runtime/​riscv64/​AsmMacros_Unix.inc Centralizes RISC-V Unix macros.
src/​coreclr/​runtime/​ppc64le/​StubDispatch.S Removes unused stub file.
src/​coreclr/​runtime/​loongarch64/​StubDispatch.S Removes unused dispatch implementation.
src/​coreclr/​runtime/​loongarch64/​InlineTls.inc Moves TLS macro into the shared architecture include.
src/​coreclr/​runtime/​loongarch64/​AsmMacros_Unix.inc Centralizes LoongArch64 Unix macros.
src/​coreclr/​runtime/​i386/​StubDispatch.S Removes unused placeholder.
src/​coreclr/​runtime/​i386/​StubDispatch.asm Removes unused Windows dispatch implementation.
src/​coreclr/​runtime/​i386/​AsmMacros_Windows.inc Centralizes Windows x86 macros and constants.
src/​coreclr/​runtime/​i386/​AsmMacros_Unix.inc Centralizes Unix x86 macros.
src/​coreclr/​runtime/​AsmMacros_Unix.inc Shares architecture-independent Unix definitions.
src/​coreclr/​runtime/​arm64/​AsmMacros_Windows.h Centralizes Windows ARM64 macros.
src/​coreclr/​runtime/​arm64/​AsmMacros_Unix.inc Centralizes Unix ARM64 macros.
src/​coreclr/​runtime/​arm/​StubDispatch.S Removes unused dispatch implementation.
src/​coreclr/​runtime/​arm/​AsmMacros_Unix.inc Centralizes Unix ARM macros.
src/​coreclr/​runtime/​amd64/​AsmMacros_Windows.inc Centralizes Windows AMD64 macros.
src/​coreclr/​runtime/​amd64/​AsmMacros_Unix.inc Centralizes Unix AMD64 macros.
src/​coreclr/​pal/​src/​arch/​loongarch64/​callsignalhandlerwrapper.S Removes redundant unwind-offset adjustment.
src/​coreclr/​pal/​inc/​unixasmmacrosx86.inc Imports shared x86 definitions.
src/​coreclr/​pal/​inc/​unixasmmacrosriscv64.inc Imports shared RISC-V definitions.
src/​coreclr/​pal/​inc/​unixasmmacrosloongarch64.inc Imports shared LoongArch64 definitions.
src/​coreclr/​pal/​inc/​unixasmmacrosarm64.inc Imports shared ARM64 definitions.
src/​coreclr/​pal/​inc/​unixasmmacrosarm.inc Imports shared ARM definitions.
src/​coreclr/​pal/​inc/​unixasmmacrosamd64.inc Imports shared AMD64 definitions.
src/​coreclr/​pal/​inc/​unixasmmacros.inc Imports common Unix definitions.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosx86.inc Replaces duplicated macros with shared include.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosriscv64.inc Imports shared macros and uses the fp alias.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosloongarch64.inc Replaces duplicated macros with shared include.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosarm64.inc Replaces duplicated macros with shared include.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosarm.inc Replaces duplicated macros with shared include.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacrosamd64.inc Replaces duplicated macros with shared include.
src/​coreclr/​nativeaot/​Runtime/​unix/​unixasmmacros.inc Imports common Unix definitions.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​UniversalTransition.S Uses shared argument save/restore macros.
src/​coreclr/​nativeaot/​Runtime/​riscv64/​ExceptionHandling.S Adapts stack adjustments to shared unwind conventions.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​UniversalTransition.S Uses shared argument-save macros.
src/​coreclr/​nativeaot/​Runtime/​loongarch64/​ExceptionHandling.S Adapts stack adjustments to shared unwind conventions.
src/​coreclr/​nativeaot/​Runtime/​i386/​AsmMacros.inc Imports shared Windows x86 definitions.
src/​coreclr/​nativeaot/​Runtime/​CMakeLists.txt Removes the dispatch-stub build entry.
src/​coreclr/​nativeaot/​Runtime/​arm64/​UniversalTransition.S Uses shared floating-point save/restore macros.
src/​coreclr/​nativeaot/​Runtime/​arm64/​ThunkPoolThunks.S Defines the thunk-pool label explicitly.
src/​coreclr/​nativeaot/​Runtime/​arm64/​GcProbe.S Reuses floating-point argument macros.
src/​coreclr/​nativeaot/​Runtime/​arm64/​AsmMacros.h Imports shared Windows ARM64 definitions.
src/​coreclr/​nativeaot/​Runtime/​amd64/​UniversalTransition.S Defines floating-point save-area size locally.
src/​coreclr/​nativeaot/​Runtime/​amd64/​ThunkPoolThunks.S Defines the thunk-pool label explicitly.
src/​coreclr/​nativeaot/​Runtime/​amd64/​GcProbe.S Uses shared macros with register-ordered save slots.
src/​coreclr/​nativeaot/​Runtime/​amd64/​AsmMacros.inc Imports shared Windows AMD64 definitions.

Review effort: Balanced

@jkotas jkotas 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.

Thanks

@jkotas
jkotas merged commit a666f11 into dotnet:main Oct 30, 2026
104 checks passed
@am11
am11 deleted the chore/dedup-asm-macros branch October 30, 2026 09:38
steveisok added a commit that referenced this pull request Nov 1, 2026
<!-- -->
Add the shared `AsmMacros_Unix.inc` and its six architecture-specific
files to the universal DBI source manifest using exact paths, without
importing unrelated runtime implementation files.

This fixes the missing assembly macro dependency closure behind the Unix
universal DBI mirror build failures in
[dotnet/diagnostics#6167](dotnet/diagnostics#6167)
after [#136638](#136638). Existing
include paths remain unchanged.

Validation: manifest-produced `git archive` snapshots reproduced the
missing include before the fix and passed all 18 PAL macro preprocessing
checks afterward. Six Linux/macOS PAL assembly smoke checks passed. Full
CoreCLR/diagnostics builds were not run; RISC-V assembly was blocked by
installed Apple clang support, and LoongArch assembly was not run. Both
passed preprocessing.

> [!NOTE]
> This PR was prepared by GitHub Copilot.

Co-authored-by: Copilot App <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants