Skip to content

Commit

Permalink
Make things work for arrays of function pointers (dotnet#71749)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
MichalStrehovsky authored Jul 7, 2022
1 parent 32ca998 commit 7331be5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/coreclr/tools/Common/Compiler/NativeAotNameMangler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ public override IEnumerable<DependencyListEntry> 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;
Expand Down

0 comments on commit 7331be5

Please sign in to comment.