From 71c07e15773082291b9ee856d8b97d99e61c943b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 7 Jun 2023 16:17:56 +0900 Subject: [PATCH 1/2] Fix reading runtime settings early in startup * Since runtime settings are read before we had a chance to run dehydration, they cannot go to the dehydrated section. This is a 48-byte penalty per setting on Linux. Hopefully we won't have too many of these. * Fix the repro project to enable dehydration. When testing the original change, I used repro project where this worked because of no dehydration. We should mirror the shipping configuration. * Add a regression test. Picked a random test as a "victim" so that we don't unnecessarily regress testing time. --- .../Compiler/RuntimeConfigurationRootProvider.cs | 6 +++--- src/coreclr/tools/aot/ILCompiler/repro/repro.csproj | 1 + src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs | 4 ++++ src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.csproj | 1 + 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs index 9f44f802f3d22b..1bf7670fa0cde2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs @@ -30,7 +30,7 @@ void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootPr rootProvider.AddCompilationRoot(new RuntimeConfigurationBlobNode(_blobName, _runtimeOptions), "Runtime configuration"); } - private sealed class RuntimeConfigurationBlobNode : DehydratableObjectNode, ISymbolDefinitionNode + private sealed class RuntimeConfigurationBlobNode : ObjectNode, ISymbolDefinitionNode { private readonly string _blobName; private readonly IReadOnlyCollection _runtimeOptions; @@ -54,11 +54,11 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) sb.Append(_blobName); } - protected override ObjectNodeSection GetDehydratedSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection; + public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection; protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler); - protected override ObjectData GetDehydratableData(NodeFactory factory, bool relocsOnly = false) + public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { var builder = new ObjectDataBuilder(factory.TypeSystemContext.Target, relocsOnly); builder.AddSymbol(this); diff --git a/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj b/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj index 26c34d3c5d4283..131ddbd3b22576 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj +++ b/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj @@ -23,6 +23,7 @@ + diff --git a/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs b/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs index 3bf0f6de7ced62..55028fdee9adb9 100644 --- a/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs +++ b/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.cs @@ -25,6 +25,10 @@ public BringUpTest() public static int Main() { + // This test also doubles as server GC test + if (!System.Runtime.GCSettings.IsServerGC) + return 42; + if (string.Empty.Length > 0) { // Just something to make sure we generate reflection metadata for the type diff --git a/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.csproj b/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.csproj index 0b1a23bf56a1c8..fe80571c3550f2 100644 --- a/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.csproj +++ b/src/tests/nativeaot/SmokeTests/Exceptions/Exceptions.csproj @@ -4,6 +4,7 @@ BuildAndRun 0 true + true From 62021cdc3062e2a39c54a5793566b8fd18ab0995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 7 Jun 2023 16:51:07 +0900 Subject: [PATCH 2/2] Maybe fix Linux? ``` ld.lld(0,0): error : relocation R_X86_64_64 cannot be used against symbol 'g_compilerEmbeddedKnobsBlob_key_3'; recompile with -fPIC [/__w/1/s/src/tests/nativeaot/CustomMain/CustomMain.csproj] ``` --- .../Compiler/RuntimeConfigurationRootProvider.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs index 1bf7670fa0cde2..de64f9eb277ce2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/RuntimeConfigurationRootProvider.cs @@ -54,7 +54,8 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) sb.Append(_blobName); } - public override ObjectNodeSection GetSection(NodeFactory factory) => ObjectNodeSection.ReadOnlyDataSection; + public override ObjectNodeSection GetSection(NodeFactory factory) => + factory.Target.IsWindows ? ObjectNodeSection.ReadOnlyDataSection : ObjectNodeSection.DataSection; protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);