From 7434c57c28b6304325997bd61c1757553d56d828 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 25 May 2026 09:47:21 +0000
Subject: [PATCH 01/27] Add NativeAOT fat executable Unix support

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/69bd1576-bcad-4ee1-aa5e-af9513609eea

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Publish.targets  | 20 +++++-
 .../Microsoft.NETCore.Native.Unix.targets     | 64 +++++++++++++++++++
 .../Microsoft.NETCore.Native.Windows.targets  | 61 ++++++++++++++++++
 .../Microsoft.NETCore.Native.targets          | 45 +++++++++++++
 .../Compiler/MainMethodRootProvider.cs        | 12 ++--
 .../StartupCodeMainMethod.Sorting.cs          |  9 +--
 .../aot/ILCompiler/ILCompilerRootCommand.cs   |  3 +
 src/coreclr/tools/aot/ILCompiler/Program.cs   | 18 +++++-
 src/tests/Directory.Build.targets             |  2 +-
 .../FatExecutableLibrary/FatLibrary.csproj    | 41 ++++++++++++
 .../FatExecutableLibrary/HelloExe/HelloExe.cs |  6 ++
 .../HelloExe/HelloExe.csproj                  |  9 +++
 .../ValidatorExe/ValidatorExe.cs              | 31 +++++++++
 .../ValidatorExe/ValidatorExe.csproj          |  9 +++
 14 files changed, 314 insertions(+), 16 deletions(-)
 create mode 100644 src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj
 create mode 100644 src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.cs
 create mode 100644 src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.csproj
 create mode 100644 src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
 create mode 100644 src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.csproj

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
index bf473414890f6c..5af6b4adc3af26 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
@@ -29,7 +29,7 @@
     ============================================================
   -->
   <Target Name="NativeCompile"
-          DependsOnTargets="_ComputeAssembliesToCompileToNative;LinkNative">
+          DependsOnTargets="_ComputeAssembliesToCompileToNative;LinkNative;CreateShimExes">
 
     <ItemGroup>
       <ResolvedFileToPublish Remove="@(_IlcManagedInputAssemblies)" />
@@ -41,6 +41,24 @@
         <RelativePath>$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
+      <ResolvedFileToPublish Include="@(_FatExecutableShim)" Condition="'$(FatExecutable)' == 'true'">
+        <RelativePath>%(_FatExecutableShim.RelativePath)</RelativePath>
+        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
+      </ResolvedFileToPublish>
+      <ResolvedFileToPublish Include="@(_FatExecutableShimSymbol)"
+                             Condition="'$(FatExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' != '.dSYM' and Exists('%(_FatExecutableShimSymbol.Identity)')">
+        <RelativePath>%(_FatExecutableShimSymbol.RelativePath)</RelativePath>
+        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
+      </ResolvedFileToPublish>
+      <_FatExecutableShimSymbolRecursivePath Include="%(_FatExecutableReferencePath.ShimSymbol)/**/*"
+                                             Condition="'$(FatExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' == '.dSYM' and Exists('%(_FatExecutableReferencePath.ShimSymbol)')">
+        <RelativePath>%(_FatExecutableReferencePath.TargetName)$(NativeSymbolExt)/%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
+      </_FatExecutableShimSymbolRecursivePath>
+      <ResolvedFileToPublish Include="@(_FatExecutableShimSymbolRecursivePath)"
+                             Condition="'$(FatExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
+        <RelativePath>%(_FatExecutableShimSymbolRecursivePath.RelativePath)</RelativePath>
+        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
+      </ResolvedFileToPublish>
     </ItemGroup>
 
     <PropertyGroup Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 6ec997d6c237ae..906d2d02d349ae 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -376,4 +376,68 @@ The .NET Foundation licenses this file to you under the MIT license.
       <DsymUtilOptions>$(DsymUtilOptions) --minimize</DsymUtilOptions>
     </PropertyGroup>
   </Target>
+
+  <Target Name="CreateShimExes"
+          Condition="'$(FatExecutable)' == 'true'"
+          DependsOnTargets="LinkNative;WriteFatExecutableShimRspFiles"
+          Inputs="$(NativeBinary);@(_FatExecutableReferencePath->'%(ShimSource)');@(_FatExecutableReferencePath->'%(ShimCompileRspFile)');@(_FatExecutableReferencePath->'%(ShimLinkRspFile)')"
+          Outputs="@(_FatExecutableShim);@(_FatExecutableShimSymbol)">
+
+    <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
+    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimCompileRspFile)&quot;" />
+    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimLinkRspFile)&quot;" />
+    <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
+          Command="&quot;$(ObjCopyName)&quot; --only-keep-debug &quot;%(_FatExecutableReferencePath.ShimBinary)&quot; &quot;%(_FatExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot;" />
+    <Exec Condition="'$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
+          Command="&quot;$(ObjCopyName)&quot; --strip-debug --strip-unneeded &quot;%(_FatExecutableReferencePath.ShimBinary)&quot;" />
+    <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
+          Command="&quot;$(ObjCopyName)&quot; --add-gnu-debuglink=&quot;%(_FatExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot; &quot;%(_FatExecutableReferencePath.ShimBinary)&quot;" />
+    <Exec Condition="'$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' == 'true'"
+          IgnoreStandardErrorWarningFormat="true"
+          Command="
+            dsymutil $(DsymUtilOptions) &quot;%(_FatExecutableReferencePath.ShimBinary)&quot; &amp;&amp;
+            strip -no_code_signature_warning -x &quot;%(_FatExecutableReferencePath.ShimBinary)&quot;" />
+  </Target>
+
+  <Target Name="WriteFatExecutableShimRspFiles"
+          Condition="'$(FatExecutable)' == 'true'"
+          DependsOnTargets="LinkNative">
+
+    <ItemGroup>
+      <_FatExecutableReferencePath>
+        <ShimSourceCode><![CDATA[extern int %(_FatExecutableReferencePath.EntryPointSymbol)(int, char**);
+
+int main(int argc, char** argv)
+{
+    return %(_FatExecutableReferencePath.EntryPointSymbol)(argc, argv);
+}
+]]></ShimSourceCode>
+      </_FatExecutableReferencePath>
+    </ItemGroup>
+
+    <ItemGroup>
+      <_FatExecutableShimCompilerArg Include="-c" />
+      <_FatExecutableShimCompilerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
+      <_FatExecutableShimCompilerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
+      <_FatExecutableShimCompilerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimCompilerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
+
+      <_FatExecutableShimLinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
+      <_FatExecutableShimLinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
+      <_FatExecutableShimLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
+      <_FatExecutableShimLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-rpath,$ORIGIN" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" />
+    </ItemGroup>
+
+    <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
+    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_FatExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimCompileRspFile)" Lines="@(_FatExecutableShimCompilerArg);&quot;%(_FatExecutableReferencePath.ShimSource)&quot;;-o;&quot;%(_FatExecutableReferencePath.ShimObject)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_FatExecutableReferencePath.ShimObject)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_FatExecutableReferencePath.ShimBinary)&quot;;@(_FatExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+  </Target>
 </Project>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 25fb0b7fae9205..bc80e765958137 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -15,6 +15,7 @@ The .NET Foundation licenses this file to you under the MIT license.
 <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <CppLinker>link</CppLinker>
+    <CppCompiler>cl</CppCompiler>
     <CppLibCreator>lib</CppLibCreator>
     <ObjectSuffix>.obj</ObjectSuffix>
     <LibrarySuffix>.lib</LibrarySuffix>
@@ -136,10 +137,70 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <PropertyGroup Condition="'$(_VCVarsAllFound)' == '0'">
       <_CppToolsDirectory>$(_FindVCVarsallOutput.Split(`#`)[0])</_CppToolsDirectory>
+      <CppCompiler>$(_CppToolsDirectory)cl.exe</CppCompiler>
       <CppLinker>$(_CppToolsDirectory)link.exe</CppLinker>
       <CppLibCreator>$(_CppToolsDirectory)lib.exe</CppLibCreator>
     </PropertyGroup>
 
     <Error Condition="'$(_VCVarsAllFound)' == '1'" Text="Platform linker not found. Ensure you have all the required prerequisites documented at https://aka.ms/nativeaot-prerequisites, in particular the Desktop Development for C++ workload in Visual Studio. For ARM64 development also install C++ ARM64 build tools." />
   </Target>
+
+  <Target Name="CreateShimExes"
+          Condition="'$(FatExecutable)' == 'true'"
+          DependsOnTargets="LinkNative;WriteFatExecutableShimRspFiles"
+          Inputs="$(NativeImportLibrary);@(_FatExecutableReferencePath->'%(ShimSource)');@(_FatExecutableReferencePath->'%(ShimCompileRspFile)');@(_FatExecutableReferencePath->'%(ShimLinkRspFile)')"
+          Outputs="@(_FatExecutableShim);@(_FatExecutableShimSymbol)">
+
+    <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
+    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_FatExecutableReferencePath.ShimCompileRspFile)&quot;" />
+    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimLinkRspFile)&quot;" />
+  </Target>
+
+  <Target Name="WriteFatExecutableShimRspFiles"
+          Condition="'$(FatExecutable)' == 'true'"
+          DependsOnTargets="LinkNative">
+
+    <ItemGroup>
+      <_FatExecutableReferencePath>
+        <ShimSourceCode><![CDATA[__declspec(dllimport) int %(_FatExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
+
+int wmain(int argc, unsigned short** argv)
+{
+    return %(_FatExecutableReferencePath.EntryPointSymbol)(argc, argv);
+}
+]]></ShimSourceCode>
+        <ShimPdbLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'">/PDB:"%(_FatExecutableReferencePath.ShimSymbol)"</ShimPdbLinkerArg>
+      </_FatExecutableReferencePath>
+    </ItemGroup>
+
+    <ItemGroup>
+      <_FatExecutableShimCompilerArg Include="/nologo" />
+      <_FatExecutableShimCompilerArg Include="/c" />
+      <_FatExecutableShimCompilerArg Include="/MT" />
+      <_FatExecutableShimCompilerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/Z7" />
+      <_FatExecutableShimCompilerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
+
+      <_FatExecutableShimLinkerArg Include="/NOLOGO" />
+      <_FatExecutableShimLinkerArg Include="/MANIFEST:NO" />
+      <_FatExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
+      <_FatExecutableShimLinkerArg Include="/STACK:$(IlcDefaultStackSize)" />
+      <_FatExecutableShimLinkerArg Include="/INCREMENTAL:NO" />
+      <_FatExecutableShimLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/DEBUG" />
+      <_FatExecutableShimLinkerArg Include="/NODEFAULTLIB:libucrt.lib" />
+      <_FatExecutableShimLinkerArg Include="/DEFAULTLIB:ucrt.lib" />
+      <_FatExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:REF" />
+      <_FatExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:ICF" />
+      <_FatExecutableShimLinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
+      <_FatExecutableShimLinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh" />
+      <_FatExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT" />
+      <_FatExecutableShimLinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO" />
+      <_FatExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont" />
+      <_FatExecutableShimLinkerArg Include="@(AdditionalNativeLibraryDirectories->'/LIBPATH:&quot;%(Identity)&quot;')" />
+    </ItemGroup>
+
+    <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
+    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_FatExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimCompileRspFile)" Lines="@(_FatExecutableShimCompilerArg);&quot;%(_FatExecutableReferencePath.ShimSource)&quot;;/Fo&quot;%(_FatExecutableReferencePath.ShimObject)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_FatExecutableReferencePath.ShimObject)&quot;;&quot;$(NativeImportLibrary)&quot;;/OUT:&quot;%(_FatExecutableReferencePath.ShimBinary)&quot;;/SUBSYSTEM:%(_FatExecutableReferencePath.ShimLinkerSubsystem);%(_FatExecutableReferencePath.ShimPdbLinkerArg);@(_FatExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+  </Target>
 </Project>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index 9c961cbee95b34..7321a5a727d3ee 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -82,6 +82,9 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <NativeObject>$(NativeIntermediateOutputPath)$(TargetName)$(NativeObjectExt)</NativeObject>
     <NativeBinary>$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</NativeBinary>
+    <NativeImportLibrary Condition="'$(NativeImportLibrary)' == '' and '$(_targetOS)' == 'win' and '$(NativeLib)' == 'Shared'">$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(LibFileExt)</NativeImportLibrary>
+    <NativeExecutableExt Condition="'$(NativeExecutableExt)' == '' and '$(_targetOS)' == 'win'">.exe</NativeExecutableExt>
+    <NativeExecutableExt Condition="'$(NativeExecutableExt)' == ''"></NativeExecutableExt>
     <IlcExportUnmanagedEntrypoints Condition="'$(IlcExportUnmanagedEntrypoints)' == '' and '$(NativeLib)' == 'Shared'">true</IlcExportUnmanagedEntrypoints>
     <ExportsFile Condition="$(ExportsFile) == '' and '$(BuildingFrameworkLibrary)' != 'true'">$(NativeIntermediateOutputPath)$(TargetName)$(ExportsFileExt)</ExportsFile>
 
@@ -100,6 +103,7 @@ The .NET Foundation licenses this file to you under the MIT license.
   <PropertyGroup Condition="'$(IlcCompileDependsOn)'=='' and '$(NativeCompilationDuringPublish)' != 'false'">
     <IlcCompileDependsOn Condition="'$(BuildingFrameworkLibrary)' != 'true'">Compile;ComputeIlcCompileInputs</IlcCompileDependsOn>
     <IlcCompileDependsOn Condition="'$(IlcMultiModule)' == 'true' and '$(BuildingFrameworkLibrary)' != 'true'">$(IlcCompileDependsOn);BuildFrameworkLib</IlcCompileDependsOn>
+    <IlcCompileDependsOn Condition="'$(FatExecutable)' == 'true'">$(IlcCompileDependsOn);ComputeFatExecutableInputs</IlcCompileDependsOn>
     <IlcCompileDependsOn>$(IlcCompileDependsOn);SetupOSSpecificProps</IlcCompileDependsOn>
   </PropertyGroup>
 
@@ -168,6 +172,44 @@ The .NET Foundation licenses this file to you under the MIT license.
     </ItemGroup>
   </Target>
 
+  <Target Name="ComputeFatExecutableInputs"
+          Condition="'$(FatExecutable)' == 'true'"
+          DependsOnTargets="ResolveReferences">
+
+    <Error Condition="'$(OutputType)' != 'Library'" Text="FatExecutable requires OutputType=Library." />
+    <Error Condition="'$(NativeLib)' != 'Shared'" Text="FatExecutable requires NativeLib=Shared." />
+
+    <ItemGroup>
+      <_FatExecutableReferencePath Include="@(ReferencePath)"
+                                   Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IncludeInFatExe)' == 'true'">
+        <AssemblyName>%(ReferencePath.Filename)</AssemblyName>
+        <SanitizedAssemblyName>$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
+        <AssemblyNameHash>$([MSBuild]::StableStringHash('%(ReferencePath.Filename)', 'Sha256'))</AssemblyNameHash>
+        <TargetName>%(ReferencePath.Filename)</TargetName>
+      </_FatExecutableReferencePath>
+      <_FatExecutableReferencePath>
+        <EntryPointSymbol>_FatExeMain_%(SanitizedAssemblyName)_%(AssemblyNameHash)</EntryPointSymbol>
+        <ShimLinkerSubsystem Condition="'%(_FatExecutableReferencePath.LinkerSubsystem)' != ''">%(_FatExecutableReferencePath.LinkerSubsystem)</ShimLinkerSubsystem>
+        <ShimLinkerSubsystem Condition="'%(_FatExecutableReferencePath.LinkerSubsystem)' == '' and '$(LinkerSubsystem)' != ''">$(LinkerSubsystem)</ShimLinkerSubsystem>
+        <ShimLinkerSubsystem Condition="'%(_FatExecutableReferencePath.LinkerSubsystem)' == '' and '$(LinkerSubsystem)' == ''">CONSOLE</ShimLinkerSubsystem>
+        <ShimSource>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe.c</ShimSource>
+        <ShimObject>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe$(NativeObjectExt)</ShimObject>
+        <ShimCompileRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe.cl.rsp</ShimCompileRspFile>
+        <ShimLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe.link.rsp</ShimLinkRspFile>
+        <ShimBinary>$(NativeOutputPath)%(TargetName)$(NativeExecutableExt)</ShimBinary>
+        <ShimSymbol>$(NativeOutputPath)%(TargetName)$(NativeSymbolExt)</ShimSymbol>
+      </_FatExecutableReferencePath>
+      <_FatExecutableShim Include="%(_FatExecutableReferencePath.ShimBinary)">
+        <RelativePath>%(_FatExecutableReferencePath.TargetName)$(NativeExecutableExt)</RelativePath>
+      </_FatExecutableShim>
+      <_FatExecutableShimSymbol Include="%(_FatExecutableReferencePath.ShimSymbol)" Condition="'$(NativeDebugSymbols)' == 'true'">
+        <RelativePath>%(_FatExecutableReferencePath.TargetName)$(NativeSymbolExt)</RelativePath>
+      </_FatExecutableShimSymbol>
+    </ItemGroup>
+
+    <Error Condition="'@(_FatExecutableReferencePath)' == ''" Text="FatExecutable requires at least one ProjectReference with IncludeInFatExe=true." />
+  </Target>
+
   <!--
     BuildFrameworkLib is invoked before IlcCompile in multi-module builds to
     produce the shared framework library on demand
