1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 using System.Collections.Generic; 7 8 using ILCompiler.DependencyAnalysisFramework; 9 using Internal.TypeSystem; 10 11 namespace ILCompiler.DependencyAnalysis 12 { 13 public abstract partial class ObjectNode : SortableDependencyNode 14 { 15 public class ObjectData 16 { ObjectData(byte[] data, Relocation[] relocs, int alignment, ISymbolDefinitionNode[] definedSymbols)17 public ObjectData(byte[] data, Relocation[] relocs, int alignment, ISymbolDefinitionNode[] definedSymbols) 18 { 19 Data = data; 20 Relocs = relocs; 21 Alignment = alignment; 22 DefinedSymbols = definedSymbols; 23 } 24 25 public readonly Relocation[] Relocs; 26 public readonly byte[] Data; 27 public readonly int Alignment; 28 public readonly ISymbolDefinitionNode[] DefinedSymbols; 29 } 30 31 public virtual bool RepresentsIndirectionCell => false; 32 GetData(NodeFactory factory, bool relocsOnly = false)33 public abstract ObjectData GetData(NodeFactory factory, bool relocsOnly = false); 34 35 public abstract ObjectNodeSection Section { get; } 36 37 /// <summary> 38 /// Should identical symbols emitted into separate object files be Comdat folded when linked together? 39 /// </summary> 40 public abstract bool IsShareable { get; } 41 42 /// <summary> 43 /// Override this function to have a node which should be skipped when emitting 44 /// to the object file. (For instance, if there are two nodes describing the same 45 /// data structure, one of those nodes should return true here.) 46 /// </summary> 47 /// <param name="factory"></param> 48 /// <returns></returns> ShouldSkipEmittingObjectNode(NodeFactory factory)49 public virtual bool ShouldSkipEmittingObjectNode(NodeFactory factory) 50 { 51 return false; 52 } 53 54 /// <summary> 55 /// Return a node that is used for linkage 56 /// </summary> 57 /// <param name="factory"></param> 58 /// <returns></returns> NodeForLinkage(NodeFactory factory)59 public virtual ObjectNode NodeForLinkage(NodeFactory factory) 60 { 61 return this; 62 } 63 64 public override bool HasConditionalStaticDependencies => false; 65 public override bool HasDynamicDependencies => false; 66 public override bool InterestingForDynamicDependencyAnalysis => false; 67 GetStaticDependencies(NodeFactory factory)68 public sealed override IEnumerable<DependencyListEntry> GetStaticDependencies(NodeFactory factory) 69 { 70 DependencyList dependencies = ComputeNonRelocationBasedDependencies(factory); 71 Relocation[] relocs = GetData(factory, true).Relocs; 72 73 if (relocs != null) 74 { 75 if (dependencies == null) 76 dependencies = new DependencyList(); 77 78 foreach (Relocation reloc in relocs) 79 { 80 dependencies.Add(reloc.Target, "reloc"); 81 } 82 } 83 84 if (dependencies == null) 85 return Array.Empty<DependencyListEntry>(); 86 else 87 return dependencies; 88 } 89 ComputeNonRelocationBasedDependencies(NodeFactory factory)90 protected virtual DependencyList ComputeNonRelocationBasedDependencies(NodeFactory factory) 91 { 92 return null; 93 } 94 95 public override IEnumerable<CombinedDependencyListEntry> GetConditionalStaticDependencies(NodeFactory factory) => null; SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory factory)96 public override IEnumerable<CombinedDependencyListEntry> SearchDynamicDependencies(List<DependencyNodeCore<NodeFactory>> markedNodes, int firstNode, NodeFactory factory) => null; 97 } 98 } 99