Skip to content

Commit 1076cf5

Browse files
Fix compiling EXE modules as native libraries (#78949)
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.
1 parent 0be32a0 commit 1076cf5

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/coreclr/tools/aot/ILCompiler/Program.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,6 @@ public int Run()
182182
compilationRoots.Add(new ExportedMethodsRootProvider(module));
183183
}
184184

185-
string[] runtimeOptions = Get(_command.RuntimeOptions);
186-
if (entrypointModule != null)
187-
{
188-
compilationRoots.Add(new MainMethodRootProvider(entrypointModule, CreateInitializerList(typeSystemContext)));
189-
compilationRoots.Add(new RuntimeConfigurationRootProvider(runtimeOptions));
190-
compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
191-
}
192-
193185
bool nativeLib = Get(_command.NativeLib);
194186
if (multiFile)
195187
{
@@ -219,6 +211,7 @@ public int Run()
219211
compilationGroup = new SingleFileCompilationModuleGroup();
220212
}
221213

214+
string[] runtimeOptions = Get(_command.RuntimeOptions);
222215
if (nativeLib)
223216
{
224217
// Set owning module of generated native library startup method to compiler generated module,
@@ -227,6 +220,12 @@ public int Run()
227220
compilationRoots.Add(new RuntimeConfigurationRootProvider(runtimeOptions));
228221
compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
229222
}
223+
else if (entrypointModule != null)
224+
{
225+
compilationRoots.Add(new MainMethodRootProvider(entrypointModule, CreateInitializerList(typeSystemContext)));
226+
compilationRoots.Add(new RuntimeConfigurationRootProvider(runtimeOptions));
227+
compilationRoots.Add(new ExpectedIsaFeaturesRootProvider(instructionSetSupport));
228+
}
230229

231230
foreach (var rdXmlFilePath in Get(_command.RdXmlFilePaths))
232231
{

0 commit comments

Comments
 (0)