Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Android IL2CPP clang++ crash

Discussion in '5.4 Beta' started by einWikinger, Mar 2, 2016.

  1. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    I know, IL2CPP for Android is currently unsupported, but for further stabilization I'd like to address this issue. I have a certain project that fails to compile with IL2CPP enabled because clang++ crashes. I'm building on Windows with the r10e 64bit NDK. I'm using the latest 5.4.0b7.

    The command line of the crashing clang++ instance is as follows:

    "D:\android-ndk-r10e\toolchains\llvm-3.6\prebuilt\windows\bin\clang++.exe" -cc1 -triple armv7-none-linux-androideabi -emit-obj -mrelax-all -mnoexecstack -disable-free -main-file-name Il2CppAttributes.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu cortex-a8 -target-feature +soft-float-abi -target-feature +neon -target-abi aapcs-linux -mfloat-abi soft -target-linker-version 2.24 -g -dwarf-column-info -ffunction-sections -fdata-sections -coverage-file "S:\UnityProject\Project\Temp/StagingArea\Il2Cpp\il2cppOutput\armeabi-v7a\Il2CppAttributes.o" -resource-dir "D:\android-ndk-r10e\toolchains\llvm-3.6\prebuilt\windows\bin\..\lib\clang\3.6" -D NDEBUG -I "U:\Unity 5.4.0b7\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\bdwgc/include" -I "U:\Unity 5.4.0b7\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\libil2cpp/include" -I "Temp/StagingArea\Il2Cpp\il2cppOutput" -I D:/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include -I D:/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -I D:/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isysroot D:/android-ndk-r10e/platforms/android-9/arch-arm -internal-isystem D:/android-ndk-r10e/platforms/android-9/arch-arm/usr/local/include -internal-isystem "D:\android-ndk-r10e\toolchains\llvm-3.6\prebuilt\windows\bin\..\lib\clang\3.6\include" -internal-externc-isystem D:/android-ndk-r10e/platforms/android-9/arch-arm/include -internal-externc-isystem D:/android-ndk-r10e/platforms/android-9/arch-arm/usr/include -O0 -std=c++11 -fdeprecated-macro -fdebug-compilation-dir "S:\UnityProject\Project" -ferror-limit 19 -fmessage-length 0 -fvisibility hidden -fvisibility-inlines-hidden -mstackrealign -fno-rtti -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o "Temp/StagingArea\Il2Cpp\il2cppOutput\armeabi-v7a\Il2CppAttributes.o" -x c++ "Temp/StagingArea\Il2Cpp\il2cppOutput\Il2CppAttributes.cpp"

    The Il2CppAttributes.cpp source file is nearly 27MB in size, maybe thats just too much for clang? It's using up nearly 1GB of RAM when it crashed.
    I also have a really relaxed link.xml file that preserves almost anything from the .net runtime:

    Code (csharp):
    1. <linker>
    2.     <assembly fullname="System" preserve="all" />
    3.     <assembly fullname="mscorlib" preserve="all" />
    4.     <assembly fullname="Mono.Security" preserve="all" />
    5. </linker>
    Maybe splitting up the generated attributes source file would improve the situation?

    I'd be glad to help out further!
     
    MrEsquire likes this.
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @einWikinger

    You may be correct about the cause of the issue, although I'm surprised that 64-bit clang would crash when using 1 GB of memory. Do you happen have an OSX machine available where you can try the same build? We've had better success with clang on OSX.

    In any case, can you submit a bug report and include this project? We should be able to split up Il2CppAttributes.cpp if indeed that is the source of the problems.
     
  3. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    Hey Josh! You were right, I incorrectly assumed it was the 64bit NDK, it actually was the 32bit. I've now installed the 64bit NDK on windows but now Unity won't go beyond the il2cpp conversion stage, crashing immediately.I don't get the crash reporter so I've submitted via the bug reporter (will note down the issue# as soon as I get the feedback mail).

    Looking into the logs it looks like Unity doesn't like the 64bit NDK, as it tries to launch the clang executeable from the 32bit NDK!

    System.ComponentModel.Win32Exception: ApplicationName='D:/android-ndk-r10e/toolchains/llvm-3.6/prebuilt/windows/bin/clang++', CommandLine='-c "Temp/StagingArea\Il2Cpp\il2cppOutput\Bulk_Generics_3.cpp" -o "Temp/StagingArea\Il2Cpp\il2cppOutput\armeabi-v7a\Bulk_Generics_3.o" --sysroot "D:/android-ndk-r10e/platforms/android-9/arch-arm" -gcc-toolchain "D:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/windows" -target armv7-none-linux-androideabi -O0 -fPIC -fdata-sections -ffunction-sections -Wa,--noexecstack -fno-rtti -std=c++11 -fstrict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -mfpu=neon -DNDEBUG -g -I "U:\Unity 5.4.0b7\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\bdwgc/include" -I "U:\Unity 5.4.0b7\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\libil2cpp/include" -I "Temp/StagingArea\Il2Cpp\il2cppOutput" -I "D:/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include" -I "D:/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/include/backward" -I "D:/android-ndk-r10e/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include"', CurrentDirectory=''

    /edit01: The Preference dialog will enforce downloading of the 32bit NDK, 64bit NDK isn't supported at all?
     
    Last edited: Mar 2, 2016
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @einWikinger

    I'm glad it is the same issue! Actually I've just learned from out Android team that Unity 5.3.3p2 (which should be out in the next day or so) will support the 64-bit NDK on Windows. So please give that build a try, and hopefully this problem will be resolved.
     
  5. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    I've "hacked" my NDK installation so Unity finds the 64bit clang binaries in the 32bit locations, and the clang crash is gone. So I assume this will go away when the 64bit NDK support is completed. Any ideas if it will come to the next 5.4 beta, too? Sadly, we have other issues with 5.3 that prevent us from using it and 5.2 has no IL2CPP support (yet?) :-/

    Yet, compilation of these huge C++ source files does take a while (test project with 10 classes with 2500 attributed fields each approx. 10 Minutes per ABI, 48MB sized Il2CppAttributes.cpp), so maaaaaaybe everyones build times would benefit by splitting them and have multiple clangs work in parallel ;-)
     
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @einWikinger

    Yes, this should be landing in a 5.4 beta soon, although it is not in 5.4b8, which was just released today. I don't think we will be making an more releases for 5.2 though.

    We're looking for way to speed up compilation times. Usually we see other files being compiled while Il2CppAttributes.cpp is compiling, so I'm not sure that splitting it up will help. Or do you see it compiling by itself when other clang processes are done?

    The best thing we can do soon for Android IL2CPP builds is support incremental C++ builds (we support them on WebGL and iOS now). That support should be coming soon I hope.
     
  7. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
    You're right, for a decent sized project that actually has code and not just 25 artificially crafted classes there may be other files that keep compiling. Although I remember that the attributes source file is getting compiled pretty late, after all the other files, surviving the others for a long time. Anyways, thanks for the quick support and clarification!
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @einWikinger

    Another option we've been considering internally (after looking at some compile-time profiling) is to eliminate this file altogether. We could write the information in this file into a binary that libil2cpp uses at runtime, which would prevent the C++ compiler from every having to parse it. That is a bit further off though, but it may be something we can do.
     
    fantastisch_ likes this.
  9. einWikinger

    einWikinger

    Joined:
    Jul 30, 2013
    Posts:
    97
  10. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @einWikinger

    Thanks for trying this and reporting the bug. I don't believe the 64-bit NDK landed in 5.4 yet, but it should be there soon.