Skip to content

Commit 4e4b27f

Browse files
Integration of changes in shared files from runtimelab/NativeAOT (#61655)
1 parent 468a495 commit 4e4b27f

File tree

12 files changed

+180
-41
lines changed

12 files changed

+180
-41
lines changed

src/coreclr/gc/gcload.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,12 @@ GC_Initialize(
7878
// various components may want to query the current configuration.
7979
GCConfig::Initialize();
8080

81+
#ifndef FEATURE_REDHAWK // GCToOSInterface is initialized directly
8182
if (!GCToOSInterface::Initialize())
8283
{
8384
return E_FAIL;
8485
}
86+
#endif
8587

8688
IGCHandleManager* handleManager = CreateGCHandleManager();
8789
if (handleManager == nullptr)

src/coreclr/jit/importer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20902,6 +20902,14 @@ void Compiler::impMarkInlineCandidateHelper(GenTreeCall* call,
2090220902
return;
2090320903
}
2090420904

20905+
// Delegate Invoke method doesn't have a body and gets special cased instead.
20906+
// Don't even bother trying to inline it.
20907+
if (call->IsDelegateInvoke())
20908+
{
20909+
inlineResult.NoteFatal(InlineObservation::CALLEE_HAS_NO_BODY);
20910+
return;
20911+
}
20912+
2090520913
// Tail recursion elimination takes precedence over inlining.
2090620914
// TODO: We may want to do some of the additional checks from fgMorphCall
2090720915
// here to reduce the chance we don't inline a call that won't be optimized

src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,12 @@ private EcmaModule AddModule(string filePath, string expectedSimpleName, bool us
193193
if (oldModuleData == null)
194194
{
195195
peReader = OpenPEFile(filePath, out mappedViewAccessor);
196+
197+
#if !READYTORUN
198+
if (peReader.HasMetadata && (peReader.PEHeaders.CorHeader.Flags & (CorFlags.ILLibrary | CorFlags.ILOnly)) == 0)
199+
throw new NotSupportedException($"Error: C++/CLI is not supported: '{filePath}'");
200+
#endif
201+
196202
pdbReader = PortablePdbSymbolReader.TryOpenEmbedded(peReader, GetMetadataStringDecoder()) ?? OpenAssociatedSymbolFile(filePath, peReader);
197203
}
198204
else

src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_X64/X64Emitter.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ public void EmitRETIfEqual()
174174
Builder.EmitByte(0xC3);
175175
}
176176

177+
public void EmitCompareToZero(Register reg)
178+
{
179+
AddrMode rexAddrMode = new AddrMode(Register.RegDirect | reg, null, 0, 0, AddrModeSize.Int64);
180+
EmitIndirInstructionSize(0x84, reg, ref rexAddrMode);
181+
}
182+
177183
public void EmitZeroReg(Register reg)
178184
{
179185
// High 32 bits get cleared automatically when using 32bit registers

src/coreclr/tools/Common/Compiler/DevirtualizationManager.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,5 +201,16 @@ protected virtual MethodDesc ResolveVirtualMethod(MethodDesc declMethod, DefType
201201

202202
return impl;
203203
}
204+
205+
#if !READYTORUN
206+
/// <summary>
207+
/// Gets a value indicating whether it might be possible to obtain a constructed type data structure for the given type.
208+
/// </summary>
209+
/// <remarks>
210+
/// This is a bit of a hack, but devirtualization manager has a global view of all allocated types
211+
/// so it can answer this question.
212+
/// </remarks>
213+
public virtual bool CanConstructType(TypeDesc type) => true;
214+
#endif
204215
}
205216
}

src/coreclr/tools/Common/Compiler/DisplayNameHelpers.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
using System;
45
using System.Text;
56

67
using Internal.TypeSystem;
@@ -11,6 +12,21 @@ namespace ILCompiler
1112
{
1213
internal static class DisplayNameHelpers
1314
{
15+
public static string GetDisplayName(this TypeSystemEntity entity)
16+
{
17+
return entity switch
18+
{
19+
MethodDesc method => method.GetDisplayName(),
20+
FieldDesc field => field.GetDisplayName(),
21+
TypeDesc type => type.GetDisplayName(),
22+
#if !READYTORUN
23+
PropertyPseudoDesc property => property.GetDisplayName(),
24+
EventPseudoDesc @event => @event.GetDisplayName(),
25+
#endif
26+
_ => throw new InvalidOperationException(),
27+
};
28+
}
29+
1430
public static string GetDisplayName(this MethodDesc method)
1531
{
1632
var sb = new StringBuilder();

src/coreclr/tools/Common/Compiler/Logger.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,23 @@ public void LogWarning(string text, int code, string origin, string subcategory
9494

9595
internal bool IsWarningSuppressed(int code, MessageOrigin origin)
9696
{
97+
// This is causing too much noise
98+
// https://github.com/dotnet/runtimelab/issues/1591
99+
if (code == 2110 || code == 2111 || code == 2113 || code == 2115)
100+
return true;
101+
97102
if (_suppressedWarnings.Contains(code))
98103
return true;
99104

100105
IEnumerable<CustomAttributeValue<TypeDesc>> suppressions = null;
101106

102107
// TODO: Suppressions with different scopes
103-
108+
109+
if (origin.MemberDefinition is TypeDesc type)
110+
{
111+
var ecmaType = type.GetTypeDefinition() as EcmaType;
112+
suppressions = ecmaType?.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "UnconditionalSuppressMessageAttribute");
113+
}
104114

105115
if (origin.MemberDefinition is MethodDesc method)
106116
{

src/coreclr/tools/Common/Compiler/Logging/ReferenceSource/MessageContainer.cs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Reflection;
78
using System.Text;
89
using Mono.Cecil;
@@ -40,7 +41,7 @@ namespace Mono.Linker
4041
/// Create an error message.
4142
/// </summary>
4243
/// <param name="text">Humanly readable message describing the error</param>
43-
/// <param name="code">Unique error ID. Please see https://github.com/mono/linker/blob/main/docs/error-codes.md
44+
/// <param name="code">Unique error ID. Please see https://github.com/dotnet/linker/blob/main/docs/error-codes.md
4445
/// for the list of errors and possibly add a new one</param>
4546
/// <param name="subcategory">Optionally, further categorize this error</param>
4647
/// <param name="origin">Filename, line, and column where the error was found</param>
@@ -80,7 +81,7 @@ public static MessageContainer CreateCustomErrorMessage (string text, int code,
8081
/// </summary>
8182
/// <param name="context">Context with the relevant warning suppression info.</param>
8283
/// <param name="text">Humanly readable message describing the warning</param>
83-
/// <param name="code">Unique warning ID. Please see https://github.com/mono/linker/blob/main/docs/error-codes.md
84+
/// <param name="code">Unique warning ID. Please see https://github.com/dotnet/linker/blob/main/docs/error-codes.md
8485
/// for the list of warnings and possibly add a new one</param>
8586
/// /// <param name="origin">Filename or member where the warning is coming from</param>
8687
/// <param name="subcategory">Optionally, further categorize this warning</param>
@@ -140,14 +141,31 @@ private static MessageContainer CreateWarningMessageContainer (LinkContext conte
140141
return new MessageContainer (MessageCategory.Warning, text, code, subcategory, origin);
141142
}
142143

144+
public bool IsWarningMessage ([NotNullWhen (true)] out int? code)
145+
{
146+
code = null;
147+
148+
if (Category is MessageCategory.Warning or MessageCategory.WarningAsError) {
149+
// Warning messages always have a code.
150+
code = Code!;
151+
return true;
152+
}
153+
154+
return false;
155+
}
156+
143157
static bool TryLogSingleWarning (LinkContext context, int code, MessageOrigin origin, string subcategory)
144158
{
145159
if (subcategory != MessageSubCategory.TrimAnalysis)
146160
return false;
147161

148-
Debug.Assert (origin.MemberDefinition != null);
149-
var declaringType = origin.MemberDefinition?.DeclaringType ?? (origin.MemberDefinition as TypeDefinition);
150-
var assembly = declaringType.Module.Assembly;
162+
Debug.Assert (origin.Provider != null);
163+
var assembly = origin.Provider switch {
164+
AssemblyDefinition asm => asm,
165+
TypeDefinition type => type.Module.Assembly,
166+
IMemberDefinition member => member.DeclaringType.Module.Assembly,
167+
_ => throw new NotSupportedException ()
168+
};
151169

152170
Debug.Assert (assembly != null);
153171
if (assembly == null)
@@ -228,17 +246,22 @@ public string ToMSBuildString ()
228246
sb.Append (" ")
229247
.Append (cat)
230248
.Append (" IL")
231-
.Append (Code.Value.ToString ("D4"))
249+
// Warning and error messages always have a code.
250+
.Append (Code!.Value.ToString ("D4"))
232251
.Append (": ");
233252
} else {
234253
sb.Append (" ");
235254
}
236255

237-
if (Origin?.MemberDefinition != null) {
238-
if (Origin?.MemberDefinition is MethodDefinition method)
256+
if (Origin?.Provider != null) {
257+
if (Origin?.Provider is MethodDefinition method)
239258
sb.Append (method.GetDisplayName ());
259+
else if (Origin?.Provider is IMemberDefinition member)
260+
sb.Append (member.FullName);
261+
else if (Origin?.Provider is AssemblyDefinition assembly)
262+
sb.Append (assembly.Name.Name);
240263
else
241-
sb.Append (Origin?.MemberDefinition.FullName);
264+
throw new NotSupportedException ();
242265

243266
sb.Append (": ");
244267
}

src/coreclr/tools/Common/Compiler/Logging/ReferenceSource/MessageOrigin.cs

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using System.Diagnostics;
56
using System.Linq;
67
using System.Text;
78
using Mono.Cecil;
@@ -13,19 +14,28 @@ namespace Mono.Linker
1314
{
1415
#nullable enable
1516
public string? FileName { get; }
16-
public IMemberDefinition? MemberDefinition { get; }
17-
18-
readonly IMemberDefinition _suppressionContextMember;
19-
public IMemberDefinition? SuppressionContextMember { get => _suppressionContextMember ?? MemberDefinition; }
17+
public ICustomAttributeProvider? Provider { get; }
18+
readonly ICustomAttributeProvider _suppressionContextMember;
19+
public ICustomAttributeProvider? SuppressionContextMember {
20+
get {
21+
Debug.Assert (_suppressionContextMember == null || _suppressionContextMember is IMemberDefinition || _suppressionContextMember is AssemblyDefinition);
22+
return _suppressionContextMember ?? Provider;
23+
}
24+
}
2025
#nullable disable
2126
public int SourceLine { get; }
2227
public int SourceColumn { get; }
2328
public int? ILOffset { get; }
2429

2530
const int HiddenLineNumber = 0xfeefee;
2631

27-
public MessageOrigin (IMemberDefinition memberDefinition)
28-
: this (memberDefinition, null)
32+
public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset = null)
33+
: this (memberDefinition as ICustomAttributeProvider, ilOffset)
34+
{
35+
}
36+
37+
public MessageOrigin (ICustomAttributeProvider provider)
38+
: this (provider, null)
2939
{
3040
}
3141

@@ -34,31 +44,43 @@ public MessageOrigin (string fileName, int sourceLine = 0, int sourceColumn = 0)
3444
FileName = fileName;
3545
SourceLine = sourceLine;
3646
SourceColumn = sourceColumn;
37-
MemberDefinition = null;
47+
Provider = null;
3848
_suppressionContextMember = null;
3949
ILOffset = null;
4050
}
4151

42-
public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset)
43-
: this (memberDefinition, ilOffset, null)
52+
public MessageOrigin (ICustomAttributeProvider provider, int? ilOffset)
53+
: this (provider, ilOffset, null)
4454
{
4555
}
4656

47-
public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset, IMemberDefinition suppressionContextMember)
57+
public MessageOrigin (ICustomAttributeProvider provider, int? ilOffset, ICustomAttributeProvider suppressionContextMember)
4858
{
59+
Debug.Assert (provider == null || provider is IMemberDefinition || provider is AssemblyDefinition);
60+
Debug.Assert (suppressionContextMember == null || suppressionContextMember is IMemberDefinition || provider is AssemblyDefinition);
4961
FileName = null;
50-
MemberDefinition = memberDefinition;
62+
Provider = provider;
5163
_suppressionContextMember = suppressionContextMember;
5264
SourceLine = 0;
5365
SourceColumn = 0;
5466
ILOffset = ilOffset;
5567
}
5668

69+
public MessageOrigin (MessageOrigin other, IMemberDefinition suppressionContextMember)
70+
{
71+
FileName = other.FileName;
72+
Provider = other.Provider;
73+
_suppressionContextMember = suppressionContextMember;
74+
SourceLine = other.SourceLine;
75+
SourceColumn = other.SourceColumn;
76+
ILOffset = other.ILOffset;
77+
}
78+
5779
public override string ToString ()
5880
{
5981
int sourceLine = SourceLine, sourceColumn = SourceColumn;
6082
string fileName = FileName;
61-
if (MemberDefinition is MethodDefinition method &&
83+
if (Provider is MethodDefinition method &&
6284
method.DebugInformation.HasSequencePoints) {
6385
var offset = ILOffset ?? 0;
6486
SequencePoint correspondingSequencePoint = method.DebugInformation.SequencePoints
@@ -94,28 +116,32 @@ public override string ToString ()
94116
}
95117

96118
public bool Equals (MessageOrigin other) =>
97-
(FileName, MemberDefinition, SourceLine, SourceColumn, ILOffset) == (other.FileName, other.MemberDefinition, other.SourceLine, other.SourceColumn, other.ILOffset);
119+
(FileName, Provider, SourceLine, SourceColumn, ILOffset) == (other.FileName, other.Provider, other.SourceLine, other.SourceColumn, other.ILOffset);
98120

99121
public override bool Equals (object obj) => obj is MessageOrigin messageOrigin && Equals (messageOrigin);
100-
public override int GetHashCode () => (FileName, MemberDefinition, SourceLine, SourceColumn).GetHashCode ();
122+
public override int GetHashCode () => (FileName, Provider, SourceLine, SourceColumn).GetHashCode ();
101123
public static bool operator == (MessageOrigin lhs, MessageOrigin rhs) => lhs.Equals (rhs);
102124
public static bool operator != (MessageOrigin lhs, MessageOrigin rhs) => !lhs.Equals (rhs);
103125

104126
public int CompareTo (MessageOrigin other)
105127
{
106-
if (MemberDefinition != null && other.MemberDefinition != null) {
107-
TypeDefinition thisTypeDef = (MemberDefinition as TypeDefinition) ?? MemberDefinition.DeclaringType;
108-
TypeDefinition otherTypeDef = (other.MemberDefinition as TypeDefinition) ?? other.MemberDefinition.DeclaringType;
109-
int result = (thisTypeDef?.Module?.Assembly?.Name?.Name, thisTypeDef?.Name, MemberDefinition?.Name).CompareTo
110-
((otherTypeDef?.Module?.Assembly?.Name?.Name, otherTypeDef?.Name, other.MemberDefinition?.Name));
128+
if (Provider != null && other.Provider != null) {
129+
var thisMember = Provider as IMemberDefinition;
130+
var otherMember = other.Provider as IMemberDefinition;
131+
TypeDefinition thisTypeDef = (Provider as TypeDefinition) ?? (Provider as IMemberDefinition)?.DeclaringType;
132+
TypeDefinition otherTypeDef = (other.Provider as TypeDefinition) ?? (other.Provider as IMemberDefinition)?.DeclaringType;
133+
var thisAssembly = thisTypeDef?.Module.Assembly ?? Provider as AssemblyDefinition;
134+
var otherAssembly = otherTypeDef?.Module.Assembly ?? other.Provider as AssemblyDefinition;
135+
int result = (thisAssembly.Name.Name, thisTypeDef?.Name, thisMember?.Name).CompareTo
136+
((otherAssembly.Name.Name, otherTypeDef?.Name, otherMember?.Name));
111137
if (result != 0)
112138
return result;
113139

114140
if (ILOffset != null && other.ILOffset != null)
115141
return ILOffset.Value.CompareTo (other.ILOffset);
116142

117143
return ILOffset == null ? (other.ILOffset == null ? 0 : 1) : -1;
118-
} else if (MemberDefinition == null && other.MemberDefinition == null) {
144+
} else if (Provider == null && other.Provider == null) {
119145
if (FileName != null && other.FileName != null) {
120146
return string.Compare (FileName, other.FileName);
121147
} else if (FileName == null && other.FileName == null) {
@@ -125,7 +151,7 @@ public int CompareTo (MessageOrigin other)
125151
return (FileName == null) ? 1 : -1;
126152
}
127153

128-
return (MemberDefinition == null) ? 1 : -1;
154+
return (Provider == null) ? 1 : -1;
129155
}
130156
}
131157
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Sources from the mono/linker repo at commit 012efef292663aa38f9047896942cdcc8765b8e0.
1+
Sources from the dotnet/linker repo at commit c0567db0b9088e2ad4144cd0fe2a985611ec28f0.

src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public enum ReadyToRunSectionType
8484
ThreadStaticIndex = 210,
8585
LoopHijackFlag = 211,
8686
ImportAddressTables = 212,
87+
ModuleInitializerList = 213,
8788

8889
// Sections 300 - 399 are reserved for RhFindBlob backwards compatibility
8990
ReadonlyBlobRegionStart = 300,

0 commit comments

Comments
 (0)