diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs index c32e6215bd5049..f281a1ca569ca5 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Compilation.cs @@ -344,7 +344,7 @@ public ISymbolNode ComputeConstantLookup(ReadyToRunHelperId lookupKind, object t case ReadyToRunHelperId.ObjectAllocator: { var type = (TypeDesc)targetOfLookup; - return NodeFactory.ExternSymbol(JitHelper.GetNewObjectHelperForType(type)); + return NodeFactory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(type)); } default: diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternEETypeSymbolNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternEETypeSymbolNode.cs index 053642f6eff505..1292076f32bde7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternEETypeSymbolNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternEETypeSymbolNode.cs @@ -9,7 +9,7 @@ namespace ILCompiler.DependencyAnalysis /// Represents a symbol that is defined externally but modelled as a type in the /// DependencyAnalysis infrastructure during compilation. /// - public sealed class ExternEETypeSymbolNode : ExternSymbolNode, IEETypeNode + public sealed class ExternEETypeSymbolNode : ExternDataSymbolNode, IEETypeNode { private TypeDesc _type; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternMethodSymbolNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternMethodSymbolNode.cs index 0abfc47f1bff82..d26a42b44192a2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternMethodSymbolNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternMethodSymbolNode.cs @@ -9,7 +9,7 @@ namespace ILCompiler.DependencyAnalysis /// Represents a symbol that is defined externally but modelled as a method /// in the DependencyAnalysis infrastructure during compilation /// - public sealed class ExternMethodSymbolNode : ExternSymbolNode, IMethodNode + public sealed class ExternMethodSymbolNode : ExternFunctionSymbolNode, IMethodNode { private MethodDesc _method; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolNode.cs index 6685fde0831273..8c576421f74d90 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolNode.cs @@ -11,13 +11,15 @@ namespace ILCompiler.DependencyAnalysis { /// /// Represents a symbol that is defined externally and statically linked to the output obj file. + /// When making a new node, do not derive from this class directly, derive from one of its subclasses + /// (ExternFunctionSymbolNode / ExternDataSymbolNode) instead. /// - public class ExternSymbolNode : SortableDependencyNode, ISortableSymbolNode + public abstract class ExternSymbolNode : SortableDependencyNode, ISortableSymbolNode { private readonly Utf8String _name; private readonly bool _isIndirection; - public ExternSymbolNode(Utf8String name, bool isIndirection = false) + protected ExternSymbolNode(Utf8String name, bool isIndirection = false) { _name = name; _isIndirection = isIndirection; @@ -29,6 +31,7 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) { sb.Append(_name); } + public int Offset => 0; public virtual bool RepresentsIndirectionCell => _isIndirection; @@ -42,8 +45,6 @@ public void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) public override IEnumerable SearchDynamicDependencies(List> markedNodes, int firstNode, NodeFactory factory) => null; #if !SUPPORT_JIT - public override int ClassCode => 1092559304; - public override int CompareToImpl(ISortableNode other, CompilerComparer comparer) { return _name.CompareTo(((ExternSymbolNode)other)._name); @@ -56,11 +57,26 @@ public override string ToString() } } - public class AddressTakenExternSymbolNode : ExternSymbolNode + /// + /// Represents a function symbol that is defined externally and statically linked to the output obj file. + /// + public class ExternFunctionSymbolNode(Utf8String name, bool isIndirection = false) : ExternSymbolNode(name, isIndirection) { - public AddressTakenExternSymbolNode(Utf8String name) - : base(name) { } + public override int ClassCode => 1452455506; + } + public class AddressTakenExternFunctionSymbolNode(Utf8String name) : ExternFunctionSymbolNode(name) + { public override int ClassCode => -45645737; } + + /// + /// Represents a data symbol that is defined externally and statically linked to the output obj file. + /// + public class ExternDataSymbolNode(Utf8String name) : ExternSymbolNode(name) + { + public override int ClassCode => 1428609964; + + protected override string GetName(NodeFactory factory) => $"ExternDataSymbolNode {ToString()}"; + } } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolsImportedNodeProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolsImportedNodeProvider.cs index b50d07c23b9e35..1a774c511071bd 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolsImportedNodeProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ExternSymbolsImportedNodeProvider.cs @@ -15,12 +15,12 @@ public override IEETypeNode ImportedEETypeNode(NodeFactory factory, TypeDesc typ public override ISortableSymbolNode ImportedGCStaticNode(NodeFactory factory, MetadataType type) { - return new ExternSymbolNode(GCStaticsNode.GetMangledName(type, factory.NameMangler)); + return new ExternDataSymbolNode(GCStaticsNode.GetMangledName(type, factory.NameMangler)); } public override ISortableSymbolNode ImportedNonGCStaticNode(NodeFactory factory, MetadataType type) { - return new ExternSymbolNode(NonGCStaticsNode.GetMangledName(type, factory.NameMangler)); + return new ExternDataSymbolNode(NonGCStaticsNode.GetMangledName(type, factory.NameMangler)); } public override ISortableSymbolNode ImportedMethodDictionaryNode(NodeFactory factory, MethodDesc method) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericLookupResult.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericLookupResult.cs index 9f5be7ae142ce0..efbd5d98bfa620 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericLookupResult.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/GenericLookupResult.cs @@ -728,7 +728,7 @@ public ObjectAllocatorGenericLookupResult(TypeDesc type) public override ISymbolNode GetTarget(NodeFactory factory, GenericLookupResultContext dictionary) { TypeDesc instantiatedType = _type.GetNonRuntimeDeterminedTypeFromRuntimeDeterminedSubtypeViaSubstitution(dictionary.TypeInstantiation, dictionary.MethodInstantiation); - return factory.ExternSymbol(JitHelper.GetNewObjectHelperForType(instantiatedType)); + return factory.ExternFunctionSymbol(JitHelper.GetNewObjectHelperForType(instantiatedType)); } public override void AppendMangledName(NameMangler nameMangler, Utf8StringBuilder sb) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs index a6add520521126..a016c48e34f4b2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs @@ -46,7 +46,7 @@ public NodeFactory( { _target = context.Target; - InitialInterfaceDispatchStub = new AddressTakenExternSymbolNode("RhpInitialDynamicInterfaceDispatch"); + InitialInterfaceDispatchStub = new AddressTakenExternFunctionSymbolNode("RhpInitialDynamicInterfaceDispatch"); _context = context; _compilationModuleGroup = compilationModuleGroup; @@ -263,13 +263,17 @@ private void CreateNodeCaches() return new FieldRvaDataNode(key); }); - _externSymbols = new NodeCache((string name) => + _externFunctionSymbols = new NodeCache((string name) => { - return new ExternSymbolNode(name); + return new ExternFunctionSymbolNode(name); }); - _externIndirectSymbols = new NodeCache((string name) => + _externIndirectFunctionSymbols = new NodeCache((string name) => { - return new ExternSymbolNode(name, isIndirection: true); + return new ExternFunctionSymbolNode(name, isIndirection: true); + }); + _externDataSymbols = new NodeCache((string name) => + { + return new ExternDataSymbolNode(name); }); _pInvokeModuleFixups = new NodeCache((PInvokeModuleData moduleData) => @@ -793,7 +797,7 @@ public ISortableSymbolNode TypeThreadStaticIndex(MetadataType type) } else { - return ExternSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type)); + return ExternDataSymbol(NameMangler.NodeMangler.ThreadStaticsIndex(type)); } } @@ -903,24 +907,31 @@ internal ISymbolNode GenericVariance(GenericVarianceDetails details) return _genericVariances.GetOrAdd(details); } - private NodeCache _externSymbols; + private NodeCache _externFunctionSymbols; - public ISortableSymbolNode ExternSymbol(string name) + public ISortableSymbolNode ExternFunctionSymbol(string name) { - return _externSymbols.GetOrAdd(name); + return _externFunctionSymbols.GetOrAdd(name); } - public ISortableSymbolNode ExternVariable(string name) + private NodeCache _externIndirectFunctionSymbols; + + public ISortableSymbolNode ExternIndirectFunctionSymbol(string name) { - string mangledName = NameMangler.NodeMangler.ExternVariable(name); - return _externSymbols.GetOrAdd(mangledName); + return _externIndirectFunctionSymbols.GetOrAdd(name); } - private NodeCache _externIndirectSymbols; + private NodeCache _externDataSymbols; - public ISortableSymbolNode ExternIndirectSymbol(string name) + public ISortableSymbolNode ExternDataSymbol(string name) { - return _externIndirectSymbols.GetOrAdd(name); + return _externDataSymbols.GetOrAdd(name); + } + + public ISortableSymbolNode ExternVariable(string name) + { + string mangledName = NameMangler.NodeMangler.ExternVariable(name); + return _externDataSymbols.GetOrAdd(mangledName); } private NodeCache _pInvokeModuleFixups; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeImportMethodNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeImportMethodNode.cs index 6ccf0d25d43ad6..1d4d4b47c3c4b1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeImportMethodNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/RuntimeImportMethodNode.cs @@ -9,7 +9,7 @@ namespace ILCompiler.DependencyAnalysis /// /// Represents a method that is imported from the runtime library. /// - public class RuntimeImportMethodNode : ExternSymbolNode, IMethodNode, ISymbolDefinitionNode + public class RuntimeImportMethodNode : ExternFunctionSymbolNode, IMethodNode, ISymbolDefinitionNode { private MethodDesc _method; diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM/ARMReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM/ARMReadyToRunHelperNode.cs index 85a507d6a1dd90..b7db3ab474e48c 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM/ARMReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM/ARMReadyToRunHelperNode.cs @@ -128,7 +128,7 @@ protected override void EmitCode(NodeFactory factory, ref ARMEmitter encoder, bo if (targetMethod.OwningType.IsInterface) { encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod)); - encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod")); + encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod")); } else { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs index 430fb07d960242..de94d044527b2f 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_ARM64/ARM64ReadyToRunHelperNode.cs @@ -144,7 +144,7 @@ protected override void EmitCode(NodeFactory factory, ref ARM64Emitter encoder, if (targetMethod.OwningType.IsInterface) { encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod)); - encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod")); + encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod")); } else { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_LoongArch64/LoongArch64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_LoongArch64/LoongArch64ReadyToRunHelperNode.cs index 3339edb837a57c..98e433a5058c4d 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_LoongArch64/LoongArch64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_LoongArch64/LoongArch64ReadyToRunHelperNode.cs @@ -136,7 +136,7 @@ protected override void EmitCode(NodeFactory factory, ref LoongArch64Emitter enc if (targetMethod.OwningType.IsInterface) { encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod)); - encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod")); + encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod")); } else { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64ReadyToRunHelperNode.cs index afe928b4f24be6..cb217b1e2bffb2 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64ReadyToRunHelperNode.cs @@ -134,7 +134,7 @@ protected override void EmitCode(NodeFactory factory, ref RiscV64Emitter encoder if (targetMethod.OwningType.IsInterface) { encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod)); - encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod")); + encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod")); } else { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs index a63deaf80c1dd3..c5f8cab13db3f7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs @@ -149,7 +149,7 @@ protected override void EmitCode(NodeFactory factory, ref X64Emitter encoder, bo if (targetMethod.OwningType.IsInterface) { encoder.EmitLEAQ(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod)); - encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod")); + encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod")); } else { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X86/X86ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X86/X86ReadyToRunHelperNode.cs index 472f628a353393..e2b8e6724aaf25 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X86/X86ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X86/X86ReadyToRunHelperNode.cs @@ -159,7 +159,7 @@ protected override void EmitCode(NodeFactory factory, ref X86Emitter encoder, bo if (targetMethod.OwningType.IsInterface) { encoder.EmitMOV(encoder.TargetRegister.Arg1, factory.InterfaceDispatchCell(targetMethod)); - encoder.EmitJMP(factory.ExternSymbol("RhpResolveInterfaceMethod")); + encoder.EmitJMP(factory.ExternFunctionSymbol("RhpResolveInterfaceMethod")); } else { diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs index bc3f6ef3945523..a2f2e23f7902d1 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs @@ -200,7 +200,7 @@ protected override Helper CreateValueFromKey(ReadyToRunHelper key) ISymbolNode entryPoint; if (mangledName != null) - entryPoint = _compilation.NodeFactory.ExternSymbol(mangledName); + entryPoint = _compilation.NodeFactory.ExternFunctionSymbol(mangledName); else entryPoint = _compilation.NodeFactory.MethodEntrypoint(methodDesc); diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ObjectWriter.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ObjectWriter.cs index 542f150cb1f315..04a4012355fa1b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ObjectWriter.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ObjectWriter/ObjectWriter.cs @@ -467,7 +467,7 @@ private void EmitObject(string objectFilePath, IReadOnlyCollectionexactContextNeedsRuntimeLookup = false; - pResult->codePointerOrStubLookup.constLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("NYI_LDVIRTFTN")); + pResult->codePointerOrStubLookup.constLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternFunctionSymbol("NYI_LDVIRTFTN")); } else { @@ -1913,7 +1913,7 @@ private void getAddressOfPInvokeTarget(CORINFO_METHOD_STRUCT_* method, ref CORIN string externName = _compilation.PInvokeILProvider.GetDirectCallExternName(md); externName = _compilation.NodeFactory.NameMangler.NodeMangler.ExternMethod(externName, md); - pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol(externName)); + pLookup = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternFunctionSymbol(externName)); } private void getGSCookie(IntPtr* pCookieVal, IntPtr** ppCookieVal) @@ -2468,10 +2468,10 @@ private bool getStaticBaseAddress(CORINFO_CLASS_STRUCT_* cls, bool isGc, ref COR private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // Offset of ThreadLocalStoragePointer in the TEB - pInfo->tlsIndexObject = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); + pInfo->tlsIndexObject = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternDataSymbol("_tls_index")); pInfo->tlsRootObject = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); pInfo->threadStaticBaseSlow = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); - pInfo->tlsGetAddrFtnPtr = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("__tls_get_addr")); + pInfo->tlsGetAddrFtnPtr = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternFunctionSymbol("__tls_get_addr")); } #pragma warning disable CA1822 // Mark members as static