blob: 262d0799ab91d96d24ef31ccbcc45d41d1ab35b6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Diagnostics;
using Internal.Text;
using Internal.TypeSystem;
using Internal.TypeSystem.Interop;
namespace ILCompiler.DependencyAnalysis
{
[Flags]
public enum AssociatedDataFlags : byte
{
None = 0,
HasUnboxingStubTarget = 1,
}
/// <summary>
/// This node contains any custom data that we'd like to associated with a method. The unwind info of the method
/// will have a reloc to this custom data if it exists. Not all methods need custom data to be emitted.
/// This custom data excludes gcinfo and ehinfo (they are written by ObjectWriter during obj file emission).
/// </summary>
public class MethodAssociatedDataNode : ObjectNode, ISymbolDefinitionNode
{
private IMethodNode _methodNode;
public MethodAssociatedDataNode(IMethodNode methodNode)
{
Debug.Assert(!methodNode.Method.IsAbstract);
Debug.Assert(methodNode.Method.GetCanonMethodTarget(CanonicalFormKind.Specific) == methodNode.Method);
_methodNode = methodNode;
}
protected override string GetName(NodeFactory factory) => this.GetMangledName(factory.NameMangler);
public override ObjectNodeSection Section => ObjectNodeSection.ReadOnlyDataSection;
public override bool StaticDependenciesAreComputed => true;
public int Offset => 0;
public override bool IsShareable => _methodNode.Method is InstantiatedMethod || EETypeNode.IsTypeNodeShareable(_methodNode.Method.OwningType);
public override int ClassCode => 1055183914;
public override int CompareToImpl(ISortableNode other, CompilerComparer comparer)
{
return comparer.Compare(_methodNode, ((MethodAssociatedDataNode)other)._methodNode);
}
public virtual void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb)
{
sb.Append("_associatedData_").Append(nameMangler.GetMangledMethodName(_methodNode.Method));
}
public static bool MethodHasAssociatedData(NodeFactory factory, IMethodNode methodNode)
{
// Instantiating unboxing stubs. We need to store their non-unboxing target pointer (looked up by runtime)
ISpecialUnboxThunkNode unboxThunk = methodNode as ISpecialUnboxThunkNode;
if(unboxThunk != null && unboxThunk.IsSpecialUnboxingThunk)
return true;
return false;
}
public override ObjectData GetData(NodeFactory factory, bool relocsOnly)
{
Debug.Assert(MethodHasAssociatedData(factory, _methodNode));
ObjectDataBuilder objData = new ObjectDataBuilder(factory, relocsOnly);
objData.RequireInitialAlignment(1);
objData.AddSymbol(this);
AssociatedDataFlags flags = AssociatedDataFlags.None;
var flagsReservation = objData.ReserveByte();
ISpecialUnboxThunkNode unboxThunkNode = _methodNode as ISpecialUnboxThunkNode;
if (unboxThunkNode != null && unboxThunkNode.IsSpecialUnboxingThunk)
{
flags |= AssociatedDataFlags.HasUnboxingStubTarget;
objData.EmitReloc(unboxThunkNode.GetUnboxingThunkTarget(factory), RelocType.IMAGE_REL_BASED_RELPTR32);
}
objData.EmitByte(flagsReservation, (byte)flags);
return objData.ToObjectData();
}
}
}
|