@@ -286,6 +328,8 @@ The .NET Foundation licenses this file to you under the MIT license.
 
       <!-- Export the managed entry point if building a native library in custom main mode -->
       <IlcArg Condition="'$(NativeLib)' == 'Shared' and '$(CustomNativeMain)' == 'true'" Include="--export-dynamic-symbol:__managed__Main" />
+      <IlcArg Condition="'$(FatExecutable)' == 'true'" Include="@(_FatExecutableReferencePath->'--fatexe:%(AssemblyName)=%(EntryPointSymbol)')" />
+      <IlcArg Condition="'$(FatExecutable)' == 'true'" Include="@(_FatExecutableReferencePath->'--export-dynamic-symbol:%(EntryPointSymbol)')" />
 
       <IlcArg Condition="'$(_InstrumentReachability)' == 'true'" Include="--reachabilityinstrument" />
       <IlcArg Condition="'$(_InstrumentReachability)' == 'true'" Include="--feature:Internal.Runtime.CompilerHelpers.ReachabilityInstrumentationSupport=true" />
@@ -336,6 +380,7 @@ The .NET Foundation licenses this file to you under the MIT license.
       <CustomLinkerArg Include="&quot;$(NativeObject)&quot;" />
       <CustomLinkerArg Include="-o &quot;$(NativeBinary)&quot;" Condition="'$(_targetOS)' != 'win'" />
       <CustomLinkerArg Include="/OUT:&quot;$(NativeBinary)&quot;" Condition="'$(_targetOS)' == 'win'" />
+      <CustomLinkerArg Include="/IMPLIB:&quot;$(NativeImportLibrary)&quot;" Condition="'$(_targetOS)' == 'win' and '$(NativeLib)' == 'Shared' and '$(NativeImportLibrary)' != ''" />
       <CustomLinkerArg Include="/DEF:&quot;$(ExportsFile)&quot;" Condition="'$(_targetOS)' == 'win' and $(ExportsFile) != ''" />
       <CustomLinkerArg Include="/LIBPATH:&quot;%(AdditionalNativeLibraryDirectories.Identity)&quot;" Condition="'$(_targetOS)' == 'win' and '@(AdditionalNativeLibraryDirectories->Count())' &gt; 0" />
       <CustomLinkerArg Include="-exported_symbols_list &quot;$(ExportsFile)&quot;" Condition="'$(_IsApplePlatform)' == 'true' and '$(ExportsFile)' != ''" />
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MainMethodRootProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MainMethodRootProvider.cs
index 75c6de55579702..8152a0f6eae661 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MainMethodRootProvider.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MainMethodRootProvider.cs
@@ -21,13 +21,15 @@ public class MainMethodRootProvider : ICompilationRootProvider
         /// </summary>
         public const string ManagedEntryPointMethodName = "__managed__Main";
 
-        private EcmaModule _module;
-        private IReadOnlyCollection<MethodDesc> _libraryInitializers;
-        private bool _generateLibraryAndModuleInitializers;
+        private readonly EcmaModule _module;
+        private readonly string _entryPointName;
+        private readonly IReadOnlyCollection<MethodDesc> _libraryInitializers;
+        private readonly bool _generateLibraryAndModuleInitializers;
 
-        public MainMethodRootProvider(EcmaModule module, IReadOnlyCollection<MethodDesc> libraryInitializers, bool generateLibraryAndModuleInitializers)
+        public MainMethodRootProvider(EcmaModule module, IReadOnlyCollection<MethodDesc> libraryInitializers, bool generateLibraryAndModuleInitializers, string entryPointName = null)
         {
             _module = module;
+            _entryPointName = entryPointName ?? ManagedEntryPointMethodName;
             _libraryInitializers = libraryInitializers;
             _generateLibraryAndModuleInitializers = generateLibraryAndModuleInitializers;
         }
@@ -41,7 +43,7 @@ public void AddCompilationRoots(IRootingServiceProvider rootProvider)
             TypeDesc owningType = _module.GetGlobalModuleType();
             var startupCodeMain = new StartupCodeMainMethod(owningType, mainMethod, _libraryInitializers, _generateLibraryAndModuleInitializers);
 
-            rootProvider.AddCompilationRoot(startupCodeMain, "Startup Code Main Method", new Utf8String(ManagedEntryPointMethodName));
+            rootProvider.AddCompilationRoot(startupCodeMain, $"Startup Code Main Method for {_module.Assembly.GetName().Name}", new Utf8String(_entryPointName));
         }
     }
 }
diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.Sorting.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.Sorting.cs
index 59d582451c80ae..0cf90ba02ec626 100644
--- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.Sorting.cs
+++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/Stubs/StartupCode/StartupCodeMainMethod.Sorting.cs
@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 
 using Internal.TypeSystem;
-using Debug = System.Diagnostics.Debug;
 
 namespace Internal.IL.Stubs.StartupCode
 {
@@ -12,9 +11,7 @@ public partial class StartupCodeMainMethod
 
         protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
         {
-            // Should be a singleton
-            Debug.Assert(this == other);
-            return 0;
+            return comparer.Compare(OwningType, other.OwningType);
         }
 
         private partial class MainMethodWrapper
@@ -23,9 +20,7 @@ private partial class MainMethodWrapper
 
             protected override int CompareToImpl(MethodDesc other, TypeSystemComparer comparer)
             {
-                // Should be a singleton
-                Debug.Assert(this == other);
-                return 0;
+                return comparer.Compare(OwningType, other.OwningType);
             }
         }
     }
diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
index 91547f5749adc0..40632fb3bf5613 100644
--- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
+++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
@@ -44,6 +44,8 @@ internal sealed class ILCompilerRootCommand : RootCommand
             new("--nativelib") { Description = "Compile as static or shared library" };
         public Option<bool> SplitExeInitialization { get; } =
             new("--splitinit") { Description = "Split initialization of an executable between the library entrypoint and a main entrypoint" };
+        public Option<string[]> FatExeLibrary { get; } =
+            new("--fatexe") { Description = "Specify fat executable library entrypoint modules (format: 'assemblyName=MainEntryPointName')" };
         public Option<string> ExportsFile { get; } =
             new("--exportsfile") { Description = "File to write exported symbol and method definitions" };
         public Option<bool> ExportUnmanagedEntryPoints { get; } =
@@ -204,6 +206,7 @@ public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler")
             Options.Add(UseDwarf5);
             Options.Add(NativeLib);
             Options.Add(SplitExeInitialization);
+            Options.Add(FatExeLibrary);
             Options.Add(ExportsFile);
             Options.Add(ExportDynamicSymbols);
             Options.Add(ExportUnmanagedEntryPoints);
diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs
index b0f39723c9ce70..bf61d252fce37f 100644
--- a/src/coreclr/tools/aot/ILCompiler/Program.cs
+++ b/src/coreclr/tools/aot/ILCompiler/Program.cs
@@ -239,9 +239,23 @@ public int Run()
                     compilationRoots.Add(new RuntimeConfigurationRootProvider(settingsBlobName, runtimeOptions));
                     compilationRoots.Add(new RuntimeConfigurationRootProvider(knobsBlobName, runtimeKnobs));
                     compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
-                    if (SplitExeInitialization)
+
+                    string[] fatExeModules = Get(_command.FatExeLibrary);
+                    if (fatExeModules.Length > 0)
+                    {
+                        foreach (string specifier in fatExeModules)
+                        {
+                            string[] asmAndEntrypointName = specifier.Split('=');
+                            if (asmAndEntrypointName.Length != 2)
+                                throw new CommandLineException($"Format '{specifier}' not recognized for --fatexe. Expected 'assemblyName=MainEntryPointName'.");
+
+                            EcmaModule module = typeSystemContext.GetModuleForSimpleName(asmAndEntrypointName[0]);
+                            compilationRoots.Add(new MainMethodRootProvider(module, null, generateLibraryAndModuleInitializers: false, asmAndEntrypointName[1]));
+                        }
+                    }
+                    else if (SplitExeInitialization)
                     {
-                        compilationRoots.Add(new MainMethodRootProvider(entrypointModule, CreateInitializerList(typeSystemContext), generateLibraryAndModuleInitializers: false));
+                        compilationRoots.Add(new MainMethodRootProvider(entrypointModule, null, generateLibraryAndModuleInitializers: false));
                     }
                 }
                 else if (entrypointModule != null)
diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets
index bd32e565d6baad..782301f35eff8c 100644
--- a/src/tests/Directory.Build.targets
+++ b/src/tests/Directory.Build.targets
@@ -593,6 +593,6 @@
 
   <Target Name="LinkNativeIfBuildAndRun"
           Condition="'$(_WillCLRTestProjectBuild)' == 'true' and '$(CLRTestKind)' == 'BuildAndRun'"
-          DependsOnTargets="ComputeResolvedFilesToPublishList;LinkNative" />
+          DependsOnTargets="ComputeResolvedFilesToPublishList;NativeCompile" />
 
 </Project>
diff --git a/src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj b/src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj
new file mode 100644
index 00000000000000..6f4e34bb0a3176
--- /dev/null
+++ b/src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj
@@ -0,0 +1,41 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Library</OutputType>
+    <CLRTestKind>BuildAndRun</CLRTestKind>
+    <CLRTestPriority>0</CLRTestPriority>
+    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
+    <BuildAsStandalone>false</BuildAsStandalone>
+    <!-- Unable to compile a project with the Library output type for apple mobile devices -->
+    <CLRTestTargetUnsupported Condition="'$(TargetsAppleMobile)' == 'true'">true</CLRTestTargetUnsupported>
+    <!-- Unable to build a library project with native dependencies for android mobile devices:
+         https://github.com/dotnet/runtime/issues/121210 -->
+    <CLRTestTargetUnsupported Condition="'$(TargetsAndroid)' == 'true'">true</CLRTestTargetUnsupported>
+    <RequiresProcessIsolation>true</RequiresProcessIsolation>
+    <CLRTestIsHosted>false</CLRTestIsHosted>
+    <CLRTestRunFile Condition="'$(TargetsWindows)' == 'true'">native\FatLibrary.exe</CLRTestRunFile>
+    <CLRTestRunFile Condition="'$(TargetsWindows)' != 'true'">./native/FatLibrary</CLRTestRunFile>
+    <SkipInferOutputType>true</SkipInferOutputType>
+    <FatExecutable>true</FatExecutable>
+    <!-- warning CS2008: No source files specified -->
+    <NoWarn>$(NoWarn);CS2008</NoWarn>
+  </PropertyGroup>
+
+  <PropertyGroup>
+    <CLRTestBatchPreCommands><![CDATA[
+$(CLRTestBatchPreCommands)
+copy /y native\ValidatorExe.exe native\FatLibrary.exe
+set ExePath=
+]]></CLRTestBatchPreCommands>
+
+    <CLRTestBashPreCommands><![CDATA[
+$(CLRTestBashPreCommands)
+cp native/ValidatorExe native/FatLibrary
+ExePath=
+]]></CLRTestBashPreCommands>
+  </PropertyGroup>
+
+  <ItemGroup>
+    <ProjectReference Include="HelloExe\HelloExe.csproj" IncludeInFatExe="true" />
+    <ProjectReference Include="ValidatorExe\ValidatorExe.csproj" IncludeInFatExe="true" />
+  </ItemGroup>
+</Project>
diff --git a/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.cs b/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.cs
new file mode 100644
index 00000000000000..9f476b06021221
--- /dev/null
+++ b/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.cs
@@ -0,0 +1,6 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+
+Console.WriteLine("Hello from HelloExe");
diff --git a/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.csproj b/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.csproj
new file mode 100644
index 00000000000000..f1bb752fd9c004
--- /dev/null
+++ b/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.csproj
@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <CLRTestKind>SharedLibrary</CLRTestKind>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="HelloExe.cs" />
+  </ItemGroup>
+</Project>
diff --git a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
new file mode 100644
index 00000000000000..847b25319ccfc1
--- /dev/null
+++ b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
@@ -0,0 +1,31 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Diagnostics;
+using System.IO;
+
+string executableExtension = OperatingSystem.IsWindows() ? ".exe" : "";
+string helloExePath = Path.Combine(AppContext.BaseDirectory, $"HelloExe{executableExtension}");
+
+using Process? helloExe = Process.Start(new ProcessStartInfo(helloExePath)
+{
+    RedirectStandardOutput = true,
+    UseShellExecute = false,
+});
+
+if (helloExe is null)
+{
+    Console.Error.WriteLine($"Failed to start {helloExePath}");
+    return 1;
+}
+
+helloExe.WaitForExit();
+string output = helloExe.StandardOutput.ReadToEnd().Trim();
+if (helloExe.ExitCode != 0 || output != "Hello from HelloExe")
+{
+    Console.Error.WriteLine($"Unexpected HelloExe result. Exit code: {helloExe.ExitCode}; output: '{output}'");
+    return 1;
+}
+
+return 100;
diff --git a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.csproj b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.csproj
new file mode 100644
index 00000000000000..bfc1086b4fb732
--- /dev/null
+++ b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.csproj
@@ -0,0 +1,9 @@
+<Project Sdk="Microsoft.NET.Sdk">
+  <PropertyGroup>
+    <OutputType>Exe</OutputType>
+    <CLRTestKind>SharedLibrary</CLRTestKind>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="ValidatorExe.cs" />
+  </ItemGroup>
+</Project>

From f74b0d38f6eafe98978a5378b171c292c814b6cf Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 25 May 2026 09:50:26 +0000
Subject: [PATCH 02/27] Address NativeAOT fat executable review feedback

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/69bd1576-bcad-4ee1-aa5e-af9513609eea

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets    | 4 +++-
 src/coreclr/tools/aot/ILCompiler/Program.cs                   | 2 +-
 .../FatExecutableLibrary/ValidatorExe/ValidatorExe.cs         | 4 +++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 906d2d02d349ae..05a7b273f14538 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -17,6 +17,7 @@ The .NET Foundation licenses this file to you under the MIT license.
     <CppCompilerAndLinkerAlternative />
     <CppCompilerAndLinkerAlternative Condition="'$(CppCompilerAndLinker)' == '' and '$(_IsApplePlatform)' != 'true'">gcc</CppCompilerAndLinkerAlternative>
     <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
+    <CppCompiler Condition="'$(CppCompiler)' == ''">$(CppCompilerAndLinker)</CppCompiler>
     <CppLinker>$(CppCompilerAndLinker)</CppLinker>
     <CppLibCreator>ar</CppLibCreator>
     <_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
@@ -313,6 +314,7 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <PropertyGroup Condition="'$(CppCompilerAndLinkerAlternative)' != '' and '$(_WhereLinker)' != '0' and '$(_WhereLinkerAlt)' == '0' and '$(NativeLib)' != 'Static'">
       <CppCompilerAndLinker>$(CppCompilerAndLinkerAlternative)</CppCompilerAndLinker>
+      <CppCompiler>$(CppCompilerAndLinker)</CppCompiler>
       <CppLinker>$(CppCompilerAndLinker)</CppLinker>
       <_WhereLinker>0</_WhereLinker>
     </PropertyGroup>
@@ -384,7 +386,7 @@ The .NET Foundation licenses this file to you under the MIT license.
           Outputs="@(_FatExecutableShim);@(_FatExecutableShimSymbol)">
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
-    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimCompileRspFile)&quot;" />
+    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_FatExecutableReferencePath.ShimCompileRspFile)&quot;" />
     <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimLinkRspFile)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
           Command="&quot;$(ObjCopyName)&quot; --only-keep-debug &quot;%(_FatExecutableReferencePath.ShimBinary)&quot; &quot;%(_FatExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot;" />
diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs
index bf61d252fce37f..814ef21be6889e 100644
--- a/src/coreclr/tools/aot/ILCompiler/Program.cs
+++ b/src/coreclr/tools/aot/ILCompiler/Program.cs
@@ -255,7 +255,7 @@ public int Run()
                     }
                     else if (SplitExeInitialization)
                     {
-                        compilationRoots.Add(new MainMethodRootProvider(entrypointModule, null, generateLibraryAndModuleInitializers: false));
+                        compilationRoots.Add(new MainMethodRootProvider(entrypointModule, CreateInitializerList(typeSystemContext), generateLibraryAndModuleInitializers: false));
                     }
                 }
                 else if (entrypointModule != null)
diff --git a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
index 847b25319ccfc1..46fc3644191419 100644
--- a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
+++ b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
@@ -10,6 +10,7 @@
 
 using Process? helloExe = Process.Start(new ProcessStartInfo(helloExePath)
 {
+    RedirectStandardError = true,
     RedirectStandardOutput = true,
     UseShellExecute = false,
 });
@@ -22,9 +23,10 @@
 
 helloExe.WaitForExit();
 string output = helloExe.StandardOutput.ReadToEnd().Trim();
+string error = helloExe.StandardError.ReadToEnd().Trim();
 if (helloExe.ExitCode != 0 || output != "Hello from HelloExe")
 {
-    Console.Error.WriteLine($"Unexpected HelloExe result. Exit code: {helloExe.ExitCode}; output: '{output}'");
+    Console.Error.WriteLine($"Unexpected HelloExe result. Exit code: {helloExe.ExitCode}; output: '{output}'; error: '{error}'");
     return 1;
 }
 

From 941a5a4eefebfc3226a198e3c40e81dac85dacd0 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 25 May 2026 09:52:54 +0000
Subject: [PATCH 03/27] Improve fat executable argument validation

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/69bd1576-bcad-4ee1-aa5e-af9513609eea

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 src/coreclr/tools/aot/ILCompiler/Program.cs | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs
index 814ef21be6889e..f62a6f5180fc44 100644
--- a/src/coreclr/tools/aot/ILCompiler/Program.cs
+++ b/src/coreclr/tools/aot/ILCompiler/Program.cs
@@ -245,12 +245,12 @@ public int Run()
                     {
                         foreach (string specifier in fatExeModules)
                         {
-                            string[] asmAndEntrypointName = specifier.Split('=');
-                            if (asmAndEntrypointName.Length != 2)
-                                throw new CommandLineException($"Format '{specifier}' not recognized for --fatexe. Expected 'assemblyName=MainEntryPointName'.");
+                            int separatorIndex = specifier.IndexOf('=');
+                            if (separatorIndex <= 0 || separatorIndex != specifier.LastIndexOf('=') || separatorIndex == specifier.Length - 1)
+                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Expected exactly one '=' separating assemblyName from MainEntryPointName.");
 
-                            EcmaModule module = typeSystemContext.GetModuleForSimpleName(asmAndEntrypointName[0]);
-                            compilationRoots.Add(new MainMethodRootProvider(module, null, generateLibraryAndModuleInitializers: false, asmAndEntrypointName[1]));
+                            EcmaModule module = typeSystemContext.GetModuleForSimpleName(specifier.Substring(0, separatorIndex));
+                            compilationRoots.Add(new MainMethodRootProvider(module, null, generateLibraryAndModuleInitializers: false, specifier.Substring(separatorIndex + 1)));
                         }
                     }
                     else if (SplitExeInitialization)

From 9272118ca672c6fe86edf687302cf94e174a7f45 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 25 May 2026 09:55:41 +0000
Subject: [PATCH 04/27] Refine NativeAOT Unix shim generation

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/69bd1576-bcad-4ee1-aa5e-af9513609eea

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets | 4 ++--
 .../BuildIntegration/Microsoft.NETCore.Native.targets      | 2 +-
 src/coreclr/tools/aot/ILCompiler/Program.cs                | 7 +++++--
 3 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 05a7b273f14538..65c27547adf587 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -429,12 +429,12 @@ int main(int argc, char** argv)
       <_FatExecutableShimLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
       <_FatExecutableShimLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
       <_FatExecutableShimLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-rpath,$ORIGIN" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_FatExecutableShimLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
       <_FatExecutableShimLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_FatExecutableShimLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_FatExecutableShimLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" />
+      <_FatExecutableShimLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
     </ItemGroup>
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index 7321a5a727d3ee..de2f0313c8187f 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -183,7 +183,7 @@ The .NET Foundation licenses this file to you under the MIT license.
       <_FatExecutableReferencePath Include="@(ReferencePath)"
                                    Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IncludeInFatExe)' == 'true'">
         <AssemblyName>%(ReferencePath.Filename)</AssemblyName>
-        <SanitizedAssemblyName>$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
+        <SanitizedAssemblyName>_$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
         <AssemblyNameHash>$([MSBuild]::StableStringHash('%(ReferencePath.Filename)', 'Sha256'))</AssemblyNameHash>
         <TargetName>%(ReferencePath.Filename)</TargetName>
       </_FatExecutableReferencePath>
diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs
index f62a6f5180fc44..f3b73bd0dc5551 100644
--- a/src/coreclr/tools/aot/ILCompiler/Program.cs
+++ b/src/coreclr/tools/aot/ILCompiler/Program.cs
@@ -246,8 +246,11 @@ public int Run()
                         foreach (string specifier in fatExeModules)
                         {
                             int separatorIndex = specifier.IndexOf('=');
-                            if (separatorIndex <= 0 || separatorIndex != specifier.LastIndexOf('=') || separatorIndex == specifier.Length - 1)
-                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Expected exactly one '=' separating assemblyName from MainEntryPointName.");
+                            if (separatorIndex < 0)
+                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Missing '=' separator between assemblyName and MainEntryPointName.");
+
+                            if (separatorIndex == 0 || separatorIndex != specifier.LastIndexOf('=') || separatorIndex == specifier.Length - 1)
+                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Expected exactly one '=' with non-empty assemblyName and MainEntryPointName.");
 
                             EcmaModule module = typeSystemContext.GetModuleForSimpleName(specifier.Substring(0, separatorIndex));
                             compilationRoots.Add(new MainMethodRootProvider(module, null, generateLibraryAndModuleInitializers: false, specifier.Substring(separatorIndex + 1)));

From 144939ca7cd7d1b913c49b4be0f955e3eab6c943 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 25 May 2026 09:57:22 +0000
Subject: [PATCH 05/27] Avoid fat executable validator pipe deadlock

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/69bd1576-bcad-4ee1-aa5e-af9513609eea

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../FatExecutableLibrary/ValidatorExe/ValidatorExe.cs      | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
index 46fc3644191419..465c66a304455e 100644
--- a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
+++ b/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
@@ -4,6 +4,7 @@
 using System;
 using System.Diagnostics;
 using System.IO;
+using System.Threading.Tasks;
 
 string executableExtension = OperatingSystem.IsWindows() ? ".exe" : "";
 string helloExePath = Path.Combine(AppContext.BaseDirectory, $"HelloExe{executableExtension}");
@@ -21,9 +22,11 @@
     return 1;
 }
 
+Task<string> outputTask = helloExe.StandardOutput.ReadToEndAsync();
+Task<string> errorTask = helloExe.StandardError.ReadToEndAsync();
 helloExe.WaitForExit();
-string output = helloExe.StandardOutput.ReadToEnd().Trim();
-string error = helloExe.StandardError.ReadToEnd().Trim();
+string output = (await outputTask).Trim();
+string error = (await errorTask).Trim();
 if (helloExe.ExitCode != 0 || output != "Hello from HelloExe")
 {
     Console.Error.WriteLine($"Unexpected HelloExe result. Exit code: {helloExe.ExitCode}; output: '{output}'; error: '{error}'");

From 263a1ad9444a361e26113262748421a6b798fca4 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 25 May 2026 09:59:57 +0000
Subject: [PATCH 06/27] Clarify fat executable symbol and option handling

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/69bd1576-bcad-4ee1-aa5e-af9513609eea

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.targets         | 2 +-
 src/coreclr/tools/aot/ILCompiler/Program.cs                   | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index de2f0313c8187f..d578b4d49e884c 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -183,7 +183,7 @@ The .NET Foundation licenses this file to you under the MIT license.
       <_FatExecutableReferencePath Include="@(ReferencePath)"
                                    Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IncludeInFatExe)' == 'true'">
         <AssemblyName>%(ReferencePath.Filename)</AssemblyName>
-        <SanitizedAssemblyName>_$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
+        <SanitizedAssemblyName>__FatExeShim_$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
         <AssemblyNameHash>$([MSBuild]::StableStringHash('%(ReferencePath.Filename)', 'Sha256'))</AssemblyNameHash>
         <TargetName>%(ReferencePath.Filename)</TargetName>
       </_FatExecutableReferencePath>
diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs
index f3b73bd0dc5551..207b26e92999ec 100644
--- a/src/coreclr/tools/aot/ILCompiler/Program.cs
+++ b/src/coreclr/tools/aot/ILCompiler/Program.cs
@@ -247,10 +247,10 @@ public int Run()
                         {
                             int separatorIndex = specifier.IndexOf('=');
                             if (separatorIndex < 0)
-                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Missing '=' separator between assemblyName and MainEntryPointName.");
+                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Missing '=' separator between assemblyName and MainEntryPointName. Expected format: assemblyName=MainEntryPointName.");
 
                             if (separatorIndex == 0 || separatorIndex != specifier.LastIndexOf('=') || separatorIndex == specifier.Length - 1)
-                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Expected exactly one '=' with non-empty assemblyName and MainEntryPointName.");
+                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Expected format: assemblyName=MainEntryPointName with non-empty assemblyName and MainEntryPointName.");
 
                             EcmaModule module = typeSystemContext.GetModuleForSimpleName(specifier.Substring(0, separatorIndex));
                             compilationRoots.Add(new MainMethodRootProvider(module, null, generateLibraryAndModuleInitializers: false, specifier.Substring(separatorIndex + 1)));

From 9b097fb2c7fbe910606c1337ecaeda2df3c32094 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 26 May 2026 05:57:55 +0000
Subject: [PATCH 07/27] Apply aggregate executable review updates

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f0f54e39-2f6a-48af-88ed-f5724228b103

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Publish.targets  | 24 +++---
 .../Microsoft.NETCore.Native.Unix.targets     | 67 +++++++---------
 .../Microsoft.NETCore.Native.Windows.targets  | 76 +++++++++----------
 .../Microsoft.NETCore.Native.targets          | 59 +++++++-------
 .../aot/ILCompiler/ILCompilerRootCommand.cs   |  6 +-
 src/coreclr/tools/aot/ILCompiler/Program.cs   | 10 +--
 .../AggregateLibrary.csproj}                  | 29 +++----
 .../HelloExe/HelloExe.cs                      |  0
 .../HelloExe/HelloExe.csproj                  |  0
 .../ValidatorExe/ValidatorExe.cs              |  0
 .../ValidatorExe/ValidatorExe.csproj          |  0
 11 files changed, 127 insertions(+), 144 deletions(-)
 rename src/tests/nativeaot/{FatExecutableLibrary/FatLibrary.csproj => AggregateExecutableLibrary/AggregateLibrary.csproj} (72%)
 rename src/tests/nativeaot/{FatExecutableLibrary => AggregateExecutableLibrary}/HelloExe/HelloExe.cs (100%)
 rename src/tests/nativeaot/{FatExecutableLibrary => AggregateExecutableLibrary}/HelloExe/HelloExe.csproj (100%)
 rename src/tests/nativeaot/{FatExecutableLibrary => AggregateExecutableLibrary}/ValidatorExe/ValidatorExe.cs (100%)
 rename src/tests/nativeaot/{FatExecutableLibrary => AggregateExecutableLibrary}/ValidatorExe/ValidatorExe.csproj (100%)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
index 5af6b4adc3af26..3062addaf33733 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
@@ -41,22 +41,22 @@
         <RelativePath>$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
-      <ResolvedFileToPublish Include="@(_FatExecutableShim)" Condition="'$(FatExecutable)' == 'true'">
-        <RelativePath>%(_FatExecutableShim.RelativePath)</RelativePath>
+      <ResolvedFileToPublish Include="@(_AggregateExecutableShim)" Condition="'$(AggregateExecutable)' == 'true'">
+        <RelativePath>%(_AggregateExecutableShim.RelativePath)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
-      <ResolvedFileToPublish Include="@(_FatExecutableShimSymbol)"
-                             Condition="'$(FatExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' != '.dSYM' and Exists('%(_FatExecutableShimSymbol.Identity)')">
-        <RelativePath>%(_FatExecutableShimSymbol.RelativePath)</RelativePath>
+      <ResolvedFileToPublish Include="@(_AggregateExecutableShimSymbol)"
+                             Condition="'$(AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' != '.dSYM' and Exists('%(_AggregateExecutableShimSymbol.Identity)')">
+        <RelativePath>%(_AggregateExecutableShimSymbol.RelativePath)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
-      <_FatExecutableShimSymbolRecursivePath Include="%(_FatExecutableReferencePath.ShimSymbol)/**/*"
-                                             Condition="'$(FatExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' == '.dSYM' and Exists('%(_FatExecutableReferencePath.ShimSymbol)')">
-        <RelativePath>%(_FatExecutableReferencePath.TargetName)$(NativeSymbolExt)/%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
-      </_FatExecutableShimSymbolRecursivePath>
-      <ResolvedFileToPublish Include="@(_FatExecutableShimSymbolRecursivePath)"
-                             Condition="'$(FatExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
-        <RelativePath>%(_FatExecutableShimSymbolRecursivePath.RelativePath)</RelativePath>
+      <_AggregateExecutableShimSymbolRecursivePath Include="%(_AggregateExecutableReferencePath.ShimSymbol)/**/*"
+                                             Condition="'$(AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' == '.dSYM' and Exists('%(_AggregateExecutableReferencePath.ShimSymbol)')">
+        <RelativePath>%(_AggregateExecutableReferencePath.TargetName)$(NativeSymbolExt)/%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
+      </_AggregateExecutableShimSymbolRecursivePath>
+      <ResolvedFileToPublish Include="@(_AggregateExecutableShimSymbolRecursivePath)"
+                             Condition="'$(AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
+        <RelativePath>%(_AggregateExecutableShimSymbolRecursivePath.RelativePath)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
     </ItemGroup>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 65c27547adf587..13c4b0e6c0910e 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -380,66 +380,57 @@ The .NET Foundation licenses this file to you under the MIT license.
   </Target>
 
   <Target Name="CreateShimExes"
-          Condition="'$(FatExecutable)' == 'true'"
-          DependsOnTargets="LinkNative;WriteFatExecutableShimRspFiles"
-          Inputs="$(NativeBinary);@(_FatExecutableReferencePath->'%(ShimSource)');@(_FatExecutableReferencePath->'%(ShimCompileRspFile)');@(_FatExecutableReferencePath->'%(ShimLinkRspFile)')"
-          Outputs="@(_FatExecutableShim);@(_FatExecutableShimSymbol)">
+          Condition="'$(AggregateExecutable)' == 'true'"
+          DependsOnTargets="LinkNative;WriteAggregateExecutableShimRspFiles"
+          Inputs="$(NativeBinary);@(_AggregateExecutableReferencePath->'%(ShimSource)');@(_AggregateExecutableReferencePath->'%(ShimLinkRspFile)')"
+          Outputs="@(_AggregateExecutableShim);@(_AggregateExecutableShimSymbol)">
 
-    <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
-    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_FatExecutableReferencePath.ShimCompileRspFile)&quot;" />
-    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimLinkRspFile)&quot;" />
+    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimLinkRspFile)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
-          Command="&quot;$(ObjCopyName)&quot; --only-keep-debug &quot;%(_FatExecutableReferencePath.ShimBinary)&quot; &quot;%(_FatExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot;" />
+          Command="&quot;$(ObjCopyName)&quot; --only-keep-debug &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot; &quot;%(_AggregateExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
-          Command="&quot;$(ObjCopyName)&quot; --strip-debug --strip-unneeded &quot;%(_FatExecutableReferencePath.ShimBinary)&quot;" />
+          Command="&quot;$(ObjCopyName)&quot; --strip-debug --strip-unneeded &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
-          Command="&quot;$(ObjCopyName)&quot; --add-gnu-debuglink=&quot;%(_FatExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot; &quot;%(_FatExecutableReferencePath.ShimBinary)&quot;" />
+          Command="&quot;$(ObjCopyName)&quot; --add-gnu-debuglink=&quot;%(_AggregateExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot; &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' == 'true'"
           IgnoreStandardErrorWarningFormat="true"
           Command="
