From bf35592e42c3cb1cbb159f3cd0c335c0beafdcbe Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Mon, 18 Jul 2022 15:27:26 -0700 Subject: [PATCH] Scan calli dependencies Contributes to #72316 --- .../IL/ILImporter.Scanner.cs | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index acaa1a0ca859d..597e42dbe92f7 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -226,12 +226,6 @@ private void EndImportingInstruction() _isReadOnly = false; } - private void ImportJmp(int token) - { - // JMP is kind of like a tail call (with no arguments pushed on the stack). - ImportCall(ILOpcode.call, token); - } - private void ImportCasting(ILOpcode opcode, int token) { TypeDesc type = (TypeDesc)_methodIL.GetObject(token); @@ -767,6 +761,31 @@ private void ImportLdFtn(int token, ILOpcode opCode) ImportCall(opCode, token); } + private void ImportJmp(int token) + { + // JMP is kind of like a tail call (with no arguments pushed on the stack). + ImportCall(ILOpcode.call, token); + } + + private void ImportCalli(int token) + { + MethodSignature signature = (MethodSignature)_methodIL.GetObject(token); + + // Managed calli + if ((signature.Flags & MethodSignatureFlags.UnmanagedCallingConventionMask) == 0) + return; + + // Calli in marshaling stubs + if (_methodIL is Internal.IL.Stubs.PInvokeILStubMethodIL) + return; + + MethodDesc stub = _compilation.PInvokeILProvider.GetCalliStub( + signature, + ((MetadataType)_methodIL.OwningMethod.OwningType).Module); + + _dependencies.Add(_factory.CanonicalEntrypoint(stub), "calli"); + } + private void ImportBranch(ILOpcode opcode, BasicBlock target, BasicBlock fallthrough) { ImportFallthrough(target); @@ -1316,7 +1335,6 @@ private void ImportStoreVar(int index, bool argument) { } private void ImportAddressOfVar(int index, bool argument) { } private void ImportDup() { } private void ImportPop() { } - private void ImportCalli(int token) { } private void ImportLoadNull() { } private void ImportReturn() { } private void ImportLoadInt(long value, StackValueKind kind) { }