Search Unity

Bug [solved][ il2cpp android] mmap(PROT_NONE) failed

Discussion in 'Linux' started by mariozhou, May 20, 2021.

  1. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23
    We use the docker image 'unityci/editor :ubuntu-2020.3.5f1-android-0.12.0' to build Android apk.
    And it suddenly built to fail and can stable reproducing the following error on only one of the docker machine.

    ===========================================================

    Android PostProcess task "Creating Android manifest" took 180.8314 ms
    DisplayProgressbar: Compiling resources
    Android PostProcess task "Compiling resources" took 4.0098 ms
    DisplayProgressbar: GenerateIl2cppPlatformProviders
    Android PostProcess task "GenerateIl2cppPlatformProviders" took 1.1844 ms
    DisplayProgressbar: IL2CPP
    mmap(PROT_NONE) failed
    Caught fatal signal - signo:6 code:-6 errno:0 addr:0x526
    Obtained 20 stack frames.
    #0 0x007f573fb72980 in (Unknown)
    #1 0x007f573f7adfb7 in (Unknown)
    #2 0x007f573f7af921 in (Unknown)
    #3 0x007f55e4aa8dbd in (Unknown)
    #4 0x007f55e4aa8e2a in (Unknown)
    #5 0x007f55e4aabf90 in (Unknown)
    #6 0x007f55e4aac35d in (Unknown)
    #7 0x007f55e4aac47c in (Unknown)
    #8 0x007f55e4aad328 in (Unknown)
    #9 0x007f55e4ab017b in (Unknown)
    #10 0x007f55e4ab0355 in (Unknown)
    #11 0x007f55e4a83251 in (Unknown)
    #12 0x007f55e4a387b3 in (Unknown)
    #13 0x007f55e4a3881a in (Unknown)
    #14 0x000000401ba0af in (Unknown)
    #15 0x00000041217f68 in Mono.Cecil.ModuleDefinition:ReadModule (Mono.Disposable`1<System.IO.Stream>,string,Mono.Cecil.ReaderParameters)
    #16 0x000000412f13ec in Mono.Cecil.BaseAssemblyResolver:GetAssembly (string,Mono.Cecil.ReaderParameters)
    #17 0x000000412f0b60 in Mono.Cecil.BaseAssemblyResolver:Resolve (Mono.Cecil.AssemblyNameReference,Mono.Cecil.ReaderParameters)
    #18 0x000000412f1f70 in UnityEditor.MonoAssemblyStripping/<>c__DisplayClass6_0:<ResolveAssemblyReferences>b__0 (Mono.Cecil.AssemblyNameReference)
    #19 0x000000412eff2c in UnityEditor.MonoAssemblyStripping:CollectAssembliesRecursive (System.Collections.Generic.IEnumerable`1<Mono.Cecil.AssemblyDefinition>)
    Aborted
    Build Unity Android_Apk fail
    Fail to run the plugin because of error(Process exited with an error: 1)
     
  2. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23
  3. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23
    Spending a lot of time trying to compile unity-2020.3-mbe without the compile option "USE_MUNMAP",but it never succeeded.(Endless compile errors and environment issues)

    So, I had to keep searching and finally found that it seemed to be related to the virtual memory setting of linux.

    (https://github.com/soedinglab/hh-suite/issues/104)
    (https://redis.io/topics/faq#backgro...-under-linux-even-if-i-have-a-lot-of-free-ram)

    The `sysctl vm.overcommit_memory` of the machine was set to 0, and could help if set to 1 (always overcommit) I guess.

    As I had no privilege to change the setting of the previous machine,I ran another machine with it set to 1, and repeatly run the build task over 100 times.

    The problem did not recur again,in an inelegant way.
     
  4. makomarkus

    makomarkus

    Joined:
    Oct 28, 2020
    Posts:
    61
    Wow that was a very frustrating - and seemingly random issue. Unfortunately overcommit_memory did not fix this issue for us. It seems to be related to
    vm.max_map_count
    which is by default set too low at ~65k.

    Fix:

    What fixed it for us was setting it to
    sysctl -w vm.max_map_count=262144


    Related reading:
    https://github.com/ivmai/bdwgc/issues/334

    Stacktrace

    Code (csharp):
    1. Android PostProcess task "Compiling resources" took 3499.2199 ms
    2. DisplayProgressbar: GenerateIl2cppPlatformProviders
    3. Android PostProcess task "GenerateIl2cppPlatformProviders" took 1.3032 ms
    4. DisplayProgressbar: IL2CPP
    5. mmap(PROT_NONE) failed
    6. Caught fatal signal - signo:6 code:-6 errno:0 addr:0x99
    7. Obtained 19 stack frames.
    8. #0  0x007f7194a02980 in (Unknown)
    9. #1  0x007f719463dfb7 in (Unknown)
    10. #2  0x007f719463f921 in (Unknown)
    11. #3  0x007f70602b7e01 in (Unknown)
    12. #4  0x007f70602b7e6e in (Unknown)
    13. #5  0x007f70602bafd4 in (Unknown)
    14. #6  0x007f70602bb23d in (Unknown)
    15. #7  0x007f70602bc32e in (Unknown)
    16. #8  0x007f70602bf1bf in (Unknown)
    17. #9  0x007f70602bf399 in (Unknown)
    18. #10 0x007f7060292293 in (Unknown)
    19. #11 0x007f70602477ff in (Unknown)
    20. #12 0x007f7060247866 in (Unknown)
    21. #13 0x000000417ce21f in (Unknown)
    22. #14 0x000000407f9338 in Mono.Cecil.ModuleDefinition:ReadModule (Mono.Disposable`1<System.IO.Stream>,string,Mono.Cecil.ReaderParameters)
    23. #15 0x0000004088c0d8 in Mono.Cecil.BaseAssemblyResolver:GetAssembly (string,Mono.Cecil.ReaderParameters)
    24. #16 0x00000040888830 in Mono.Cecil.BaseAssemblyResolver:Resolve (Mono.Cecil.AssemblyNameReference,Mono.Cecil.ReaderParameters)
    25. #17 0x00000041f97ef0 in UnityEditor.MonoAssemblyStripping/<>c__DisplayClass6_0:<ResolveAssemblyReferences>b__0 (Mono.Cecil.AssemblyNameReference)
    26. #18 0x00000041f962e4 in UnityEditor.MonoAssemblyStripping:CollectAssembliesRecursive (System.Collections.Generic.IEnumerable`1<Mono.Cecil.AssemblyDefinition>)
    27. Aborted (core dumped)
    28. Build failed, with exit code 134
     
    3dHomer and mariozhou like this.
  5. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23

    I just looked at my docker's environment variables and found that vm.max_map_count is already 262144
     
  6. mariozhou

    mariozhou

    Joined:
    Oct 18, 2019
    Posts:
    23

    I also checked the machine that was causing the problem before and found that vm.max_map_count was indeed 65530. you did a great job @makomarkus
     
  7. makomarkus

    makomarkus

    Joined:
    Oct 28, 2020
    Posts:
    61
    Nice!