-            dsymutil $(DsymUtilOptions) &quot;%(_FatExecutableReferencePath.ShimBinary)&quot; &amp;&amp;
-            strip -no_code_signature_warning -x &quot;%(_FatExecutableReferencePath.ShimBinary)&quot;" />
+            dsymutil $(DsymUtilOptions) &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot; &amp;&amp;
+            strip -no_code_signature_warning -x &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;" />
   </Target>
 
-  <Target Name="WriteFatExecutableShimRspFiles"
-          Condition="'$(FatExecutable)' == 'true'"
+  <Target Name="WriteAggregateExecutableShimRspFiles"
+          Condition="'$(AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative">
 
     <ItemGroup>
-      <_FatExecutableReferencePath>
-        <ShimSourceCode><![CDATA[extern int %(_FatExecutableReferencePath.EntryPointSymbol)(int, char**);
+      <_AggregateExecutableReferencePath>
+        <ShimSourceCode><![CDATA[extern int %(_AggregateExecutableReferencePath.EntryPointSymbol)(int, char**);
 
 int main(int argc, char** argv)
 {
-    return %(_FatExecutableReferencePath.EntryPointSymbol)(argc, argv);
+    return %(_AggregateExecutableReferencePath.EntryPointSymbol)(argc, argv);
 }
 ]]></ShimSourceCode>
-      </_FatExecutableReferencePath>
+      </_AggregateExecutableReferencePath>
     </ItemGroup>
 
     <ItemGroup>
-      <_FatExecutableShimCompilerArg Include="-c" />
-      <_FatExecutableShimCompilerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
-      <_FatExecutableShimCompilerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
-      <_FatExecutableShimCompilerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimCompilerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
-
-      <_FatExecutableShimLinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
-      <_FatExecutableShimLinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
-      <_FatExecutableShimLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
-      <_FatExecutableShimLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_FatExecutableShimLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
+      <_AggregateExecutableShimLinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
+      <_AggregateExecutableShimLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
     </ItemGroup>
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
-    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_FatExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimCompileRspFile)" Lines="@(_FatExecutableShimCompilerArg);&quot;%(_FatExecutableReferencePath.ShimSource)&quot;;-o;&quot;%(_FatExecutableReferencePath.ShimObject)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_FatExecutableReferencePath.ShimObject)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_FatExecutableReferencePath.ShimBinary)&quot;;@(_FatExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_AggregateExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;;@(_AggregateExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
   </Target>
 </Project>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index bc80e765958137..c95c70b709f75d 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -146,61 +146,61 @@ The .NET Foundation licenses this file to you under the MIT license.
   </Target>
 
   <Target Name="CreateShimExes"
-          Condition="'$(FatExecutable)' == 'true'"
-          DependsOnTargets="LinkNative;WriteFatExecutableShimRspFiles"
-          Inputs="$(NativeImportLibrary);@(_FatExecutableReferencePath->'%(ShimSource)');@(_FatExecutableReferencePath->'%(ShimCompileRspFile)');@(_FatExecutableReferencePath->'%(ShimLinkRspFile)')"
-          Outputs="@(_FatExecutableShim);@(_FatExecutableShimSymbol)">
+          Condition="'$(AggregateExecutable)' == 'true'"
+          DependsOnTargets="LinkNative;WriteAggregateExecutableShimRspFiles"
+          Inputs="$(NativeImportLibrary);@(_AggregateExecutableReferencePath->'%(ShimSource)');@(_AggregateExecutableReferencePath->'%(ShimCompileRspFile)');@(_AggregateExecutableReferencePath->'%(ShimLinkRspFile)')"
+          Outputs="@(_AggregateExecutableShim);@(_AggregateExecutableShimSymbol)">
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
-    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_FatExecutableReferencePath.ShimCompileRspFile)&quot;" />
-    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_FatExecutableReferencePath.ShimLinkRspFile)&quot;" />
+    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimCompileRspFile)&quot;" />
+    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimLinkRspFile)&quot;" />
   </Target>
 
-  <Target Name="WriteFatExecutableShimRspFiles"
-          Condition="'$(FatExecutable)' == 'true'"
+  <Target Name="WriteAggregateExecutableShimRspFiles"
+          Condition="'$(AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative">
 
     <ItemGroup>
-      <_FatExecutableReferencePath>
-        <ShimSourceCode><![CDATA[__declspec(dllimport) int %(_FatExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
+      <_AggregateExecutableReferencePath>
+        <ShimSourceCode><![CDATA[__declspec(dllimport) int %(_AggregateExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
 
 int wmain(int argc, unsigned short** argv)
 {
-    return %(_FatExecutableReferencePath.EntryPointSymbol)(argc, argv);
+    return %(_AggregateExecutableReferencePath.EntryPointSymbol)(argc, argv);
 }
 ]]></ShimSourceCode>
-        <ShimPdbLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'">/PDB:"%(_FatExecutableReferencePath.ShimSymbol)"</ShimPdbLinkerArg>
-      </_FatExecutableReferencePath>
+        <ShimPdbLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'">/PDB:"%(_AggregateExecutableReferencePath.ShimSymbol)"</ShimPdbLinkerArg>
+      </_AggregateExecutableReferencePath>
     </ItemGroup>
 
     <ItemGroup>
-      <_FatExecutableShimCompilerArg Include="/nologo" />
-      <_FatExecutableShimCompilerArg Include="/c" />
-      <_FatExecutableShimCompilerArg Include="/MT" />
-      <_FatExecutableShimCompilerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/Z7" />
-      <_FatExecutableShimCompilerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
-
-      <_FatExecutableShimLinkerArg Include="/NOLOGO" />
-      <_FatExecutableShimLinkerArg Include="/MANIFEST:NO" />
-      <_FatExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
-      <_FatExecutableShimLinkerArg Include="/STACK:$(IlcDefaultStackSize)" />
-      <_FatExecutableShimLinkerArg Include="/INCREMENTAL:NO" />
-      <_FatExecutableShimLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/DEBUG" />
-      <_FatExecutableShimLinkerArg Include="/NODEFAULTLIB:libucrt.lib" />
-      <_FatExecutableShimLinkerArg Include="/DEFAULTLIB:ucrt.lib" />
-      <_FatExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:REF" />
-      <_FatExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:ICF" />
-      <_FatExecutableShimLinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
-      <_FatExecutableShimLinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh" />
-      <_FatExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT" />
-      <_FatExecutableShimLinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO" />
-      <_FatExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont" />
-      <_FatExecutableShimLinkerArg Include="@(AdditionalNativeLibraryDirectories->'/LIBPATH:&quot;%(Identity)&quot;')" />
+      <_AggregateExecutableShimCompilerArg Include="/nologo" />
+      <_AggregateExecutableShimCompilerArg Include="/c" />
+      <_AggregateExecutableShimCompilerArg Include="/MT" />
+      <_AggregateExecutableShimCompilerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/Z7" />
+      <_AggregateExecutableShimCompilerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
+
+      <_AggregateExecutableShimLinkerArg Include="/NOLOGO" />
+      <_AggregateExecutableShimLinkerArg Include="/MANIFEST:NO" />
+      <_AggregateExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
+      <_AggregateExecutableShimLinkerArg Include="/STACK:$(IlcDefaultStackSize)" />
+      <_AggregateExecutableShimLinkerArg Include="/INCREMENTAL:NO" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/DEBUG" />
+      <_AggregateExecutableShimLinkerArg Include="/NODEFAULTLIB:libucrt.lib" />
+      <_AggregateExecutableShimLinkerArg Include="/DEFAULTLIB:ucrt.lib" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:REF" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:ICF" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO" />
+      <_AggregateExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont" />
+      <_AggregateExecutableShimLinkerArg Include="@(AdditionalNativeLibraryDirectories->'/LIBPATH:&quot;%(Identity)&quot;')" />
     </ItemGroup>
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
-    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_FatExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimCompileRspFile)" Lines="@(_FatExecutableShimCompilerArg);&quot;%(_FatExecutableReferencePath.ShimSource)&quot;;/Fo&quot;%(_FatExecutableReferencePath.ShimObject)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_FatExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_FatExecutableReferencePath.ShimObject)&quot;;&quot;$(NativeImportLibrary)&quot;;/OUT:&quot;%(_FatExecutableReferencePath.ShimBinary)&quot;;/SUBSYSTEM:%(_FatExecutableReferencePath.ShimLinkerSubsystem);%(_FatExecutableReferencePath.ShimPdbLinkerArg);@(_FatExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_AggregateExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimCompileRspFile)" Lines="@(_AggregateExecutableShimCompilerArg);&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;/Fo&quot;%(_AggregateExecutableReferencePath.ShimObject)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_AggregateExecutableReferencePath.ShimObject)&quot;;&quot;$(NativeImportLibrary)&quot;;/OUT:&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;;/SUBSYSTEM:%(_AggregateExecutableReferencePath.ShimLinkerSubsystem);%(_AggregateExecutableReferencePath.ShimPdbLinkerArg);@(_AggregateExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
   </Target>
 </Project>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index d578b4d49e884c..195b2bde1beeeb 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -103,7 +103,7 @@ The .NET Foundation licenses this file to you under the MIT license.
   <PropertyGroup Condition="'$(IlcCompileDependsOn)'=='' and '$(NativeCompilationDuringPublish)' != 'false'">
     <IlcCompileDependsOn Condition="'$(BuildingFrameworkLibrary)' != 'true'">Compile;ComputeIlcCompileInputs</IlcCompileDependsOn>
     <IlcCompileDependsOn Condition="'$(IlcMultiModule)' == 'true' and '$(BuildingFrameworkLibrary)' != 'true'">$(IlcCompileDependsOn);BuildFrameworkLib</IlcCompileDependsOn>
-    <IlcCompileDependsOn Condition="'$(FatExecutable)' == 'true'">$(IlcCompileDependsOn);ComputeFatExecutableInputs</IlcCompileDependsOn>
+    <IlcCompileDependsOn>$(IlcCompileDependsOn);ComputeAggregateExecutableInputs</IlcCompileDependsOn>
     <IlcCompileDependsOn>$(IlcCompileDependsOn);SetupOSSpecificProps</IlcCompileDependsOn>
   </PropertyGroup>
 
@@ -172,42 +172,43 @@ The .NET Foundation licenses this file to you under the MIT license.
     </ItemGroup>
   </Target>
 
-  <Target Name="ComputeFatExecutableInputs"
-          Condition="'$(FatExecutable)' == 'true'"
+  <Target Name="ComputeAggregateExecutableInputs"
           DependsOnTargets="ResolveReferences">
 
-    <Error Condition="'$(OutputType)' != 'Library'" Text="FatExecutable requires OutputType=Library." />
-    <Error Condition="'$(NativeLib)' != 'Shared'" Text="FatExecutable requires NativeLib=Shared." />
-
     <ItemGroup>
-      <_FatExecutableReferencePath Include="@(ReferencePath)"
-                                   Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IncludeInFatExe)' == 'true'">
+      <_AggregateExecutableReferencePath Include="@(ReferencePath)"
+                                   Condition="'%(ReferencePath.ReferenceSourceTarget)' == 'ProjectReference' and '%(ReferencePath.IncludeInAggregateExecutable)' == 'true'">
         <AssemblyName>%(ReferencePath.Filename)</AssemblyName>
-        <SanitizedAssemblyName>__FatExeShim_$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
+        <SanitizedAssemblyName>__AggregateExeShim_$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
         <AssemblyNameHash>$([MSBuild]::StableStringHash('%(ReferencePath.Filename)', 'Sha256'))</AssemblyNameHash>
         <TargetName>%(ReferencePath.Filename)</TargetName>
-      </_FatExecutableReferencePath>
-      <_FatExecutableReferencePath>
-        <EntryPointSymbol>_FatExeMain_%(SanitizedAssemblyName)_%(AssemblyNameHash)</EntryPointSymbol>
-        <ShimLinkerSubsystem Condition="'%(_FatExecutableReferencePath.LinkerSubsystem)' != ''">%(_FatExecutableReferencePath.LinkerSubsystem)</ShimLinkerSubsystem>
-        <ShimLinkerSubsystem Condition="'%(_FatExecutableReferencePath.LinkerSubsystem)' == '' and '$(LinkerSubsystem)' != ''">$(LinkerSubsystem)</ShimLinkerSubsystem>
-        <ShimLinkerSubsystem Condition="'%(_FatExecutableReferencePath.LinkerSubsystem)' == '' and '$(LinkerSubsystem)' == ''">CONSOLE</ShimLinkerSubsystem>
-        <ShimSource>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe.c</ShimSource>
-        <ShimObject>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe$(NativeObjectExt)</ShimObject>
-        <ShimCompileRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe.cl.rsp</ShimCompileRspFile>
-        <ShimLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).fatexe.link.rsp</ShimLinkRspFile>
+      </_AggregateExecutableReferencePath>
+      <_AggregateExecutableReferencePath>
+        <EntryPointSymbol>_AggregateExeMain_%(SanitizedAssemblyName)_%(AssemblyNameHash)</EntryPointSymbol>
+        <ShimLinkerSubsystem Condition="'%(_AggregateExecutableReferencePath.LinkerSubsystem)' != ''">%(_AggregateExecutableReferencePath.LinkerSubsystem)</ShimLinkerSubsystem>
+        <ShimLinkerSubsystem Condition="'%(_AggregateExecutableReferencePath.LinkerSubsystem)' == '' and '$(LinkerSubsystem)' != ''">$(LinkerSubsystem)</ShimLinkerSubsystem>
+        <ShimLinkerSubsystem Condition="'%(_AggregateExecutableReferencePath.LinkerSubsystem)' == '' and '$(LinkerSubsystem)' == ''">CONSOLE</ShimLinkerSubsystem>
+        <ShimSource>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.c</ShimSource>
+        <ShimObject>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe$(NativeObjectExt)</ShimObject>
+        <ShimCompileRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.cl.rsp</ShimCompileRspFile>
+        <ShimLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.link.rsp</ShimLinkRspFile>
         <ShimBinary>$(NativeOutputPath)%(TargetName)$(NativeExecutableExt)</ShimBinary>
         <ShimSymbol>$(NativeOutputPath)%(TargetName)$(NativeSymbolExt)</ShimSymbol>
-      </_FatExecutableReferencePath>
-      <_FatExecutableShim Include="%(_FatExecutableReferencePath.ShimBinary)">
-        <RelativePath>%(_FatExecutableReferencePath.TargetName)$(NativeExecutableExt)</RelativePath>
-      </_FatExecutableShim>
-      <_FatExecutableShimSymbol Include="%(_FatExecutableReferencePath.ShimSymbol)" Condition="'$(NativeDebugSymbols)' == 'true'">
-        <RelativePath>%(_FatExecutableReferencePath.TargetName)$(NativeSymbolExt)</RelativePath>
-      </_FatExecutableShimSymbol>
+      </_AggregateExecutableReferencePath>
+      <_AggregateExecutableShim Include="%(_AggregateExecutableReferencePath.ShimBinary)">
+        <RelativePath>%(_AggregateExecutableReferencePath.TargetName)$(NativeExecutableExt)</RelativePath>
+      </_AggregateExecutableShim>
+      <_AggregateExecutableShimSymbol Include="%(_AggregateExecutableReferencePath.ShimSymbol)" Condition="'$(NativeDebugSymbols)' == 'true'">
+        <RelativePath>%(_AggregateExecutableReferencePath.TargetName)$(NativeSymbolExt)</RelativePath>
+      </_AggregateExecutableShimSymbol>
     </ItemGroup>
 
-    <Error Condition="'@(_FatExecutableReferencePath)' == ''" Text="FatExecutable requires at least one ProjectReference with IncludeInFatExe=true." />
+    <PropertyGroup>
+      <AggregateExecutable Condition="'$(NativeLib)' == 'Shared' and '@(_AggregateExecutableReferencePath)' != ''">true</AggregateExecutable>
+    </PropertyGroup>
+
+    <Error Condition="'@(_AggregateExecutableReferencePath)' != '' and '$(OutputType)' != 'Library'" Text="IncludeInAggregateExecutable requires OutputType=Library." />
+    <Error Condition="'@(_AggregateExecutableReferencePath)' != '' and '$(NativeLib)' != 'Shared'" Text="IncludeInAggregateExecutable requires NativeLib=Shared." />
   </Target>
 
   <!--
@@ -328,8 +329,8 @@ The .NET Foundation licenses this file to you under the MIT license.
 
       <!-- Export the managed entry point if building a native library in custom main mode -->
       <IlcArg Condition="'$(NativeLib)' == 'Shared' and '$(CustomNativeMain)' == 'true'" Include="--export-dynamic-symbol:__managed__Main" />
