getsentry / sentry-unity

Development of Sentry SDK for Unity
https://docs.sentry.io/platforms/unity/
MIT License
208 stars 52 forks source link

Builds on Unity 2022.1 break with aliased package #691

Closed bitsandfoxes closed 2 years ago

bitsandfoxes commented 2 years ago

Building an IL2CPP build with the aliased Sentry package installed results in: The build works fine when using the un-aliased Sentry package.

Building .../MacStandalonePlayerBuildProgram/4g2s2/96vv_icMethods2.o failed with output:
.../MacStandalonePlayerBuildProgram/il2cppOutput/cpp/GenericMethods2.cpp:16744:10:
error: cannot initialize return object of type 'Il2CppFullySharedGenericAny *' (aka 'void **') with an lvalue of type 'void *'
                return (L_2);
                       ^~~~~
1 error generated.

This is the generated method in question:

// T& System.Runtime.CompilerServices.Unsafe::Unbox<Unity.IL2CPP.Metadata.__Il2CppFullySharedGenericType>(System.Object)
IL2CPP_EXTERN_C IL2CPP_METHOD_ATTR Il2CppFullySharedGenericAny* Unsafe_Unbox_TisIl2CppFullySharedGenericAny_mF6CD1F81A0CA0414C3EA88A19A4BB220865E8182_gshared (RuntimeObject* ___box0, const RuntimeMethod* method) 
{
  il2cpp_rgctx_method_init(method);
  // T
  // sizeof(T)
  const uint32_t SizeOf_T_t6EEA42083AA5049EFD4B883DDFBF7D3F1BF8696C = il2cpp_codegen_sizeof(il2cpp_rgctx_data(method->rgctx_data, 0));
  const Il2CppFullySharedGenericAny L_1 = alloca(SizeOf_T_t6EEA42083AA5049EFD4B883DDFBF7D3F1BF8696C);
  {
    RuntimeObject* L_0 = ___box0;
    void* L_2 = UnBox_Any(L_0, il2cpp_rgctx_data(method->rgctx_data, 0), L_1);
    return (L_2);
  }
}

The issue has been raised with Unity and can be tracked here: https://fogbugz.unity3d.com/default.asp?1419859_qmt0m8hc0mpc1mc5 Since we're aliasing the DLLs but the IL remains valid and it seems to be related to Unity's new Il2CppFullySharedGenericAny feature we hope this can be resolved by the IL2CPP team.

I've appended a minimal repro that contains a link.xml (to keep the Unsafe.dll from being stripped) and the aliased Unsafe.dll 2022_1.zip

SimonCropp commented 2 years ago

@bitsandfoxes

SimonCropp commented 2 years ago

also what does this mean https://unity3d.com/unity/beta/2022.1.0b16

IL2CPP: Use intrinsics for System.Runtime.CompilerServices.Unsafe methods.

bitsandfoxes commented 2 years ago
  • does unity explicitly use System.Runtime.CompilerServices.Unsafe.dll internally? if so what version?

I found a couple of those inside the installation:

./2022.1.0b15/Unity.app/Contents/Tools/ScriptUpdater/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/Tools/netcorerun/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/DotNetSdkRoslyn/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/MonoBleedingEdge/lib/mono/msbuild/Current/bin/Roslyn/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/MonoBleedingEdge/lib/mono/net_4_x-linux/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/MonoBleedingEdge/lib/mono/net_4_x-win32/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/MonoBleedingEdge/lib/mono/4.5/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/MonoBleedingEdge/lib/mono/net_4_x-macos/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/NetCoreRuntime/shared/Microsoft.NETCore.App/5.0.3/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/il2cpp/build/deploy/System.Runtime.CompilerServices.Unsafe.dll
./2022.1.0b15/Unity.app/Contents/Frameworks/UnityLicensingClient.app/Contents/MacOS/System.Runtime.CompilerServices.Unsafe.dll

The one that jumped at me was ./2022.1.0b15/Unity.app/Contents/il2cpp/build/deploy/System.Runtime.CompilerServices.Unsafe.dll that's in there in version 5.0.0.0

  • i wonder if unity has some hard coded string type checking that looks for "System.Runtime.CompilerServices.Unsafe". do u know where we could find this?

I don't know. I do know that we had an issue where if we were to build the SDK with the TargetFramework netstandard2.1 the Memory.dll we'd bring would conflict with with the one that Unity ships with.

also what does this mean https://unity3d.com/unity/beta/2022.1.0b16

IL2CPP: Use intrinsics for System.Runtime.CompilerServices.Unsafe methods.

When I see intrinsics in context of Unity I would think it's about that: https://blog.unity.com/games/updated-guide-for-using-neon-intrinsics-in-unity-burst

vaind commented 2 years ago

Pasting the current status here for anyone who's following

https://github.com/getsentry/sentry-unity/pull/765#issuecomment-1148569378 We've got a response from Unity: They are looking into it and are keen to fix this.

ghost commented 2 years ago

Is there a workaround in the meantime? I'm exploring building with IL2CPP and 2022.1 (for the sake of line numbers in stack traces) and I'm running into this exact issue.

bitsandfoxes commented 2 years ago

Unfortunately, short of building the SDK yourself, I currently don't see a workaround. We've got the issue open with Unity and it looks like they are actively working on it: https://issuetracker.unity3d.com/issues/il2cpp-build-fails-when-using-an-assembly-renamed-via-sentrys-assembly-alias-tool

Additionally, we're currently working on providing line numbers ourselves which looks like should work down to Unity 2020.3.

bruno-garcia commented 2 years ago

Any update from Unity on this one? I see there's no update on their bug tracker though: https://fogbugz.unity3d.com/default.asp?1419859_qmt0m8hc0mpc1mc5

bitsandfoxes commented 2 years ago

We're basically waiting for a new version and one of the boxes to go green: https://issuetracker.unity3d.com/issues/il2cpp-build-fails-when-using-an-assembly-renamed-via-sentrys-assembly-alias-tool

ghost commented 2 years ago

Even though the fix is still shown as in review for 2022.1.12f1, the release just now dropped, and contains the fix inside the release notes: https://unity3d.com/unity/whats-new/2022.1.12

IL2CPP: Fixed IL2CPP build failure when using Unbox instruction with generic by reference return type. (UUM-5942)

bitsandfoxes commented 2 years ago

@moonshinebot oh this is awesome! I didn't get around to checking the release notes yet, thanks for letting us know!

bitsandfoxes commented 2 years ago

Happy to confirm: The package now works with Unity 2022 and we've added it to CI to keep track of it: https://github.com/getsentry/sentry-unity/pull/927