1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice

4.6.3 IL2CPP Xcode build errors

Discussion in 'iOS and tvOS' started by helios, Feb 21, 2015.

  1. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    292
    Hello, I just upgraded to 4.6.3 (from 4.6.2) and when I build my project in Xcode I'm greeted with about 20 of the same error:

    "error: cast from pointer to smaller type 'il2cpp_array_size_t' (aka 'int') loses information"

    What gives? I had zero issues in 4.6.2. Many thanks.
     
  2. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    292
    Any ideas?
     
  3. Twistplay

    Twistplay

    Joined:
    Dec 6, 2012
    Posts:
    35
    I would like to know an answer to this also, we're seeing this error too. Seems like a bug, I've created a fresh Xcode project from Unity and it still happens. IL2CPP but to just a 32-bit build does compile (not that we can submit to Apple with that ... but can at least play the game), it's the 64 bit pointer conversion that's breaking here.

    I'd log a bug with Unity, but getting a repro case of my project down to a reasonable size is not an easy task ...
     
  4. MrEsquire

    MrEsquire

    Joined:
    Nov 5, 2013
    Posts:
    2,615
    Is this a yellow warning error or red, cannot build Xcode error?
     
  5. Twistplay

    Twistplay

    Joined:
    Dec 6, 2012
    Posts:
    35
    Red.

    For example in Bulk_BouncyCastle.Crypto_12.cpp, the parts below highlighted in red give red exclamation marks in Xcode (legitimately, as far as I can see):

    {

    ByteU5BU5D_t12* L_0 = V_0;

    V_3 = L_0;

    int32_t L_1 = ((int32_t)(V_1/8));

    V_4.___m_value = (void*)L_1;

    NullCheck(V_3);

    IL2CPP_ARRAY_BOUNDS_CHECK(V_3, (il2cpp_array_size_t)V_4.___m_value);

    NullCheck(L_0);

    IL2CPP_ARRAY_BOUNDS_CHECK(L_0, L_1);

    *((uint8_t*)(uint8_t*)SZArrayLdElema(L_0, L_1)) = (uint8_t)(((uint8_t)((int32_t)((*(uint8_t*)(uint8_t*)SZArrayLdElema(V_3, (uint32_t)V_4.___m_value))|(((uint8_t)((int32_t)(1<<((int32_t)(((int32_t)(7-((int32_t)(V_1%8))))&((int32_t)31)))))))))));

    }
     
  6. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    292
    Yes, these are major errors, not warnings. Xcode won't build.
     
  7. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    292
    Twistplay, just to verify, which version of Unity are you using? This is happening to me on 4.6.3, but it worked perfectly fine in 4.6.2.
     
  8. Twistplay

    Twistplay

    Joined:
    Dec 6, 2012
    Posts:
    35
    Definitely 4.6.3
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    I've tracked down the cause of this problem, and I have corrected it internally. I've missed the cut-off for our 4.6.3p1 release, but this fix should land in the 4.6.3p2 release.

    In the meantime, you could try to work around the problem by modifying the generated C++ code. Unfortunately, each time you build the project in Unity, these problems will come back. Still to work around the issue, you can try this:

    Change:

    IL2CPP_ARRAY_BOUNDS_CHECK(V_3, (il2cpp_array_size_t)V_4.___m_value);

    to:

    IL2CPP_ARRAY_BOUNDS_CHECK(V_3, (il2cpp_array_size_t)(intptr_t)V_4.___m_value);

    And change:

    (uint32_t)V_4.___m_value)

    to:

    (uint32_t)(intptr_t)V_4.___m_value)


    There will likely be a number of occurrences of this problem though, so maybe some regulart expressions like this might help:

    s/(il2cpp_array_size_t)\(.*\)\.___m_value/(il2cpp_array_size_t)(intptr_t)\1.___m_value
    s/(uint32_t)\(.*\)\.___m_value/(uint32_t)(intptr_t)\1.___m_value

    The problem here is that clang is pretty strict during a 64-bit compile, not allowing any casts from a pointer (64-bits wide) to a narrower integer type (like a 32-bit int32_t). The fix first casts to a pointer-sized integer type (intptr_t), then casts down to a 32-bit integer.

    On the C# side, the code here is using an IntPtr to index into an array (the IntPtr is V_4, in this case). IL2CPP uses a void* (the ___m_value field) to store the value of the IntPtr. Obviously we could be losing something if the IntPtr used to index into the array actually has a value larger than the maximum value for a 32-bit integer. I think that case is pretty unlikely though, so this looks like a good fix.
     
    Dmitriy-Yukhanov likes this.
  10. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    292
    Thanks for the reply. Glad it's sorted out. There's a patch release roughly every week, right?
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    Yes, we're shipping weekly patch releases. The schedule can and sometimes does slip, but I would expect this fix near the end of next week.
     
  12. Twistplay

    Twistplay

    Joined:
    Dec 6, 2012
    Posts:
    35
    Hi Josh,

    This unfortunately does not fix all cases in 4.6.3p2 (but I can confirm the il2cpp_array_size_t errors seem to have gone in that patch)

    For example:

    uint8_t L_17 = GenArrayGet2(V_24, (int32_t)V_23.___m_value_0, 0, uint8_t);;

    Gives the error "Cast from pointer to smaller type 'int32_t' (aka 'int') loses information"

    I'm down to about 5 such errors in our project now ...

    For reference, the entire generated function looked like this:
    IL_0174:

    {

    ByteU5B0___U2C0___U5D_t2520* L_15 = V_4;

    V_24 = L_15;

    int32_t L_16 = V_11;

    V_23.___m_value_0 = (void*)L_16;

    NullCheck(V_24);

    uint8_t L_17 = GenArrayGet2(V_24, (int32_t)V_23.___m_value_0, 0, uint8_t);;

    IL2CPP_RUNTIME_CLASS_INIT(InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo));

    NullCheck(V_4);

    uint8_t L_18 = GenArrayGet2(V_4, ((int32_t)(((int32_t)(V_11+1))%4)), ((int32_t)(V_0-1)), uint8_t);;

    NullCheck((((RijndaelEngine_t2508_StaticFields*)InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo)->static_fields)->___S_4));

    IL2CPP_ARRAY_BOUNDS_CHECK((((RijndaelEngine_t2508_StaticFields*)InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo)->static_fields)->___S_4), ((int32_t)((int32_t)L_18&(int32_t)((int32_t)255))));

    int32_t L_19 = ((int32_t)((int32_t)L_18&(int32_t)((int32_t)255)));

    NullCheck(L_15);

    GenArraySet2(L_15, L_16, 0, (((uint8_t)((int32_t)((int32_t)L_17^(int32_t)(*(uint8_t*)(uint8_t*)SZArrayLdElema((((RijndaelEngine_t2508_StaticFields*)InitializedTypeInfo(&RijndaelEngine_t2508_il2cpp_TypeInfo)->static_fields)->___S_4), L_19)))))), uint8_t);;

    V_11 = ((int32_t)(V_11+1));

    }​

    In Bulk_BouncyCastle.Crypto_7.cpp


    Adrian
     
  13. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    I see the cases that I originally missed now, sorry. Is it possible for you to submit a bug with an example project? I would like to be able to make sure that we don't miss any other cases with the next fix. Thanks.
     
  14. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    Hello Josh,

    I have upgraded to 4.6.6p4 (from 4.6.2) and when I build my project in Xcode I'm getting similar issues.
    "Member reference base type 'intptr_t' (aka 'long') is not a structure or union"

    32bit build is working fine here.

    I attaching the screenshot of the error.

    What is the work around for this issue?
    Thanks
     

    Attached Files:

  15. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    I am stuck on this issues from last two weeks. latest 4.6.7 is also giving me the same error. anyone can help me on this?
     
  16. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    @c.rajiv.chandel

    Can you submit a bug report on this issue? If you submitted one previously, please let me know the bug report number, and I'll check on its status. Something here in the IL code is causing IL2CPP to generate bad C++ code, which we need to correct.
     
  17. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    I have not reported this issue. I am reporting it now. Thank you.
     
  18. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    Hello Josh,
    I have reported the bug report number:-
    "(Case 709995) We have created 32 bit using Unity 4.6.2 and to now we want to 64bit iOS build. We are getting this issue while compiling in it."

    Many Thanks.
     
  19. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    Hello Josh,

    Did you got time to look into this?
     
  20. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    @c.rajiv.chandel

    Thanks for submitting this bug. We've not yet had a chance to process it, but I'll ping our QA team to have a look.
     
  21. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    Ok thank you
     
  22. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    I shared some source code with you, for which you asked for. Case 711755. Please have look whenever you get time.
     
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    @c.rajiv.chandel

    Thanks, I've associated the two cases in our bug tracking system. We will investigate them.
     
  24. c-rajiv-chandel

    c-rajiv-chandel

    Joined:
    Nov 19, 2012
    Posts:
    30
    Thank you very much! I hope this will get resolved or you can guide me with alternative solution for this.
     
  25. L05TTTTTT

    L05TTTTTT

    Joined:
    Mar 23, 2016
    Posts:
    2
    When I upgrade Xcode to 7.3, it appears this problem,Please have look whenever you get time.
     

    Attached Files:

  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    @L05TTTTTT

    If you are on a 4.x version of Unity, you will need to use 4.7.1 to correct his issue. On 5.x, you will need to use Unity 5.3.1p4 or later. Apple changed the behavior of Xcode 7.3 for some C++ attributes, so Unity versions earlier than that will not work with Xcode 7.3.
     
  27. L05TTTTTT

    L05TTTTTT

    Joined:
    Mar 23, 2016
    Posts:
    2
    Thanks,i got it,

     
  28. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    95
    I'm getting similar errors running Unity 5.4b25 with Xcode 7.3.1 (see attached image)
     

    Attached Files:

  29. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    95
    Here's the offending code:

    Code (csharp):
    1.  
    2.     public static string ExpandToString<T>(this IList<T> source, string delimiter = ",") where T : IComparable
    3.     {
    4.         StringBuilder stringBuilder = new StringBuilder();
    5.  
    6.         stringBuilder.AppendFormat("[List<{0}>({1}):{{", typeof(T).Name, source.Count);
    7.  
    8.         if(source.Count > 0)
    9.         {
    10.             for(int i = 0; i < source.Count; i++)
    11.             {
    12.                 T t = source[i];
    13.                 stringBuilder.AppendFormat("{0}{1}", t, i == (source.Count - 1) ? "" : ",");
    14.             }
    15.         }
    16.  
    17.         stringBuilder.Append("}]");
    18.  
    19.         return stringBuilder.ToString();
    20.     }
    21.  
     
  30. hogwash

    hogwash

    Joined:
    Oct 12, 2012
    Posts:
    95
    If I try and patch up those calls to cast to intptr_t first, then the IL2CPP crashes at runtime inside the call to StringBuilder.AppendFormat
     
  31. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    @hogwash

    This certainly looks like a bug on the Unity side that we need to correct. Can you submit a bug report and let me know the bug number?
     
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    2,549
    @hogwash

    I've just tried this code snippet locally with our latest code, and it does convert and compile correctly, so I might be missing something in the case that you see. If we can get a bug report with a project that reproduces this, we will investigate it! Thanks.