-      <IlcArg Condition="'$(FatExecutable)' == 'true'" Include="@(_FatExecutableReferencePath->'--fatexe:%(AssemblyName)=%(EntryPointSymbol)')" />
-      <IlcArg Condition="'$(FatExecutable)' == 'true'" Include="@(_FatExecutableReferencePath->'--export-dynamic-symbol:%(EntryPointSymbol)')" />
+      <IlcArg Condition="'@(_AggregateExecutableReferencePath)' != ''" Include="@(_AggregateExecutableReferencePath->'--aggregateexe:%(AssemblyName)=%(EntryPointSymbol)')" />
+      <IlcArg Condition="'@(_AggregateExecutableReferencePath)' != ''" Include="@(_AggregateExecutableReferencePath->'--export-dynamic-symbol:%(EntryPointSymbol)')" />
 
       <IlcArg Condition="'$(_InstrumentReachability)' == 'true'" Include="--reachabilityinstrument" />
       <IlcArg Condition="'$(_InstrumentReachability)' == 'true'" Include="--feature:Internal.Runtime.CompilerHelpers.ReachabilityInstrumentationSupport=true" />
diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
index 40632fb3bf5613..875bbeaf73b9e7 100644
--- a/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
+++ b/src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs
@@ -44,8 +44,8 @@ internal sealed class ILCompilerRootCommand : RootCommand
             new("--nativelib") { Description = "Compile as static or shared library" };
         public Option<bool> SplitExeInitialization { get; } =
             new("--splitinit") { Description = "Split initialization of an executable between the library entrypoint and a main entrypoint" };
-        public Option<string[]> FatExeLibrary { get; } =
-            new("--fatexe") { Description = "Specify fat executable library entrypoint modules (format: 'assemblyName=MainEntryPointName')" };
+        public Option<string[]> AggregateExeLibrary { get; } =
+            new("--aggregateexe") { Description = "Specify aggregate executable library entrypoint modules (format: 'assemblyName=MainEntryPointName')" };
         public Option<string> ExportsFile { get; } =
             new("--exportsfile") { Description = "File to write exported symbol and method definitions" };
         public Option<bool> ExportUnmanagedEntryPoints { get; } =
@@ -206,7 +206,7 @@ public ILCompilerRootCommand(string[] args) : base(".NET Native IL Compiler")
             Options.Add(UseDwarf5);
             Options.Add(NativeLib);
             Options.Add(SplitExeInitialization);
-            Options.Add(FatExeLibrary);
+            Options.Add(AggregateExeLibrary);
             Options.Add(ExportsFile);
             Options.Add(ExportDynamicSymbols);
             Options.Add(ExportUnmanagedEntryPoints);
diff --git a/src/coreclr/tools/aot/ILCompiler/Program.cs b/src/coreclr/tools/aot/ILCompiler/Program.cs
index 207b26e92999ec..3e3c9a3eb002a9 100644
--- a/src/coreclr/tools/aot/ILCompiler/Program.cs
+++ b/src/coreclr/tools/aot/ILCompiler/Program.cs
@@ -240,17 +240,17 @@ public int Run()
                     compilationRoots.Add(new RuntimeConfigurationRootProvider(knobsBlobName, runtimeKnobs));
                     compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
 
-                    string[] fatExeModules = Get(_command.FatExeLibrary);
-                    if (fatExeModules.Length > 0)
+                    string[] aggregateExeModules = Get(_command.AggregateExeLibrary);
+                    if (aggregateExeModules.Length > 0)
                     {
-                        foreach (string specifier in fatExeModules)
+                        foreach (string specifier in aggregateExeModules)
                         {
                             int separatorIndex = specifier.IndexOf('=');
                             if (separatorIndex < 0)
-                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Missing '=' separator between assemblyName and MainEntryPointName. Expected format: assemblyName=MainEntryPointName.");
+                                throw new CommandLineException($"Invalid format for --aggregateexe: '{specifier}'. Missing '=' separator between assemblyName and MainEntryPointName. Expected format: assemblyName=MainEntryPointName.");
 
                             if (separatorIndex == 0 || separatorIndex != specifier.LastIndexOf('=') || separatorIndex == specifier.Length - 1)
-                                throw new CommandLineException($"Invalid format for --fatexe: '{specifier}'. Expected format: assemblyName=MainEntryPointName with non-empty assemblyName and MainEntryPointName.");
+                                throw new CommandLineException($"Invalid format for --aggregateexe: '{specifier}'. Expected format: assemblyName=MainEntryPointName with non-empty assemblyName and MainEntryPointName.");
 
                             EcmaModule module = typeSystemContext.GetModuleForSimpleName(specifier.Substring(0, separatorIndex));
                             compilationRoots.Add(new MainMethodRootProvider(module, null, generateLibraryAndModuleInitializers: false, specifier.Substring(separatorIndex + 1)));
diff --git a/src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
similarity index 72%
rename from src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj
rename to src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
index 6f4e34bb0a3176..ba32076b7e4a0b 100644
--- a/src/tests/nativeaot/FatExecutableLibrary/FatLibrary.csproj
+++ b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
@@ -12,30 +12,21 @@
     <CLRTestTargetUnsupported Condition="'$(TargetsAndroid)' == 'true'">true</CLRTestTargetUnsupported>
     <RequiresProcessIsolation>true</RequiresProcessIsolation>
     <CLRTestIsHosted>false</CLRTestIsHosted>
-    <CLRTestRunFile Condition="'$(TargetsWindows)' == 'true'">native\FatLibrary.exe</CLRTestRunFile>
-    <CLRTestRunFile Condition="'$(TargetsWindows)' != 'true'">./native/FatLibrary</CLRTestRunFile>
+    <CLRTestRunFile Condition="'$(TargetsWindows)' == 'true'">native\ValidatorExe.exe</CLRTestRunFile>
+    <CLRTestRunFile Condition="'$(TargetsWindows)' != 'true'">./native/ValidatorExe</CLRTestRunFile>
     <SkipInferOutputType>true</SkipInferOutputType>
-    <FatExecutable>true</FatExecutable>
     <!-- warning CS2008: No source files specified -->
     <NoWarn>$(NoWarn);CS2008</NoWarn>
   </PropertyGroup>
 
-  <PropertyGroup>
-    <CLRTestBatchPreCommands><![CDATA[
-$(CLRTestBatchPreCommands)
-copy /y native\ValidatorExe.exe native\FatLibrary.exe
-set ExePath=
-]]></CLRTestBatchPreCommands>
-
-    <CLRTestBashPreCommands><![CDATA[
-$(CLRTestBashPreCommands)
-cp native/ValidatorExe native/FatLibrary
-ExePath=
-]]></CLRTestBashPreCommands>
-  </PropertyGroup>
-
   <ItemGroup>
-    <ProjectReference Include="HelloExe\HelloExe.csproj" IncludeInFatExe="true" />
-    <ProjectReference Include="ValidatorExe\ValidatorExe.csproj" IncludeInFatExe="true" />
+    <ProjectReference Include="HelloExe\HelloExe.csproj" IncludeInAggregateExecutable="true" />
+    <ProjectReference Include="ValidatorExe\ValidatorExe.csproj" IncludeInAggregateExecutable="true" />
   </ItemGroup>
+
+  <Target Name="UseValidatorExecutableForNativeAotRun" BeforeTargets="GenerateBatchExecutionScript;GenerateBashExecutionScript">
+    <PropertyGroup>
+      <InputAssemblyName>ValidatorExe.dll</InputAssemblyName>
+    </PropertyGroup>
+  </Target>
 </Project>
diff --git a/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.cs b/src/tests/nativeaot/AggregateExecutableLibrary/HelloExe/HelloExe.cs
similarity index 100%
rename from src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.cs
rename to src/tests/nativeaot/AggregateExecutableLibrary/HelloExe/HelloExe.cs
diff --git a/src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/HelloExe/HelloExe.csproj
similarity index 100%
rename from src/tests/nativeaot/FatExecutableLibrary/HelloExe/HelloExe.csproj
rename to src/tests/nativeaot/AggregateExecutableLibrary/HelloExe/HelloExe.csproj
diff --git a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs b/src/tests/nativeaot/AggregateExecutableLibrary/ValidatorExe/ValidatorExe.cs
similarity index 100%
rename from src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.cs
rename to src/tests/nativeaot/AggregateExecutableLibrary/ValidatorExe/ValidatorExe.cs
diff --git a/src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/ValidatorExe/ValidatorExe.csproj
similarity index 100%
rename from src/tests/nativeaot/FatExecutableLibrary/ValidatorExe/ValidatorExe.csproj
rename to src/tests/nativeaot/AggregateExecutableLibrary/ValidatorExe/ValidatorExe.csproj

From c88d0f2e803ad00c93c8699ae6acee7601c35b1b Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 26 May 2026 06:02:20 +0000
Subject: [PATCH 08/27] Address aggregate executable validation feedback

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f0f54e39-2f6a-48af-88ed-f5724228b103

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets  | 6 +++---
 .../BuildIntegration/Microsoft.NETCore.Native.targets       | 1 +
 .../AggregateExecutableLibrary/AggregateLibrary.csproj      | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 13c4b0e6c0910e..518a5eb2876c35 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -382,10 +382,10 @@ The .NET Foundation licenses this file to you under the MIT license.
   <Target Name="CreateShimExes"
           Condition="'$(AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative;WriteAggregateExecutableShimRspFiles"
-          Inputs="$(NativeBinary);@(_AggregateExecutableReferencePath->'%(ShimSource)');@(_AggregateExecutableReferencePath->'%(ShimLinkRspFile)')"
+          Inputs="$(NativeBinary);@(_AggregateExecutableReferencePath->'%(ShimSource)');@(_AggregateExecutableReferencePath->'%(ShimCompileLinkRspFile)')"
           Outputs="@(_AggregateExecutableShim);@(_AggregateExecutableShimSymbol)">
 
-    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimLinkRspFile)&quot;" />
+    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
           Command="&quot;$(ObjCopyName)&quot; --only-keep-debug &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot; &quot;%(_AggregateExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
@@ -431,6 +431,6 @@ int main(int argc, char** argv)
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
     <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_AggregateExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimLinkRspFile)" Lines="&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;;@(_AggregateExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)" Lines="&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;;@(_AggregateExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
   </Target>
 </Project>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index 195b2bde1beeeb..d0ff50c5d2f077 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -192,6 +192,7 @@ The .NET Foundation licenses this file to you under the MIT license.
         <ShimObject>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe$(NativeObjectExt)</ShimObject>
         <ShimCompileRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.cl.rsp</ShimCompileRspFile>
         <ShimLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.link.rsp</ShimLinkRspFile>
+        <ShimCompileLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.rsp</ShimCompileLinkRspFile>
         <ShimBinary>$(NativeOutputPath)%(TargetName)$(NativeExecutableExt)</ShimBinary>
         <ShimSymbol>$(NativeOutputPath)%(TargetName)$(NativeSymbolExt)</ShimSymbol>
       </_AggregateExecutableReferencePath>
diff --git a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
index ba32076b7e4a0b..ffe26bff3c9f40 100644
--- a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
+++ b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
@@ -12,7 +12,7 @@
     <CLRTestTargetUnsupported Condition="'$(TargetsAndroid)' == 'true'">true</CLRTestTargetUnsupported>
     <RequiresProcessIsolation>true</RequiresProcessIsolation>
     <CLRTestIsHosted>false</CLRTestIsHosted>
-    <CLRTestRunFile Condition="'$(TargetsWindows)' == 'true'">native\ValidatorExe.exe</CLRTestRunFile>
+    <CLRTestRunFile Condition="'$(TargetsWindows)' == 'true'">native/ValidatorExe.exe</CLRTestRunFile>
     <CLRTestRunFile Condition="'$(TargetsWindows)' != 'true'">./native/ValidatorExe</CLRTestRunFile>
     <SkipInferOutputType>true</SkipInferOutputType>
     <!-- warning CS2008: No source files specified -->

From 93f93d0bcd059e0513f53151e1b81e844d6bab43 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 26 May 2026 06:06:53 +0000
Subject: [PATCH 09/27] Refine aggregate executable response file handling

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f0f54e39-2f6a-48af-88ed-f5724228b103

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Unix.targets     | 24 +++++++++----------
 .../AggregateLibrary.csproj                   |  2 +-
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 518a5eb2876c35..60e1ec47be086e 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -416,21 +416,21 @@ int main(int argc, char** argv)
     </ItemGroup>
 
     <ItemGroup>
-      <_AggregateExecutableShimLinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
-      <_AggregateExecutableShimLinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
-      <_AggregateExecutableShimLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
     </ItemGroup>
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
     <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_AggregateExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)" Lines="&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;;@(_AggregateExecutableShimLinkerArg)" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)" Lines="@(_AggregateExecutableShimCompilerAndLinkerArg);&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
   </Target>
 </Project>
diff --git a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
index ffe26bff3c9f40..648b606c19f6ac 100644
--- a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
+++ b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
@@ -24,7 +24,7 @@
     <ProjectReference Include="ValidatorExe\ValidatorExe.csproj" IncludeInAggregateExecutable="true" />
   </ItemGroup>
 
-  <Target Name="UseValidatorExecutableForNativeAotRun" BeforeTargets="GenerateBatchExecutionScript;GenerateBashExecutionScript">
+  <Target Name="OverrideTestEntryPointToValidator" BeforeTargets="GenerateBatchExecutionScript;GenerateBashExecutionScript">
     <PropertyGroup>
       <InputAssemblyName>ValidatorExe.dll</InputAssemblyName>
     </PropertyGroup>

From 9cea2e33611f2f589581ea1e97752001327e2a1c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 26 May 2026 08:10:56 +0000
Subject: [PATCH 10/27] Avoid absolute aggregate shared library dependency

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ff586a1f-b533-4271-a092-8a030ea016ec

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets  | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 60e1ec47be086e..0c7612c68743af 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -427,10 +427,14 @@ int main(int argc, char** argv)
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
+
+      <_AggregateExecutableShimNativeLibraryArg Include="-L&quot;$(NativeOutputPath)&quot;" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimNativeLibraryArg Include="-l:$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <_AggregateExecutableShimNativeLibraryArg Include="&quot;$(NativeBinary)&quot;" Condition="'$(_IsApplePlatform)' == 'true'" />
     </ItemGroup>
 
     <MakeDir Directories="$(NativeIntermediateOutputPath);$(NativeOutputPath)" />
     <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimSource)" Lines="$([MSBuild]::Escape('%(_AggregateExecutableReferencePath.ShimSourceCode)'))" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
-    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)" Lines="@(_AggregateExecutableShimCompilerAndLinkerArg);&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;&quot;$(NativeBinary)&quot;;-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
+    <WriteLinesToFile File="%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)" Lines="@(_AggregateExecutableShimCompilerAndLinkerArg);&quot;%(_AggregateExecutableReferencePath.ShimSource)&quot;;@(_AggregateExecutableShimNativeLibraryArg);-o;&quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot;" Overwrite="true" Encoding="utf-8" WriteOnlyWhenDifferent="true" />
   </Target>
 </Project>

From d273bad498e505375fa28bcf6d8484ac4bab14db Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Tue, 26 May 2026 10:35:24 +0000
Subject: [PATCH 11/27] Restore execute permission for aggregate test shim

Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/5b3bca38-fa3b-46a4-840c-50b496db204a

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../AggregateExecutableLibrary/AggregateLibrary.csproj   | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
index 648b606c19f6ac..8fed09b471616a 100644
--- a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
+++ b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
@@ -29,4 +29,13 @@
       <InputAssemblyName>ValidatorExe.dll</InputAssemblyName>
     </PropertyGroup>
   </Target>
+
+  <Target Name="WriteHelixExtraExecutablesList" AfterTargets="NativeCompile" Condition="'$(TargetsWindows)' != 'true'">
+    <PropertyGroup>
+      <_HelloExeRelative>$(BuildProjectRelativeDir)native/HelloExe</_HelloExeRelative>
+      <_HelloExeRelative Condition="'$(BuildProjectRelativeDir)' == ''">$([System.IO.Path]::GetRelativePath('$(TestBinDir)', '$(TargetDir)native/HelloExe'))</_HelloExeRelative>
+    </PropertyGroup>
+
+    <WriteLinesToFile File="$(TargetDir)helix-extra-executables.list" Lines="$(_HelloExeRelative)" Overwrite="true" WriteOnlyWhenDifferent="true" />
+  </Target>
 </Project>

From a9c6fdcc65cd7bc4cdde9b7d4db9f23f05e9429d Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 02:49:03 +0000
Subject: [PATCH 12/27] Address aggregate executable build integration review

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Publish.targets  | 10 +--
 .../Microsoft.NETCore.Native.Unix.targets     | 58 +++++++++------
 .../Microsoft.NETCore.Native.Windows.targets  | 70 ++++++++++++-------
 .../Microsoft.NETCore.Native.targets          | 14 ++--
 4 files changed, 89 insertions(+), 63 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
