Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration of changes in shared files from runtimelab/NativeAOT #61655

Merged
merged 8 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/coreclr/gc/gcload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ GC_Initialize(
// various components may want to query the current configuration.
GCConfig::Initialize();

#ifndef FEATURE_REDHAWK // GCToOSInterface is initialized directly
if (!GCToOSInterface::Initialize())
{
return E_FAIL;
}
#endif

IGCHandleManager* handleManager = CreateGCHandleManager();
if (handleManager == nullptr)
Expand Down
8 changes: 8 additions & 0 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20884,6 +20884,14 @@ void Compiler::impMarkInlineCandidateHelper(GenTreeCall* call,
return;
}

// Delegate Invoke method doesn't have a body and gets special cased instead.
// Don't even bother trying to inline it.
if (call->IsDelegateInvoke())
{
inlineResult.NoteFatal(InlineObservation::CALLEE_HAS_NO_BODY);
return;
}

// Tail recursion elimination takes precedence over inlining.
// TODO: We may want to do some of the additional checks from fgMorphCall
// here to reduce the chance we don't inline a call that won't be optimized
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ private EcmaModule AddModule(string filePath, string expectedSimpleName, bool us
if (oldModuleData == null)
{
peReader = OpenPEFile(filePath, out mappedViewAccessor);

#if !READYTORUN
if (peReader.HasMetadata && (peReader.PEHeaders.CorHeader.Flags & (CorFlags.ILLibrary | CorFlags.ILOnly)) == 0)
throw new NotSupportedException($"Error: C++/CLI is not supported: '{filePath}'");
#endif

pdbReader = PortablePdbSymbolReader.TryOpenEmbedded(peReader, GetMetadataStringDecoder()) ?? OpenAssociatedSymbolFile(filePath, peReader);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ public void EmitRETIfEqual()
Builder.EmitByte(0xC3);
}

public void EmitCompareToZero(Register reg)
{
AddrMode rexAddrMode = new AddrMode(Register.RegDirect | reg, null, 0, 0, AddrModeSize.Int64);
EmitIndirInstructionSize(0x84, reg, ref rexAddrMode);
}

public void EmitZeroReg(Register reg)
{
// High 32 bits get cleared automatically when using 32bit registers
Expand Down
11 changes: 11 additions & 0 deletions src/coreclr/tools/Common/Compiler/DevirtualizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,5 +201,16 @@ protected virtual MethodDesc ResolveVirtualMethod(MethodDesc declMethod, DefType

return impl;
}

#if !READYTORUN
/// <summary>
/// Gets a value indicating whether it might be possible to obtain a constructed type data structure for the given type.
/// </summary>
/// <remarks>
/// This is a bit of a hack, but devirtualization manager has a global view of all allocated types
/// so it can answer this question.
/// </remarks>
public virtual bool CanConstructType(TypeDesc type) => true;
#endif
}
}
16 changes: 16 additions & 0 deletions src/coreclr/tools/Common/Compiler/DisplayNameHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// 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.Text;

using Internal.TypeSystem;
Expand All @@ -11,6 +12,21 @@ namespace ILCompiler
{
internal static class DisplayNameHelpers
{
public static string GetDisplayName(this TypeSystemEntity entity)
{
return entity switch
{
MethodDesc method => method.GetDisplayName(),
FieldDesc field => field.GetDisplayName(),
TypeDesc type => type.GetDisplayName(),
#if !READYTORUN
PropertyPseudoDesc property => property.GetDisplayName(),
EventPseudoDesc @event => @event.GetDisplayName(),
MichalStrehovsky marked this conversation as resolved.
Show resolved Hide resolved
#endif
_ => throw new InvalidOperationException(),
};
}

public static string GetDisplayName(this MethodDesc method)
{
var sb = new StringBuilder();
Expand Down
12 changes: 11 additions & 1 deletion src/coreclr/tools/Common/Compiler/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,23 @@ public void LogWarning(string text, int code, string origin, string subcategory

internal bool IsWarningSuppressed(int code, MessageOrigin origin)
{
// This is causing too much noise
// https://github.com/dotnet/runtimelab/issues/1591
if (code == 2110 || code == 2111 || code == 2113 || code == 2115)
return true;

if (_suppressedWarnings.Contains(code))
return true;

IEnumerable<CustomAttributeValue<TypeDesc>> suppressions = null;

// TODO: Suppressions with different scopes


if (origin.MemberDefinition is TypeDesc type)
{
var ecmaType = type.GetTypeDefinition() as EcmaType;
suppressions = ecmaType?.GetDecodedCustomAttributes("System.Diagnostics.CodeAnalysis", "UnconditionalSuppressMessageAttribute");
}

if (origin.MemberDefinition is MethodDesc method)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// 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.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text;
using Mono.Cecil;
Expand Down Expand Up @@ -40,7 +41,7 @@ namespace Mono.Linker
/// Create an error message.
/// </summary>
/// <param name="text">Humanly readable message describing the error</param>
/// <param name="code">Unique error ID. Please see https://github.com/mono/linker/blob/main/docs/error-codes.md
/// <param name="code">Unique error ID. Please see https://github.com/dotnet/linker/blob/main/docs/error-codes.md
/// for the list of errors and possibly add a new one</param>
/// <param name="subcategory">Optionally, further categorize this error</param>
/// <param name="origin">Filename, line, and column where the error was found</param>
Expand Down Expand Up @@ -80,7 +81,7 @@ public static MessageContainer CreateCustomErrorMessage (string text, int code,
/// </summary>
/// <param name="context">Context with the relevant warning suppression info.</param>
/// <param name="text">Humanly readable message describing the warning</param>
/// <param name="code">Unique warning ID. Please see https://github.com/mono/linker/blob/main/docs/error-codes.md
/// <param name="code">Unique warning ID. Please see https://github.com/dotnet/linker/blob/main/docs/error-codes.md
/// for the list of warnings and possibly add a new one</param>
/// /// <param name="origin">Filename or member where the warning is coming from</param>
/// <param name="subcategory">Optionally, further categorize this warning</param>
Expand Down Expand Up @@ -140,14 +141,31 @@ private static MessageContainer CreateWarningMessageContainer (LinkContext conte
return new MessageContainer (MessageCategory.Warning, text, code, subcategory, origin);
}

public bool IsWarningMessage ([NotNullWhen (true)] out int? code)
{
code = null;

if (Category is MessageCategory.Warning or MessageCategory.WarningAsError) {
// Warning messages always have a code.
code = Code!;
return true;
}

return false;
}

static bool TryLogSingleWarning (LinkContext context, int code, MessageOrigin origin, string subcategory)
{
if (subcategory != MessageSubCategory.TrimAnalysis)
return false;

Debug.Assert (origin.MemberDefinition != null);
var declaringType = origin.MemberDefinition?.DeclaringType ?? (origin.MemberDefinition as TypeDefinition);
var assembly = declaringType.Module.Assembly;
Debug.Assert (origin.Provider != null);
var assembly = origin.Provider switch {
AssemblyDefinition asm => asm,
TypeDefinition type => type.Module.Assembly,
IMemberDefinition member => member.DeclaringType.Module.Assembly,
_ => throw new NotSupportedException ()
};

Debug.Assert (assembly != null);
if (assembly == null)
Expand Down Expand Up @@ -228,17 +246,22 @@ public string ToMSBuildString ()
sb.Append (" ")
.Append (cat)
.Append (" IL")
.Append (Code.Value.ToString ("D4"))
// Warning and error messages always have a code.
.Append (Code!.Value.ToString ("D4"))
.Append (": ");
} else {
sb.Append (" ");
}

if (Origin?.MemberDefinition != null) {
if (Origin?.MemberDefinition is MethodDefinition method)
if (Origin?.Provider != null) {
if (Origin?.Provider is MethodDefinition method)
sb.Append (method.GetDisplayName ());
else if (Origin?.Provider is IMemberDefinition member)
sb.Append (member.FullName);
else if (Origin?.Provider is AssemblyDefinition assembly)
sb.Append (assembly.Name.Name);
else
sb.Append (Origin?.MemberDefinition.FullName);
throw new NotSupportedException ();

sb.Append (": ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Mono.Cecil;
Expand All @@ -13,19 +14,28 @@ namespace Mono.Linker
{
#nullable enable
public string? FileName { get; }
public IMemberDefinition? MemberDefinition { get; }

readonly IMemberDefinition _suppressionContextMember;
public IMemberDefinition? SuppressionContextMember { get => _suppressionContextMember ?? MemberDefinition; }
public ICustomAttributeProvider? Provider { get; }
readonly ICustomAttributeProvider _suppressionContextMember;
public ICustomAttributeProvider? SuppressionContextMember {
get {
Debug.Assert (_suppressionContextMember == null || _suppressionContextMember is IMemberDefinition || _suppressionContextMember is AssemblyDefinition);
return _suppressionContextMember ?? Provider;
}
}
#nullable disable
public int SourceLine { get; }
public int SourceColumn { get; }
public int? ILOffset { get; }

const int HiddenLineNumber = 0xfeefee;

public MessageOrigin (IMemberDefinition memberDefinition)
: this (memberDefinition, null)
public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset = null)
: this (memberDefinition as ICustomAttributeProvider, ilOffset)
{
}

public MessageOrigin (ICustomAttributeProvider provider)
: this (provider, null)
{
}

Expand All @@ -34,31 +44,43 @@ public MessageOrigin (string fileName, int sourceLine = 0, int sourceColumn = 0)
FileName = fileName;
SourceLine = sourceLine;
SourceColumn = sourceColumn;
MemberDefinition = null;
Provider = null;
_suppressionContextMember = null;
ILOffset = null;
}

public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset)
: this (memberDefinition, ilOffset, null)
public MessageOrigin (ICustomAttributeProvider provider, int? ilOffset)
: this (provider, ilOffset, null)
{
}

public MessageOrigin (IMemberDefinition memberDefinition, int? ilOffset, IMemberDefinition suppressionContextMember)
public MessageOrigin (ICustomAttributeProvider provider, int? ilOffset, ICustomAttributeProvider suppressionContextMember)
{
Debug.Assert (provider == null || provider is IMemberDefinition || provider is AssemblyDefinition);
Debug.Assert (suppressionContextMember == null || suppressionContextMember is IMemberDefinition || provider is AssemblyDefinition);
FileName = null;
MemberDefinition = memberDefinition;
Provider = provider;
_suppressionContextMember = suppressionContextMember;
SourceLine = 0;
SourceColumn = 0;
ILOffset = ilOffset;
}

public MessageOrigin (MessageOrigin other, IMemberDefinition suppressionContextMember)
{
FileName = other.FileName;
Provider = other.Provider;
_suppressionContextMember = suppressionContextMember;
SourceLine = other.SourceLine;
SourceColumn = other.SourceColumn;
ILOffset = other.ILOffset;
}

public override string ToString ()
{
int sourceLine = SourceLine, sourceColumn = SourceColumn;
string fileName = FileName;
if (MemberDefinition is MethodDefinition method &&
if (Provider is MethodDefinition method &&
method.DebugInformation.HasSequencePoints) {
var offset = ILOffset ?? 0;
SequencePoint correspondingSequencePoint = method.DebugInformation.SequencePoints
Expand Down Expand Up @@ -94,28 +116,32 @@ public override string ToString ()
}

public bool Equals (MessageOrigin other) =>
(FileName, MemberDefinition, SourceLine, SourceColumn, ILOffset) == (other.FileName, other.MemberDefinition, other.SourceLine, other.SourceColumn, other.ILOffset);
(FileName, Provider, SourceLine, SourceColumn, ILOffset) == (other.FileName, other.Provider, other.SourceLine, other.SourceColumn, other.ILOffset);

public override bool Equals (object obj) => obj is MessageOrigin messageOrigin && Equals (messageOrigin);
public override int GetHashCode () => (FileName, MemberDefinition, SourceLine, SourceColumn).GetHashCode ();
public override int GetHashCode () => (FileName, Provider, SourceLine, SourceColumn).GetHashCode ();
public static bool operator == (MessageOrigin lhs, MessageOrigin rhs) => lhs.Equals (rhs);
public static bool operator != (MessageOrigin lhs, MessageOrigin rhs) => !lhs.Equals (rhs);

public int CompareTo (MessageOrigin other)
{
if (MemberDefinition != null && other.MemberDefinition != null) {
TypeDefinition thisTypeDef = (MemberDefinition as TypeDefinition) ?? MemberDefinition.DeclaringType;
TypeDefinition otherTypeDef = (other.MemberDefinition as TypeDefinition) ?? other.MemberDefinition.DeclaringType;
int result = (thisTypeDef?.Module?.Assembly?.Name?.Name, thisTypeDef?.Name, MemberDefinition?.Name).CompareTo
((otherTypeDef?.Module?.Assembly?.Name?.Name, otherTypeDef?.Name, other.MemberDefinition?.Name));
if (Provider != null && other.Provider != null) {
var thisMember = Provider as IMemberDefinition;
var otherMember = other.Provider as IMemberDefinition;
TypeDefinition thisTypeDef = (Provider as TypeDefinition) ?? (Provider as IMemberDefinition)?.DeclaringType;
TypeDefinition otherTypeDef = (other.Provider as TypeDefinition) ?? (other.Provider as IMemberDefinition)?.DeclaringType;
var thisAssembly = thisTypeDef?.Module.Assembly ?? Provider as AssemblyDefinition;
var otherAssembly = otherTypeDef?.Module.Assembly ?? other.Provider as AssemblyDefinition;
int result = (thisAssembly.Name.Name, thisTypeDef?.Name, thisMember?.Name).CompareTo
((otherAssembly.Name.Name, otherTypeDef?.Name, otherMember?.Name));
if (result != 0)
return result;

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

return ILOffset == null ? (other.ILOffset == null ? 0 : 1) : -1;
} else if (MemberDefinition == null && other.MemberDefinition == null) {
} else if (Provider == null && other.Provider == null) {
if (FileName != null && other.FileName != null) {
return string.Compare (FileName, other.FileName);
} else if (FileName == null && other.FileName == null) {
Expand All @@ -125,7 +151,7 @@ public int CompareTo (MessageOrigin other)
return (FileName == null) ? 1 : -1;
}

return (MemberDefinition == null) ? 1 : -1;
return (Provider == null) ? 1 : -1;
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Sources from the mono/linker repo at commit 012efef292663aa38f9047896942cdcc8765b8e0.
Sources from the dotnet/linker repo at commit c0567db0b9088e2ad4144cd0fe2a985611ec28f0.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public enum ReadyToRunSectionType
ThreadStaticIndex = 210,
LoopHijackFlag = 211,
ImportAddressTables = 212,
ModuleInitializerList = 213,

// Sections 300 - 399 are reserved for RhFindBlob backwards compatibility
ReadonlyBlobRegionStart = 300,
Expand Down
Loading