Skip to content

Commit

Permalink
Fix compiling EXE modules as native libraries (#78949)
Browse files Browse the repository at this point in the history
When `--nativelib` is used together with a module that defines an entrypoint, we would incorrectly run some of the logic meant for EXEs. This is failure is only reachable when one constructs inputs to `ilc.exe` manually. The SDK doesn't allow constructing such inputs.
  • Loading branch information
MichalStrehovsky authored Nov 30, 2022
1 parent 0be32a0 commit 1076cf5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/coreclr/tools/aot/ILCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,6 @@ public int Run()
compilationRoots.Add(new ExportedMethodsRootProvider(module));
}

string[] runtimeOptions = Get(_command.RuntimeOptions);
if (entrypointModule != null)
{
compilationRoots.Add(new MainMethodRootProvider(entrypointModule, CreateInitializerList(typeSystemContext)));
compilationRoots.Add(new RuntimeConfigurationRootProvider(runtimeOptions));
compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
}

bool nativeLib = Get(_command.NativeLib);
if (multiFile)
{
Expand Down Expand Up @@ -219,6 +211,7 @@ public int Run()
compilationGroup = new SingleFileCompilationModuleGroup();
}

string[] runtimeOptions = Get(_command.RuntimeOptions);
if (nativeLib)
{
// Set owning module of generated native library startup method to compiler generated module,
Expand All @@ -227,6 +220,12 @@ public int Run()
compilationRoots.Add(new RuntimeConfigurationRootProvider(runtimeOptions));
compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
}
else if (entrypointModule != null)
{
compilationRoots.Add(new MainMethodRootProvider(entrypointModule, CreateInitializerList(typeSystemContext)));
compilationRoots.Add(new RuntimeConfigurationRootProvider(runtimeOptions));
compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
}

foreach (var rdXmlFilePath in Get(_command.RdXmlFilePaths))
{
Expand Down

0 comments on commit 1076cf5

Please sign in to comment.