index 3062addaf33733..610ae55338e49d 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
@@ -41,21 +41,21 @@
         <RelativePath>$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
-      <ResolvedFileToPublish Include="@(_AggregateExecutableShim)" Condition="'$(AggregateExecutable)' == 'true'">
+      <ResolvedFileToPublish Include="@(_AggregateExecutableShim)" Condition="'$(_AggregateExecutable)' == 'true'">
         <RelativePath>%(_AggregateExecutableShim.RelativePath)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
       <ResolvedFileToPublish Include="@(_AggregateExecutableShimSymbol)"
-                             Condition="'$(AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' != '.dSYM' and Exists('%(_AggregateExecutableShimSymbol.Identity)')">
+                             Condition="'$(_AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' != '.dSYM' and Exists('%(_AggregateExecutableShimSymbol.Identity)')">
         <RelativePath>%(_AggregateExecutableShimSymbol.RelativePath)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
       <_AggregateExecutableShimSymbolRecursivePath Include="%(_AggregateExecutableReferencePath.ShimSymbol)/**/*"
-                                             Condition="'$(AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' == '.dSYM' and Exists('%(_AggregateExecutableReferencePath.ShimSymbol)')">
-        <RelativePath>%(_AggregateExecutableReferencePath.TargetName)$(NativeSymbolExt)/%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
+                                             Condition="'$(_AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(NativeSymbolExt)' == '.dSYM' and Exists('%(_AggregateExecutableReferencePath.ShimSymbol)')">
+        <RelativePath>%(_AggregateExecutableReferencePath.AssemblyName)$(NativeSymbolExt)/%(RecursiveDir)%(Filename)%(Extension)</RelativePath>
       </_AggregateExecutableShimSymbolRecursivePath>
       <ResolvedFileToPublish Include="@(_AggregateExecutableShimSymbolRecursivePath)"
-                             Condition="'$(AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
+                             Condition="'$(_AggregateExecutable)' == 'true' and '$(CopyOutputSymbolsToPublishDirectory)' == 'true'">
         <RelativePath>%(_AggregateExecutableShimSymbolRecursivePath.RelativePath)</RelativePath>
         <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
       </ResolvedFileToPublish>
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 0c7612c68743af..d35fcb6d189023 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -17,7 +17,6 @@ The .NET Foundation licenses this file to you under the MIT license.
     <CppCompilerAndLinkerAlternative />
     <CppCompilerAndLinkerAlternative Condition="'$(CppCompilerAndLinker)' == '' and '$(_IsApplePlatform)' != 'true'">gcc</CppCompilerAndLinkerAlternative>
     <CppCompilerAndLinker Condition="'$(CppCompilerAndLinker)' == ''">clang</CppCompilerAndLinker>
-    <CppCompiler Condition="'$(CppCompiler)' == ''">$(CppCompilerAndLinker)</CppCompiler>
     <CppLinker>$(CppCompilerAndLinker)</CppLinker>
     <CppLibCreator>ar</CppLibCreator>
     <_SymbolPrefix Condition="'$(_IsApplePlatform)' == 'true'">_</_SymbolPrefix>
@@ -240,15 +239,27 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <ItemGroup>
       <LinkerArg Include="-gz=zlib" Condition="'$(CompressSymbols)' != 'false'" />
-      <LinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
+      <LinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <LinkerArg Include="@(NativeLibrary)" />
-      <LinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
-      <LinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
-      <LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
-      <LinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
+      <LinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <LinkerArg Include="-Wl,--strip-debug" Condition="$(NativeDebugSymbols) != 'true' and '$(_IsApplePlatform)' != 'true'" />
       <LinkerArg Include="-Wl,-install_name,&quot;$(SharedLibraryInstallName)&quot;" Condition="'$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'" />
-      <LinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <LinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <LinkerArg Include="-Wl,--as-needed" Condition="'$(_IsApplePlatform)' != 'true'" />
       <LinkerArg Include="-Wl,-e,0x0" Condition="'$(NativeLib)' == 'Shared' and '$(_IsApplePlatform)' != 'true'" />
       <LinkerArg Include="-pthread" Condition="'$(_IsApplePlatform)' != 'true'" />
@@ -264,10 +275,16 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
       <LinkerArg Include="-Wl,-no-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' == 'false'" />
       <!-- binskim warning BA3010 The GNU_RELRO segment is missing -->
-      <LinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
+      <LinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <!-- binskim warning BA3011 The BIND_NOW flag is missing -->
-      <LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" />
+      <LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <!-- this workaround can be deleted once the minimum supported glibc version
            (runtime's official build machine's glibc version) is at least 2.33
            see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
@@ -286,6 +303,10 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Include="-Wl,-z,max-page-size=16384" Condition=" '$(_linuxLibcFlavor)' == 'bionic' and '$(NativeLib)' == 'Shared' and ('$(_targetArchitecture)' == 'x64' or '$(_targetArchitecture)' == 'arm64')" />
     </ItemGroup>
 
+    <ItemGroup>
+      <_CommonLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.AggregateExecutableShimLink)' == 'true'" />
+    </ItemGroup>
+
     <Exec Command="xcodebuild -version" Condition="'$(_IsApplePlatform)' == 'true' and '$(UseLdClassicXCodeLinker)' == ''" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">
       <Output TaskParameter="ExitCode" PropertyName="_XcodeVersionStringExitCode" />
       <Output TaskParameter="ConsoleOutput" PropertyName="_XcodeVersionString" />
@@ -314,7 +335,6 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <PropertyGroup Condition="'$(CppCompilerAndLinkerAlternative)' != '' and '$(_WhereLinker)' != '0' and '$(_WhereLinkerAlt)' == '0' and '$(NativeLib)' != 'Static'">
       <CppCompilerAndLinker>$(CppCompilerAndLinkerAlternative)</CppCompilerAndLinker>
-      <CppCompiler>$(CppCompilerAndLinker)</CppCompiler>
       <CppLinker>$(CppCompilerAndLinker)</CppLinker>
       <_WhereLinker>0</_WhereLinker>
     </PropertyGroup>
@@ -380,12 +400,12 @@ The .NET Foundation licenses this file to you under the MIT license.
   </Target>
 
   <Target Name="CreateShimExes"
-          Condition="'$(AggregateExecutable)' == 'true'"
+          Condition="'$(_AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative;WriteAggregateExecutableShimRspFiles"
           Inputs="$(NativeBinary);@(_AggregateExecutableReferencePath->'%(ShimSource)');@(_AggregateExecutableReferencePath->'%(ShimCompileLinkRspFile)')"
           Outputs="@(_AggregateExecutableShim);@(_AggregateExecutableShimSymbol)">
 
-    <Exec Command="&quot;$(CppCompiler)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)&quot;" />
+    <Exec Command="&quot;$(CppLinker)&quot; @&quot;%(_AggregateExecutableReferencePath.ShimCompileLinkRspFile)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(NativeDebugSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
           Command="&quot;$(ObjCopyName)&quot; --only-keep-debug &quot;%(_AggregateExecutableReferencePath.ShimBinary)&quot; &quot;%(_AggregateExecutableReferencePath.ShimBinary)$(NativeSymbolExt)&quot;" />
     <Exec Condition="'$(StripSymbols)' == 'true' and '$(_IsApplePlatform)' != 'true'"
@@ -400,7 +420,7 @@ The .NET Foundation licenses this file to you under the MIT license.
   </Target>
 
   <Target Name="WriteAggregateExecutableShimRspFiles"
-          Condition="'$(AggregateExecutable)' == 'true'"
+          Condition="'$(_AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative">
 
     <ItemGroup>
@@ -416,17 +436,9 @@ int main(int argc, char** argv)
     </ItemGroup>
 
     <ItemGroup>
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="@(_CommonLinkerArg)" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" />
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != '' and '$(_IsApplePlatform)' != 'true'" />
 
       <_AggregateExecutableShimNativeLibraryArg Include="-L&quot;$(NativeOutputPath)&quot;" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimNativeLibraryArg Include="-l:$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" Condition="'$(_IsApplePlatform)' != 'true'" />
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index c95c70b709f75d..b2c71ccabccd1c 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -94,35 +94,63 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Condition="'$(NativeLib)' == 'Shared'" Include="/DLL" />
       <LinkerArg Include="@(NativeLibrary->'&quot;%(Identity)&quot;')" />
       <LinkerArg Include="@(SdkNativeLibrary->'&quot;%(Identity)&quot;')" />
-      <LinkerArg Include="/NOLOGO /MANIFEST:NO" />
+      <LinkerArg Include="/NOLOGO /MANIFEST:NO">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <LinkerArg Condition="$(IlcMergeSections) != 'false'" Include="/MERGE:.managedcode=.text /MERGE:hydrated=.bss" />
-      <LinkerArg Condition="$(NativeDebugSymbols) == 'true'" Include="/DEBUG" />
+      <LinkerArg Condition="$(NativeDebugSymbols) == 'true'" Include="/DEBUG">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <!-- The runtime is not compatible with jump stubs inserted by incremental linking. -->
-      <LinkerArg Include="/INCREMENTAL:NO" />
+      <LinkerArg Include="/INCREMENTAL:NO">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <LinkerArg Condition="'$(NativeLib)' == '' and '$(LinkerSubsystem)' != ''" Include="/SUBSYSTEM:$(LinkerSubsystem)" />
       <LinkerArg Condition="'$(NativeLib)' == ''" Include="/ENTRY:$(EntryPointSymbol) /NOEXP /NOIMPLIB /STACK:$(IlcDefaultStackSize)" />
       <LinkerArg Include="/NATVIS:&quot;$(MSBuildThisFileDirectory)NativeAOT.natvis&quot;" />
-      <LinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
-      <LinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh" />
+      <LinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <!-- Do not warn if someone declares UnmanagedCallersOnly with an entrypoint of 'DllGetClassObject' and similar -->
       <LinkerArg Include="/IGNORE:4104" />
       <!-- Opt into CETCOMPAT by default. -->
-      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT" />
+      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <!-- Allow user to opt out. -->
-      <LinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO" />
+      <LinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
       <!-- Enable EHCONT if CET is not disabled and CFG is enabled. -->
-      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont"/>
+      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
     </ItemGroup>
 
     <ItemGroup Condition="!Exists('$(IlcSdkPath)debugucrt.txt')">
       <!-- Force ucrt to be dynamically linked for release runtime -->
-      <LinkerArg Include="/NODEFAULTLIB:libucrt.lib" />
-      <LinkerArg Include="/DEFAULTLIB:ucrt.lib" />
+      <LinkerArg Include="/NODEFAULTLIB:libucrt.lib">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Include="/DEFAULTLIB:ucrt.lib">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
     </ItemGroup>
 
     <ItemGroup Condition="'$(Configuration)' != 'Debug'">
-      <LinkerArg Include="/OPT:REF" />
-      <LinkerArg Include="/OPT:ICF" />
+      <LinkerArg Include="/OPT:REF">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+      <LinkerArg Include="/OPT:ICF">
+        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
+      </LinkerArg>
+    </ItemGroup>
+
+    <ItemGroup>
+      <_CommonLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.AggregateExecutableShimLink)' == 'true'" />
     </ItemGroup>
 
     <Exec Condition="'$(IlcUseEnvironmentalTools)' != 'true'" Command="&quot;$(MSBuildThisFileDirectory)findvcvarsall.bat&quot; $(_targetArchitecture)"
@@ -146,7 +174,7 @@ The .NET Foundation licenses this file to you under the MIT license.
   </Target>
 
   <Target Name="CreateShimExes"
-          Condition="'$(AggregateExecutable)' == 'true'"
+          Condition="'$(_AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative;WriteAggregateExecutableShimRspFiles"
           Inputs="$(NativeImportLibrary);@(_AggregateExecutableReferencePath->'%(ShimSource)');@(_AggregateExecutableReferencePath->'%(ShimCompileRspFile)');@(_AggregateExecutableReferencePath->'%(ShimLinkRspFile)')"
           Outputs="@(_AggregateExecutableShim);@(_AggregateExecutableShimSymbol)">
@@ -157,7 +185,7 @@ The .NET Foundation licenses this file to you under the MIT license.
   </Target>
 
   <Target Name="WriteAggregateExecutableShimRspFiles"
-          Condition="'$(AggregateExecutable)' == 'true'"
+          Condition="'$(_AggregateExecutable)' == 'true'"
           DependsOnTargets="LinkNative">
 
     <ItemGroup>
@@ -180,21 +208,9 @@ int wmain(int argc, unsigned short** argv)
       <_AggregateExecutableShimCompilerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/Z7" />
       <_AggregateExecutableShimCompilerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
 
-      <_AggregateExecutableShimLinkerArg Include="/NOLOGO" />
-      <_AggregateExecutableShimLinkerArg Include="/MANIFEST:NO" />
+      <_AggregateExecutableShimLinkerArg Include="@(_CommonLinkerArg)" />
       <_AggregateExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
       <_AggregateExecutableShimLinkerArg Include="/STACK:$(IlcDefaultStackSize)" />
-      <_AggregateExecutableShimLinkerArg Include="/INCREMENTAL:NO" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/DEBUG" />
-      <_AggregateExecutableShimLinkerArg Include="/NODEFAULTLIB:libucrt.lib" />
-      <_AggregateExecutableShimLinkerArg Include="/DEFAULTLIB:ucrt.lib" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:REF" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(Configuration)' != 'Debug'" Include="/OPT:ICF" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO" />
-      <_AggregateExecutableShimLinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont" />
       <_AggregateExecutableShimLinkerArg Include="@(AdditionalNativeLibraryDirectories->'/LIBPATH:&quot;%(Identity)&quot;')" />
     </ItemGroup>
 
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index d0ff50c5d2f077..7a3efa0d1d6710 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -103,8 +103,7 @@ The .NET Foundation licenses this file to you under the MIT license.
   <PropertyGroup Condition="'$(IlcCompileDependsOn)'=='' and '$(NativeCompilationDuringPublish)' != 'false'">
     <IlcCompileDependsOn Condition="'$(BuildingFrameworkLibrary)' != 'true'">Compile;ComputeIlcCompileInputs</IlcCompileDependsOn>
     <IlcCompileDependsOn Condition="'$(IlcMultiModule)' == 'true' and '$(BuildingFrameworkLibrary)' != 'true'">$(IlcCompileDependsOn);BuildFrameworkLib</IlcCompileDependsOn>
-    <IlcCompileDependsOn>$(IlcCompileDependsOn);ComputeAggregateExecutableInputs</IlcCompileDependsOn>
-    <IlcCompileDependsOn>$(IlcCompileDependsOn);SetupOSSpecificProps</IlcCompileDependsOn>
+    <IlcCompileDependsOn>$(IlcCompileDependsOn);ComputeAggregateExecutableInputs;SetupOSSpecificProps</IlcCompileDependsOn>
   </PropertyGroup>
 
   <ItemGroup Condition="$(IlcSystemModule) == ''">
@@ -181,7 +180,6 @@ The .NET Foundation licenses this file to you under the MIT license.
         <AssemblyName>%(ReferencePath.Filename)</AssemblyName>
         <SanitizedAssemblyName>__AggregateExeShim_$([System.Text.RegularExpressions.Regex]::Replace('%(ReferencePath.Filename)', '[^A-Za-z0-9_]', '_'))</SanitizedAssemblyName>
         <AssemblyNameHash>$([MSBuild]::StableStringHash('%(ReferencePath.Filename)', 'Sha256'))</AssemblyNameHash>
-        <TargetName>%(ReferencePath.Filename)</TargetName>
       </_AggregateExecutableReferencePath>
       <_AggregateExecutableReferencePath>
         <EntryPointSymbol>_AggregateExeMain_%(SanitizedAssemblyName)_%(AssemblyNameHash)</EntryPointSymbol>
@@ -193,19 +191,19 @@ The .NET Foundation licenses this file to you under the MIT license.
         <ShimCompileRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.cl.rsp</ShimCompileRspFile>
         <ShimLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.link.rsp</ShimLinkRspFile>
         <ShimCompileLinkRspFile>$(NativeIntermediateOutputPath)%(AssemblyName).aggregateexe.rsp</ShimCompileLinkRspFile>
