Skip to content

JIT_PInvoke asm stubs missing for i386 #68411

@ta264

Description

@ta264

Description

The JIT_PInvokeBegin and JIT_PInvokeEnd stubs are missing for i386.

Currently you can compile a linux-x86 runtime and it seems functional. However if you allow the build process to run crossgen2 on the output, the resulting product fails and throws SIGTRAP at runtime.

The missing stubs should be here:

LEAF_ENTRY JIT_PInvokeBegin, _TEXT
// Not yet supported
int 3
ret
LEAF_END JIT_PInvokeBegin, _TEXT
//
// IN:
// InlinedCallFrame (ecx) = pointer to the InlinedCallFrame data, including the GS cookie slot (GS cookie right
// before actual InlinedCallFrame data)
//
//
LEAF_ENTRY JIT_PInvokeEnd, _TEXT
// Not yet supported
int 3
ret
LEAF_END JIT_PInvokeEnd, _TEXT

Reproduction Steps

See the pipeline here:
https://github.com/Servarr/dotnet-linux-x86/blob/4b0474c30e5ea2900e14fbe94831d64d7f44b318/azure-pipelines.yml#L73

Omit the following two lines to allow crossgen2 to run:
https://github.com/Servarr/dotnet-linux-x86/blob/4b0474c30e5ea2900e14fbe94831d64d7f44b318/azure-pipelines.yml#L82-L83

Expected behavior

Resulting product can run a hello world

Actual behavior

Starting program: /git_working/dotnet/dotnet ./bin/Debug/net7.0/helloworld2.dll
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0xf735eb40 (LWP 362)]
[New Thread 0xf69ffb40 (LWP 363)]
[New Thread 0xf5fffb40 (LWP 364)]
[New Thread 0xf55ffb40 (LWP 365)]
[New Thread 0xf1bfeb40 (LWP 366)]
[New Thread 0xefbd6b40 (LWP 367)]

Thread 1 "dotnet" received signal SIGTRAP, Trace/breakpoint trap.
JIT_PInvokeBegin () at /runtime/src/coreclr/vm/i386/pinvokestubs.S:17
17              ret
(gdb) bt
#0  JIT_PInvokeBegin () at /runtime/src/coreclr/vm/i386/pinvokestubs.S:17
#1  0xeff0e799 in ?? ()
#2  0xeff0e75e in ?? ()
#3  0xeff2c86e in ?? ()
#4  0xeff3884d in ?? ()
#5  0xf76a48aa in CallDescrWorkerInternal () at /runtime/src/coreclr/vm/i386/asmhelpers.S:303
#6  0xf74dff13 in CallDescrWorkerWithHandler (pCallDescrData=0xffffd038, fCriticalCall=0) at /runtime/src/coreclr/vm/callhelpers.cpp:67
#7  MethodDescCallSite::CallTargetWorker (this=0xffffd0d0, pArguments=0xffffd140, pReturnValue=0x0, cbReturnValue=0) at /runtime/src/coreclr/vm/callhelpers.cpp:538
#8  0xf73e45b1 in MethodDescCallSite::Call (this=0xffffd0d0, pArguments=0xffffd140) at /runtime/src/coreclr/vm/callhelpers.h:458
#9  CorHost2::CreateAppDomainWithManager (this=0x5657aa90, wszFriendlyName=<optimized out>, dwFlags=0, wszAppDomainManagerAssemblyName=<optimized out>, wszAppDomainManagerTypeName=<optimized out>, nProperties=9, pPropertyNames=0x56576960, pPropertyValues=0x565813a0, pAppDomainID=0xffffd260) at /runtime/src/coreclr/vm/corhost.cpp:625
#10 0xf7398325 in coreclr_initialize (exePath=0x56570190 "/git_working/dotnet/dotnet", appDomainFriendlyName=0xf7a47ae4 "clrhost", propertyCount=9, propertyKeys=0x56582900, propertyValues=0x56582a70, hostHandle=0xffffd264, domainId=0xffffd260) at /runtime/src/coreclr/dlls/mscoree/exports.cpp:254
#11 0xf7a1346f in ?? () from /git_working/dotnet/shared/Microsoft.NETCore.App/7.0.0-preview.3.22175.4/libhostpolicy.so
#12 0xf7a21209 in ?? () from /git_working/dotnet/shared/Microsoft.NETCore.App/7.0.0-preview.3.22175.4/libhostpolicy.so
#13 0xf7a20aed in corehost_main () from /git_working/dotnet/shared/Microsoft.NETCore.App/7.0.0-preview.3.22175.4/libhostpolicy.so
#14 0xf7a66f62 in ?? () from /git_working/dotnet/host/fxr/7.0.0-preview.3.22175.4/libhostfxr.so
#15 0xf7a65a4f in ?? () from /git_working/dotnet/host/fxr/7.0.0-preview.3.22175.4/libhostfxr.so
#16 0xf7a624f6 in hostfxr_main_startupinfo () from /git_working/dotnet/host/fxr/7.0.0-preview.3.22175.4/libhostfxr.so
#17 0x56562ca2 in ?? ()
#18 0x56562f18 in ?? ()
#19 0xf7ac7ee5 in __libc_start_main () from /lib/i386-linux-gnu/libc.so.6
#20 0x565588df in ?? ()


### Regression?

I'm not sure

### Known Workarounds

Replacing `EmitIL` here:
https://github.com/dotnet/runtime/blob/0e18cfda13a8136103c83442e1a649cdecc237b0/src/coreclr/tools/aot/ILCompiler.ReadyToRun/IL/Stubs/PInvokeILEmitter.cs#L82-L129

with:
```csharp
private MethodIL EmitIL()
{
    throw new NotSupportedException();
}

seems to help.

Alternatively disable running crossgen completely.

Configuration

.NET 7 Preview 3
Cross compiling on Ubuntu 20.04 for linux-x86
Running the output in an Ubuntu 20.04 docker with multilib support enabled

dpkg --add-architecture i386
apt-get update
apt-get install libc6:i386 libgcc1:i386 libgssapi-krb5-2:i386 libicu66:i386 libssl1.1:i386 libstdc++6:i386 zlib1g:i386

Other information

Would be happy to help to try to implement this but I'm totally out of my depth so would need some pointers

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-x86area-VM-coreclrhelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is mergedos-linuxLinux OS (any supported distro)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions