From d31b5b32d281a7f48e0e14927e606437c2f20c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 7 Jul 2022 12:58:26 +0900 Subject: [PATCH] Make things work for arrays of function pointers * Don't try to obtain type handles for fields of types of function pointer arrays * Add function pointer support to name mangler. We still don't make EETypes for these, but debug info generation also needs mangled names. We currently generate debug info for function pointers as debug info for `void*`, but arrays of function pointers only partially go through that handling and still end up needing a mangled name for the function pointer. --- .../Common/Compiler/NativeAotNameMangler.cs | 17 +++++++++++++++++ .../DependencyAnalysis/ReflectableFieldNode.cs | 6 +++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs b/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs index c93e19a9173e4f..f0ca74dde53e57 100644 --- a/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs +++ b/src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs @@ -302,6 +302,23 @@ private string ComputeMangledTypeName(TypeDesc type) case TypeFlags.Pointer: mangledName = GetMangledTypeName(((PointerType)type).ParameterType) + NestMangledName("Pointer"); break; + case TypeFlags.FunctionPointer: + // TODO: need to also encode calling convention (or all modopts?) + var fnPtrType = (FunctionPointerType)type; + mangledName = "__FnPtr" + EnterNameScopeSequence; + mangledName += GetMangledTypeName(fnPtrType.Signature.ReturnType); + + mangledName += EnterNameScopeSequence; + for (int i = 0; i < fnPtrType.Signature.Length; i++) + { + if (i != 0) + mangledName += DelimitNameScopeSequence; + mangledName += GetMangledTypeName(fnPtrType.Signature[i]); + } + mangledName += ExitNameScopeSequence; + + mangledName += ExitNameScopeSequence; + break; default: // Case of a generic type. If `type' is a type definition we use the type name // for mangling, otherwise we use the mangling of the type and its generic type diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs index c5bd4945050676..4f4cd477d44e3b 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReflectableFieldNode.cs @@ -85,7 +85,11 @@ public override IEnumerable GetStaticDependencies(NodeFacto // Runtime reflection stack needs to obtain the type handle of the field // (but there's no type handles for function pointers) - if (!_field.FieldType.IsFunctionPointer) + TypeDesc fieldTypeToCheck = _field.FieldType; + while (fieldTypeToCheck.IsParameterizedType) + fieldTypeToCheck = ((ParameterizedType)fieldTypeToCheck).ParameterType; + + if (!fieldTypeToCheck.IsFunctionPointer) dependencies.Add(factory.MaximallyConstructableType(_field.FieldType.NormalizeInstantiation()), "Type of the field"); return dependencies;