-        <ShimBinary>$(NativeOutputPath)%(TargetName)$(NativeExecutableExt)</ShimBinary>
-        <ShimSymbol>$(NativeOutputPath)%(TargetName)$(NativeSymbolExt)</ShimSymbol>
+        <ShimBinary>$(NativeOutputPath)%(AssemblyName)$(NativeExecutableExt)</ShimBinary>
+        <ShimSymbol>$(NativeOutputPath)%(AssemblyName)$(NativeSymbolExt)</ShimSymbol>
       </_AggregateExecutableReferencePath>
       <_AggregateExecutableShim Include="%(_AggregateExecutableReferencePath.ShimBinary)">
-        <RelativePath>%(_AggregateExecutableReferencePath.TargetName)$(NativeExecutableExt)</RelativePath>
+        <RelativePath>%(_AggregateExecutableReferencePath.AssemblyName)$(NativeExecutableExt)</RelativePath>
       </_AggregateExecutableShim>
       <_AggregateExecutableShimSymbol Include="%(_AggregateExecutableReferencePath.ShimSymbol)" Condition="'$(NativeDebugSymbols)' == 'true'">
-        <RelativePath>%(_AggregateExecutableReferencePath.TargetName)$(NativeSymbolExt)</RelativePath>
+        <RelativePath>%(_AggregateExecutableReferencePath.AssemblyName)$(NativeSymbolExt)</RelativePath>
       </_AggregateExecutableShimSymbol>
     </ItemGroup>
 
     <PropertyGroup>
-      <AggregateExecutable Condition="'$(NativeLib)' == 'Shared' and '@(_AggregateExecutableReferencePath)' != ''">true</AggregateExecutable>
+      <_AggregateExecutable Condition="'$(NativeLib)' == 'Shared' and '@(_AggregateExecutableReferencePath)' != ''">true</_AggregateExecutable>
     </PropertyGroup>
 
     <Error Condition="'@(_AggregateExecutableReferencePath)' != '' and '$(OutputType)' != 'Library'" Text="IncludeInAggregateExecutable requires OutputType=Library." />

From 631b1f64be5b6b8452e927b64a92e02494f87a2d Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 03:29:39 +0000
Subject: [PATCH 13/27] Simplify aggregate shim linker metadata

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Unix.targets     | 42 ++++-----------
 .../Microsoft.NETCore.Native.Windows.targets  | 54 +++++--------------
 2 files changed, 23 insertions(+), 73 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index d35fcb6d189023..c8438875676e57 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -239,27 +239,15 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <ItemGroup>
       <LinkerArg Include="-gz=zlib" Condition="'$(CompressSymbols)' != 'false'" />
-      <LinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="-fuse-ld=$(LinkerFlavor)" Condition="'$(LinkerFlavor)' != ''" Shim="true" />
       <LinkerArg Include="@(NativeLibrary)" />
-      <LinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="--sysroot=&quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' != 'true'" Shim="true" />
+      <LinkerArg Include="-isysroot &quot;$(SysRoot)&quot;" Condition="'$(SysRoot)' != '' and '$(_IsApplePlatform)' == 'true'" Shim="true" />
+      <LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" Shim="true" />
+      <LinkerArg Include="-g" Condition="$(NativeDebugSymbols) == 'true'" Shim="true" />
       <LinkerArg Include="-Wl,--strip-debug" Condition="$(NativeDebugSymbols) != 'true' and '$(_IsApplePlatform)' != 'true'" />
       <LinkerArg Include="-Wl,-install_name,&quot;$(SharedLibraryInstallName)&quot;" Condition="'$(_IsApplePlatform)' == 'true' and '$(NativeLib)' == 'Shared'" />
-      <LinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="-Wl,--build-id=sha1" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
       <LinkerArg Include="-Wl,--as-needed" Condition="'$(_IsApplePlatform)' != 'true'" />
       <LinkerArg Include="-Wl,-e,0x0" Condition="'$(NativeLib)' == 'Shared' and '$(_IsApplePlatform)' != 'true'" />
       <LinkerArg Include="-pthread" Condition="'$(_IsApplePlatform)' != 'true'" />
@@ -275,16 +263,10 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
       <LinkerArg Include="-Wl,-no-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(NativeLib)' == '' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' == 'false'" />
       <!-- binskim warning BA3010 The GNU_RELRO segment is missing -->
-      <LinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="-Wl,-z,relro" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
       <!-- binskim warning BA3011 The BIND_NOW flag is missing -->
-      <LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="-Wl,-z,now" Condition="'$(_IsApplePlatform)' != 'true'" Shim="true" />
+      <LinkerArg Include="-Wl,-z,stack-size=$(IlcDefaultStackSize)" Condition="'$(IlcDefaultStackSize)' != ''" Shim="true" />
       <!-- this workaround can be deleted once the minimum supported glibc version
            (runtime's official build machine's glibc version) is at least 2.33
            see https://github.com/bminor/glibc/commit/99468ed45f5a58f584bab60364af937eb6f8afda -->
@@ -303,10 +285,6 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Include="-Wl,-z,max-page-size=16384" Condition=" '$(_linuxLibcFlavor)' == 'bionic' and '$(NativeLib)' == 'Shared' and ('$(_targetArchitecture)' == 'x64' or '$(_targetArchitecture)' == 'arm64')" />
     </ItemGroup>
 
-    <ItemGroup>
-      <_CommonLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.AggregateExecutableShimLink)' == 'true'" />
-    </ItemGroup>
-
     <Exec Command="xcodebuild -version" Condition="'$(_IsApplePlatform)' == 'true' and '$(UseLdClassicXCodeLinker)' == ''" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">
       <Output TaskParameter="ExitCode" PropertyName="_XcodeVersionStringExitCode" />
       <Output TaskParameter="ConsoleOutput" PropertyName="_XcodeVersionString" />
@@ -436,7 +414,7 @@ int main(int argc, char** argv)
     </ItemGroup>
 
     <ItemGroup>
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="@(_CommonLinkerArg)" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.Shim)' == 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
 
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index b2c71ccabccd1c..7fa77a475f8aa1 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -94,63 +94,35 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Condition="'$(NativeLib)' == 'Shared'" Include="/DLL" />
       <LinkerArg Include="@(NativeLibrary->'&quot;%(Identity)&quot;')" />
       <LinkerArg Include="@(SdkNativeLibrary->'&quot;%(Identity)&quot;')" />
-      <LinkerArg Include="/NOLOGO /MANIFEST:NO">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="/NOLOGO /MANIFEST:NO" Shim="true" />
       <LinkerArg Condition="$(IlcMergeSections) != 'false'" Include="/MERGE:.managedcode=.text /MERGE:hydrated=.bss" />
-      <LinkerArg Condition="$(NativeDebugSymbols) == 'true'" Include="/DEBUG">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Condition="$(NativeDebugSymbols) == 'true'" Include="/DEBUG" Shim="true" />
       <!-- The runtime is not compatible with jump stubs inserted by incremental linking. -->
-      <LinkerArg Include="/INCREMENTAL:NO">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="/INCREMENTAL:NO" Shim="true" />
       <LinkerArg Condition="'$(NativeLib)' == '' and '$(LinkerSubsystem)' != ''" Include="/SUBSYSTEM:$(LinkerSubsystem)" />
       <LinkerArg Condition="'$(NativeLib)' == ''" Include="/ENTRY:$(EntryPointSymbol) /NOEXP /NOIMPLIB /STACK:$(IlcDefaultStackSize)" />
       <LinkerArg Include="/NATVIS:&quot;$(MSBuildThisFileDirectory)NativeAOT.natvis&quot;" />
-      <LinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" Shim="true" />
+      <LinkerArg Condition="'$(_targetArchitecture)' == 'x86'" Include="/safeseh" Shim="true" />
       <!-- Do not warn if someone declares UnmanagedCallersOnly with an entrypoint of 'DllGetClassObject' and similar -->
       <LinkerArg Include="/IGNORE:4104" />
       <!-- Opt into CETCOMPAT by default. -->
-      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT" Shim="true" />
       <!-- Allow user to opt out. -->
-      <LinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Condition="'$(CETCompat)' == 'false' and '$(_targetArchitecture)' == 'x64'" Include="/CETCOMPAT:NO" Shim="true" />
       <!-- Enable EHCONT if CET is not disabled and CFG is enabled. -->
-      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Condition="'$(CETCompat)' != 'false' and '$(_targetArchitecture)' == 'x64' and '$(ControlFlowGuard)' == 'Guard'" Include="/guard:ehcont" Shim="true" />
     </ItemGroup>
 
     <ItemGroup Condition="!Exists('$(IlcSdkPath)debugucrt.txt')">
       <!-- Force ucrt to be dynamically linked for release runtime -->
-      <LinkerArg Include="/NODEFAULTLIB:libucrt.lib">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Include="/DEFAULTLIB:ucrt.lib">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
+      <LinkerArg Include="/NODEFAULTLIB:libucrt.lib" Shim="true" />
+      <LinkerArg Include="/DEFAULTLIB:ucrt.lib" Shim="true" />
     </ItemGroup>
 
     <ItemGroup Condition="'$(Configuration)' != 'Debug'">
-      <LinkerArg Include="/OPT:REF">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-      <LinkerArg Include="/OPT:ICF">
-        <AggregateExecutableShimLink>true</AggregateExecutableShimLink>
-      </LinkerArg>
-    </ItemGroup>
-
-    <ItemGroup>
-      <_CommonLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.AggregateExecutableShimLink)' == 'true'" />
+      <LinkerArg Include="/OPT:REF" Shim="true" />
+      <LinkerArg Include="/OPT:ICF" Shim="true" />
     </ItemGroup>
 
     <Exec Condition="'$(IlcUseEnvironmentalTools)' != 'true'" Command="&quot;$(MSBuildThisFileDirectory)findvcvarsall.bat&quot; $(_targetArchitecture)"
@@ -208,7 +180,7 @@ int wmain(int argc, unsigned short** argv)
       <_AggregateExecutableShimCompilerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/Z7" />
       <_AggregateExecutableShimCompilerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
 
-      <_AggregateExecutableShimLinkerArg Include="@(_CommonLinkerArg)" />
+      <_AggregateExecutableShimLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.Shim)' == 'true'" />
       <_AggregateExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
       <_AggregateExecutableShimLinkerArg Include="/STACK:$(IlcDefaultStackSize)" />
       <_AggregateExecutableShimLinkerArg Include="@(AdditionalNativeLibraryDirectories->'/LIBPATH:&quot;%(Identity)&quot;')" />

From c32bdc07785db53736eb701e32c278dbc3cf8f11 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 04:51:06 +0000
Subject: [PATCH 14/27] Address aggregate shim linker feedback

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets      | 2 ++
 .../BuildIntegration/Microsoft.NETCore.Native.Windows.targets   | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index c8438875676e57..7c4e98c6fd85d4 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -417,6 +417,8 @@ int main(int argc, char** argv)
       <_AggregateExecutableShimCompilerAndLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.Shim)' == 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
+      <!-- binskim warning BA3001 PIE disabled on executable -->
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
 
       <_AggregateExecutableShimNativeLibraryArg Include="-L&quot;$(NativeOutputPath)&quot;" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimNativeLibraryArg Include="-l:$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" Condition="'$(_IsApplePlatform)' != 'true'" />
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 7fa77a475f8aa1..95f8c0c7c8b579 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -98,7 +98,7 @@ The .NET Foundation licenses this file to you under the MIT license.
       <LinkerArg Condition="$(IlcMergeSections) != 'false'" Include="/MERGE:.managedcode=.text /MERGE:hydrated=.bss" />
       <LinkerArg Condition="$(NativeDebugSymbols) == 'true'" Include="/DEBUG" Shim="true" />
       <!-- The runtime is not compatible with jump stubs inserted by incremental linking. -->
-      <LinkerArg Include="/INCREMENTAL:NO" Shim="true" />
+      <LinkerArg Include="/INCREMENTAL:NO" />
       <LinkerArg Condition="'$(NativeLib)' == '' and '$(LinkerSubsystem)' != ''" Include="/SUBSYSTEM:$(LinkerSubsystem)" />
       <LinkerArg Condition="'$(NativeLib)' == ''" Include="/ENTRY:$(EntryPointSymbol) /NOEXP /NOIMPLIB /STACK:$(IlcDefaultStackSize)" />
       <LinkerArg Include="/NATVIS:&quot;$(MSBuildThisFileDirectory)NativeAOT.natvis&quot;" />

From 6f3fb22cd684d1221496a1e306695b2674bea9a6 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 12:55:36 +0000
Subject: [PATCH 15/27] Fix Windows x86 aggregate shim symbol

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Windows.targets              | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 95f8c0c7c8b579..f23083411d85df 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -162,11 +162,15 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <ItemGroup>
       <_AggregateExecutableReferencePath>
