Skip to content

Commit

Permalink
Harvest signatures of methods being compiled by the token resolver (#…
Browse files Browse the repository at this point in the history
…57366)

Fixes: #56971

I believe this is the primary fix for the issue; when a type only
ever occurs in method signatures in an assembly, never in the
implementation IL, JIT never calls resolveToken for it and so it
doesn't make it to the module token resolver table.

My investigation revealed additional potential problems in the
product around exported type resolution and the IL linker;
I described them in the issue thread but I believe this to be
both the most appropriate and the safest primary fix.

Thanks

Tomas
  • Loading branch information
trylek authored Aug 14, 2021
1 parent 73b249e commit 1f26d24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public void AddModuleTokenForMethod(MethodDesc method, ModuleToken token)
AddModuleTokenForType(owningType, new ModuleToken(token.Module, owningTypeHandle));
memberRef.DecodeMethodSignature<DummyTypeInfo, ModuleTokenResolver>(new TokenResolverProvider(this, token.Module), this);
}
if (token.TokenType == CorTokenType.mdtMethodDef)
{
MethodDefinition methodDef = token.MetadataReader.GetMethodDefinition((MethodDefinitionHandle)token.Handle);
methodDef.DecodeSignature<DummyTypeInfo, ModuleTokenResolver>(new TokenResolverProvider(this, token.Module), this);
}
}

private void AddModuleTokenForFieldReference(TypeDesc owningType, ModuleToken token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ public void CompileMethod(MethodWithGCInfo methodCodeNodeNeedingCode, Logger log
{
if (!FunctionJustThrows(methodIL))
{
if (MethodBeingCompiled.GetTypicalMethodDefinition() is EcmaMethod ecmaMethod)
{
// Harvest the method being compiled for the purpose of populating the type resolver
var resolver = _compilation.NodeFactory.Resolver;
resolver.AddModuleTokenForMethod(MethodBeingCompiled, new ModuleToken(ecmaMethod.Module, ecmaMethod.Handle));
}
CompileMethodInternal(methodCodeNodeNeedingCode, methodIL);
codeGotPublished = true;
}
Expand Down

0 comments on commit 1f26d24

Please sign in to comment.