-        <ShimSourceCode><![CDATA[__declspec(dllimport) int %(_AggregateExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
+        <ShimEntryPointSymbol>%(_AggregateExecutableReferencePath.EntryPointSymbol)</ShimEntryPointSymbol>
+        <ShimEntryPointSymbol Condition="'$(_targetArchitecture)' == 'x86'">$([System.String]::Copy('%(_AggregateExecutableReferencePath.EntryPointSymbol)').Substring(1))</ShimEntryPointSymbol>
+      </_AggregateExecutableReferencePath>
+      <_AggregateExecutableReferencePath>
+        <ShimSourceCode><![CDATA[__declspec(dllimport) int %(_AggregateExecutableReferencePath.ShimEntryPointSymbol)(int, unsigned short**);
 
 int wmain(int argc, unsigned short** argv)
 {
-    return %(_AggregateExecutableReferencePath.EntryPointSymbol)(argc, argv);
+    return %(_AggregateExecutableReferencePath.ShimEntryPointSymbol)(argc, argv);
 }
 ]]></ShimSourceCode>
         <ShimPdbLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'">/PDB:"%(_AggregateExecutableReferencePath.ShimSymbol)"</ShimPdbLinkerArg>

From 29306fbe889258414f6874ec64a2d446ea6c9c18 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 13:02:22 +0000
Subject: [PATCH 16/27] Match x86 aggregate shim altname pattern

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Windows.targets  | 20 +++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index f23083411d85df..21fccc96701267 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -162,15 +162,23 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <ItemGroup>
       <_AggregateExecutableReferencePath>
-        <ShimEntryPointSymbol>%(_AggregateExecutableReferencePath.EntryPointSymbol)</ShimEntryPointSymbol>
-        <ShimEntryPointSymbol Condition="'$(_targetArchitecture)' == 'x86'">$([System.String]::Copy('%(_AggregateExecutableReferencePath.EntryPointSymbol)').Substring(1))</ShimEntryPointSymbol>
-      </_AggregateExecutableReferencePath>
-      <_AggregateExecutableReferencePath>
-        <ShimSourceCode><![CDATA[__declspec(dllimport) int %(_AggregateExecutableReferencePath.ShimEntryPointSymbol)(int, unsigned short**);
+        <ShimSourceCode><![CDATA[#if defined(_M_IX86)
+#define AGGREGATE_EXE_SHIM_STRINGIFY(s) #s
+#define AGGREGATE_EXE_SHIM_ALTNAME(_method) AGGREGATE_EXE_SHIM_STRINGIFY(/alternatename:_##_method=_method)
+#define AGGREGATE_EXE_SHIM_CALLCONV __cdecl
+#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) \
+    __pragma(comment(linker, AGGREGATE_EXE_SHIM_ALTNAME(_name))) \
+    extern int AGGREGATE_EXE_SHIM_CALLCONV _name(int, unsigned short**);
+#else
+#define AGGREGATE_EXE_SHIM_CALLCONV
+#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) extern int _name(int, unsigned short**);
+#endif
+
+AGGREGATE_EXE_SHIM_ENTRYPOINT(%(_AggregateExecutableReferencePath.EntryPointSymbol))
 
 int wmain(int argc, unsigned short** argv)
 {
-    return %(_AggregateExecutableReferencePath.ShimEntryPointSymbol)(argc, argv);
+    return %(_AggregateExecutableReferencePath.EntryPointSymbol)(argc, argv);
 }
 ]]></ShimSourceCode>
         <ShimPdbLinkerArg Condition="'$(NativeDebugSymbols)' == 'true'">/PDB:"%(_AggregateExecutableReferencePath.ShimSymbol)"</ShimPdbLinkerArg>

From 0e47636a5bf87772deb06af5a492db519cf195aa Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 13:04:23 +0000
Subject: [PATCH 17/27] Simplify aggregate shim altname macro

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Windows.targets | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 21fccc96701267..7ae248b7ffc7df 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -165,12 +165,10 @@ The .NET Foundation licenses this file to you under the MIT license.
         <ShimSourceCode><![CDATA[#if defined(_M_IX86)
 #define AGGREGATE_EXE_SHIM_STRINGIFY(s) #s
 #define AGGREGATE_EXE_SHIM_ALTNAME(_method) AGGREGATE_EXE_SHIM_STRINGIFY(/alternatename:_##_method=_method)
-#define AGGREGATE_EXE_SHIM_CALLCONV __cdecl
 #define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) \
     __pragma(comment(linker, AGGREGATE_EXE_SHIM_ALTNAME(_name))) \
-    extern int AGGREGATE_EXE_SHIM_CALLCONV _name(int, unsigned short**);
+    extern int __cdecl _name(int, unsigned short**);
 #else
-#define AGGREGATE_EXE_SHIM_CALLCONV
 #define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) extern int _name(int, unsigned short**);
 #endif
 

From 10937fdd51210e736edb2e8312416fe11473146c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 27 May 2026 21:42:17 +0000
Subject: [PATCH 18/27] Simplify aggregate shim x86 pragma

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Windows.targets           | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 7ae248b7ffc7df..0caff6d7d579d3 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -163,16 +163,10 @@ The .NET Foundation licenses this file to you under the MIT license.
     <ItemGroup>
       <_AggregateExecutableReferencePath>
         <ShimSourceCode><![CDATA[#if defined(_M_IX86)
-#define AGGREGATE_EXE_SHIM_STRINGIFY(s) #s
-#define AGGREGATE_EXE_SHIM_ALTNAME(_method) AGGREGATE_EXE_SHIM_STRINGIFY(/alternatename:_##_method=_method)
-#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) \
-    __pragma(comment(linker, AGGREGATE_EXE_SHIM_ALTNAME(_name))) \
-    extern int __cdecl _name(int, unsigned short**);
-#else
-#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) extern int _name(int, unsigned short**);
+#pragma comment(linker, "/alternatename:_%(_AggregateExecutableReferencePath.EntryPointSymbol)=%(_AggregateExecutableReferencePath.EntryPointSymbol)")
 #endif
 
-AGGREGATE_EXE_SHIM_ENTRYPOINT(%(_AggregateExecutableReferencePath.EntryPointSymbol))
+extern int %(_AggregateExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
 
 int wmain(int argc, unsigned short** argv)
 {

From e5e8cddc685760d4a3056a175ece1751ead21c3c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 28 May 2026 05:46:03 +0000
Subject: [PATCH 19/27] Restore aggregate shim x86 altname macro

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../Microsoft.NETCore.Native.Windows.targets           | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 0caff6d7d579d3..7ae248b7ffc7df 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -163,10 +163,16 @@ The .NET Foundation licenses this file to you under the MIT license.
     <ItemGroup>
       <_AggregateExecutableReferencePath>
         <ShimSourceCode><![CDATA[#if defined(_M_IX86)
-#pragma comment(linker, "/alternatename:_%(_AggregateExecutableReferencePath.EntryPointSymbol)=%(_AggregateExecutableReferencePath.EntryPointSymbol)")
+#define AGGREGATE_EXE_SHIM_STRINGIFY(s) #s
+#define AGGREGATE_EXE_SHIM_ALTNAME(_method) AGGREGATE_EXE_SHIM_STRINGIFY(/alternatename:_##_method=_method)
+#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) \
+    __pragma(comment(linker, AGGREGATE_EXE_SHIM_ALTNAME(_name))) \
+    extern int __cdecl _name(int, unsigned short**);
+#else
+#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) extern int _name(int, unsigned short**);
 #endif
 
-extern int %(_AggregateExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
+AGGREGATE_EXE_SHIM_ENTRYPOINT(%(_AggregateExecutableReferencePath.EntryPointSymbol))
 
 int wmain(int argc, unsigned short** argv)
 {

From 51a2c67230df8613556a975ce0f2b88192f22830 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?=
 <MichalStrehovsky@users.noreply.github.com>
Date: Fri, 29 May 2026 12:35:00 +0900
Subject: [PATCH 20/27] One weird trick

---
 .../Microsoft.NETCore.Native.Windows.targets         | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 7ae248b7ffc7df..36f586e634fd28 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -162,17 +162,7 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <ItemGroup>
       <_AggregateExecutableReferencePath>
-        <ShimSourceCode><![CDATA[#if defined(_M_IX86)
-#define AGGREGATE_EXE_SHIM_STRINGIFY(s) #s
-#define AGGREGATE_EXE_SHIM_ALTNAME(_method) AGGREGATE_EXE_SHIM_STRINGIFY(/alternatename:_##_method=_method)
-#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) \
-    __pragma(comment(linker, AGGREGATE_EXE_SHIM_ALTNAME(_name))) \
-    extern int __cdecl _name(int, unsigned short**);
-#else
-#define AGGREGATE_EXE_SHIM_ENTRYPOINT(_name) extern int _name(int, unsigned short**);
-#endif
-
-AGGREGATE_EXE_SHIM_ENTRYPOINT(%(_AggregateExecutableReferencePath.EntryPointSymbol))
+        <ShimSourceCode><![CDATA[extern int __stdcall %(_AggregateExecutableReferencePath.EntryPointSymbol)(int, unsigned short**);
 
 int wmain(int argc, unsigned short** argv)
 {

From 6cb087660180728df4f1f202663585eb082d5e9a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?=
 <MichalStrehovsky@users.noreply.github.com>
Date: Fri, 29 May 2026 12:36:44 +0900
Subject: [PATCH 21/27] Preempt binskim reports

---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets  | 6 ++++++
 .../Microsoft.NETCore.Native.Windows.targets                | 5 +++++
 2 files changed, 11 insertions(+)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 7c4e98c6fd85d4..14573ba2217e2b 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -417,8 +417,14 @@ int main(int argc, char** argv)
       <_AggregateExecutableShimCompilerAndLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.Shim)' == 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,'$ORIGIN'" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-Wl,-rpath,@executable_path" Condition="'$(_IsApplePlatform)' == 'true'" />
+
       <!-- binskim warning BA3001 PIE disabled on executable -->
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
+      <!-- binskim error BA3003: The stack protector was not found -->
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="--stack-protector-strong" />
+      <!-- binskim error BA3031: X was compiled using Clang but without the SafeStack -->
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fsanitize=safe-stack" />
+
 
       <_AggregateExecutableShimNativeLibraryArg Include="-L&quot;$(NativeOutputPath)&quot;" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimNativeLibraryArg Include="-l:$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" Condition="'$(_IsApplePlatform)' != 'true'" />
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index 36f586e634fd28..e792b4c17f598c 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -180,6 +180,11 @@ int wmain(int argc, unsigned short** argv)
       <_AggregateExecutableShimCompilerArg Condition="'$(NativeDebugSymbols)' == 'true'" Include="/Z7" />
       <_AggregateExecutableShimCompilerArg Condition="'$(ControlFlowGuard)' == 'Guard'" Include="/guard:cf" />
 
+      <!-- binskim BA2007 X was compiled at too low a warning level -->
+      <_AggregateExecutableShimCompilerArg Include="/W4" />
+      <!-- binskim BA2026 X is a Windows PE that wasn't compiled with recommended Security Development Lifecycle (SDL) checks -->
+      <_AggregateExecutableShimCompilerArg Include="/SDL" />
+
       <_AggregateExecutableShimLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.Shim)' == 'true'" />
       <_AggregateExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
       <_AggregateExecutableShimLinkerArg Include="/STACK:$(IlcDefaultStackSize)" />

From a79724465d39f55e1b790db6bd7579e6c0483d13 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?=
 <MichalStrehovsky@users.noreply.github.com>
Date: Fri, 29 May 2026 00:16:33 -0700
Subject: [PATCH 22/27] Apply suggestions from code review
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Michal Strehovský <MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets    | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 14573ba2217e2b..ef0b9158bf6571 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -421,9 +421,9 @@ int main(int argc, char** argv)
       <!-- binskim warning BA3001 PIE disabled on executable -->
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
       <!-- binskim error BA3003: The stack protector was not found -->
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="--stack-protector-strong" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fstack-protector-strong" />
       <!-- binskim error BA3031: X was compiled using Clang but without the SafeStack -->
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fsanitize=safe-stack" />
+      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fsanitize=safe-stack" Condition="$(CppCompilerAndLinker.Contains('clang'))" />
 
 
       <_AggregateExecutableShimNativeLibraryArg Include="-L&quot;$(NativeOutputPath)&quot;" Condition="'$(_IsApplePlatform)' != 'true'" />

From c8965a489d8f59bb8abd053cad3c39dd729f21cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?=
 <MichalStrehovsky@users.noreply.github.com>
Date: Fri, 29 May 2026 03:50:19 -0700
Subject: [PATCH 23/27] Update Microsoft.NETCore.Native.Unix.targets

error : cannot open /usr/local/lib/clang/22/lib/aarch64-unknown-linux-gnu/libclang_rt.safestack.a:
---
 .../BuildIntegration/Microsoft.NETCore.Native.Unix.targets     | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index ef0b9158bf6571..8c429c993788bb 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -422,9 +422,6 @@ int main(int argc, char** argv)
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-pie -Wl,-pie" Condition="'$(_IsApplePlatform)' != 'true' and '$(StaticExecutable)' != 'true' and '$(PositionIndependentExecutable)' != 'false'" />
       <!-- binskim error BA3003: The stack protector was not found -->
       <_AggregateExecutableShimCompilerAndLinkerArg Include="-fstack-protector-strong" />
-      <!-- binskim error BA3031: X was compiled using Clang but without the SafeStack -->
-      <_AggregateExecutableShimCompilerAndLinkerArg Include="-fsanitize=safe-stack" Condition="$(CppCompilerAndLinker.Contains('clang'))" />
-
 
       <_AggregateExecutableShimNativeLibraryArg Include="-L&quot;$(NativeOutputPath)&quot;" Condition="'$(_IsApplePlatform)' != 'true'" />
       <_AggregateExecutableShimNativeLibraryArg Include="-l:$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" Condition="'$(_IsApplePlatform)' != 'true'" />

From 6323c3f43f28fa3bd54e40fd81a54ad02b6ac644 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 1 Jun 2026 02:30:04 +0000
Subject: [PATCH 24/27] Track import library as LinkNative output

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.targets      | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index 7a3efa0d1d6710..5524540385fcbe 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -373,9 +373,14 @@ The .NET Foundation licenses this file to you under the MIT license.
 
   <Target Name="LinkNative"
       Inputs="$(NativeObject);@(NativeLibrary)"
-      Outputs="$(NativeBinary)"
+      Outputs="$(_LinkNativeOutputs)"
       DependsOnTargets="$(LinkNativeDependsOn)">
 
+    <PropertyGroup>
+      <_LinkNativeOutputs>$(NativeBinary)</_LinkNativeOutputs>
+      <_LinkNativeOutputs Condition="'$(_targetOS)' == 'win' and '$(NativeLib)' == 'Shared' and '$(NativeImportLibrary)' != ''">$(NativeBinary);$(NativeImportLibrary)</_LinkNativeOutputs>
+    </PropertyGroup>
+
     <ItemGroup>
       <CustomLinkerArg Include="&quot;$(NativeObject)&quot;" />
       <CustomLinkerArg Include="-o &quot;$(NativeBinary)&quot;" Condition="'$(_targetOS)' != 'win'" />

From 5c192771023ece586117f855d02d671c73ec09e6 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 1 Jun 2026 02:47:48 +0000
Subject: [PATCH 25/27] Move LinkNative outputs property evaluation outside
 target

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../BuildIntegration/Microsoft.NETCore.Native.targets      | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index 5524540385fcbe..583970621e74ce 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -83,6 +83,8 @@ The .NET Foundation licenses this file to you under the MIT license.
     <NativeObject>$(NativeIntermediateOutputPath)$(TargetName)$(NativeObjectExt)</NativeObject>
     <NativeBinary>$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</NativeBinary>
     <NativeImportLibrary Condition="'$(NativeImportLibrary)' == '' and '$(_targetOS)' == 'win' and '$(NativeLib)' == 'Shared'">$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(LibFileExt)</NativeImportLibrary>
+    <_LinkNativeOutputs>$(NativeBinary)</_LinkNativeOutputs>
+    <_LinkNativeOutputs Condition="'$(_targetOS)' == 'win' and '$(NativeLib)' == 'Shared' and '$(NativeImportLibrary)' != ''">$(NativeBinary);$(NativeImportLibrary)</_LinkNativeOutputs>
     <NativeExecutableExt Condition="'$(NativeExecutableExt)' == '' and '$(_targetOS)' == 'win'">.exe</NativeExecutableExt>
     <NativeExecutableExt Condition="'$(NativeExecutableExt)' == ''"></NativeExecutableExt>
     <IlcExportUnmanagedEntrypoints Condition="'$(IlcExportUnmanagedEntrypoints)' == '' and '$(NativeLib)' == 'Shared'">true</IlcExportUnmanagedEntrypoints>
@@ -376,11 +378,6 @@ The .NET Foundation licenses this file to you under the MIT license.
       Outputs="$(_LinkNativeOutputs)"
       DependsOnTargets="$(LinkNativeDependsOn)">
 
-    <PropertyGroup>
-      <_LinkNativeOutputs>$(NativeBinary)</_LinkNativeOutputs>
-      <_LinkNativeOutputs Condition="'$(_targetOS)' == 'win' and '$(NativeLib)' == 'Shared' and '$(NativeImportLibrary)' != ''">$(NativeBinary);$(NativeImportLibrary)</_LinkNativeOutputs>
-    </PropertyGroup>
-
     <ItemGroup>
       <CustomLinkerArg Include="&quot;$(NativeObject)&quot;" />
       <CustomLinkerArg Include="-o &quot;$(NativeBinary)&quot;" Condition="'$(_targetOS)' != 'win'" />

From 197e36d279e11a2b8421c645cdd9eb21291e56c3 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 1 Jun 2026 07:35:52 +0000
Subject: [PATCH 26/27] Require preview features for aggregate executable mode

Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
---
 .../nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets  | 1 +
 .../nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj | 1 +
 2 files changed, 2 insertions(+)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
index 583970621e74ce..ce0f7292f4c76d 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
@@ -210,6 +210,7 @@ The .NET Foundation licenses this file to you under the MIT license.
 
     <Error Condition="'@(_AggregateExecutableReferencePath)' != '' and '$(OutputType)' != 'Library'" Text="IncludeInAggregateExecutable requires OutputType=Library." />
     <Error Condition="'@(_AggregateExecutableReferencePath)' != '' and '$(NativeLib)' != 'Shared'" Text="IncludeInAggregateExecutable requires NativeLib=Shared." />
+    <Error Condition="'@(_AggregateExecutableReferencePath)' != '' and '$(EnablePreviewFeatures)' != 'true'" Text="IncludeInAggregateExecutable requires EnablePreviewFeatures=true." />
   </Target>
 
   <!--
diff --git a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
index 8fed09b471616a..730c7c1181824d 100644
--- a/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
+++ b/src/tests/nativeaot/AggregateExecutableLibrary/AggregateLibrary.csproj
@@ -15,6 +15,7 @@
     <CLRTestRunFile Condition="'$(TargetsWindows)' == 'true'">native/ValidatorExe.exe</CLRTestRunFile>
     <CLRTestRunFile Condition="'$(TargetsWindows)' != 'true'">./native/ValidatorExe</CLRTestRunFile>
     <SkipInferOutputType>true</SkipInferOutputType>
+    <EnablePreviewFeatures>true</EnablePreviewFeatures>
     <!-- warning CS2008: No source files specified -->
     <NoWarn>$(NoWarn);CS2008</NoWarn>
   </PropertyGroup>

From 64894f5ed0ffd20652aa64482b3206e504a4eacf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?=
 <MichalStrehovsky@users.noreply.github.com>
Date: Tue, 2 Jun 2026 18:29:10 +0900
Subject: [PATCH 27/27] Copilot why you don't apply this! Switch is case
 sensitive.

---
 .../BuildIntegration/Microsoft.NETCore.Native.Windows.targets   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
index e792b4c17f598c..e7cea22fcf0442 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
@@ -183,7 +183,7 @@ int wmain(int argc, unsigned short** argv)
       <!-- binskim BA2007 X was compiled at too low a warning level -->
       <_AggregateExecutableShimCompilerArg Include="/W4" />
       <!-- binskim BA2026 X is a Windows PE that wasn't compiled with recommended Security Development Lifecycle (SDL) checks -->
-      <_AggregateExecutableShimCompilerArg Include="/SDL" />
+      <_AggregateExecutableShimCompilerArg Include="/sdl" />
 
       <_AggregateExecutableShimLinkerArg Include="@(LinkerArg)" Condition="'%(LinkerArg.Shim)' == 'true'" />
       <_AggregateExecutableShimLinkerArg Include="/ENTRY:wmainCRTStartup" />
