Assertion Fail in elf32-arm.c:7827 when building for Android with IL2CPP

Hello,

I am trying to build my project with IL2CPP for Android, but I keep hitting strange issues and compiler errors that I have no idea how to fix or to even work out what could be causing them.

I have tried removing .NET assemblies from the project one by one, but it seems to be trigerred by the major one, which has a lot of dependencies and is very big on itself, so it takes long time to replicate (Unity’s bug report team complained about this and asked for a smaller version, but I just can’t reduce it any further, so I’m on my own).

Here’s what I found:

  • Happens with recent version of Unity (2018.1.9f)
  • Compiling the same codebase with IL2CPP for Windows works
  • The major library which triggers this doesn’t have any P/Invoke methods, its dependencies do
  • Compiling only the dependencies with link.xml works fine
  • Seems like a potential bug in the NDK itself, specifically the linker which fails
  • List item

The error output generates many assertion fails in the elf32-arm.c file on line 7827, the assert in that file is this:

BFD_ASSERT ((got_displacement & 0xf0000000) == 0);

(whole source here: binutils-2.25/bfd/elf32-arm.c - toolchain/binutils - Git at Google )

I’m not sure what this does though and what could be potentially even causing it in my own code. I’d appreciate it if anyone has any ideas where to look or how I could isolate this.

Here’s the error output from Unity Editor:

stdout:
Building libil2cpp.so with AndroidToolChain.
	Output directory: D:\Sync\Projects\Software\Applications\NeoS\Testing\IL2CPP_Bug3\Temp\StagingArea\assets\bin\Data\Native\armeabi-v7a
	Cache directory: D:\Sync\Projects\Software\Applications\NeoS\Testing\IL2CPP_Bug3\Library\il2cpp_android_armeabi-v7a\il2cpp_cache
ObjectFiles: 1665 of which compiled: 0
Total compilation time: 877 milliseconds.
il2cpp.exe didn't catch exception: Unity.IL2CPP.Building.BuilderFailedException: C:\android-ndk-r13b	oolchains\llvm\prebuilt\windows-x86_64\bin\clang++ @"C:\Users\Tomas\AppData\Local\Temp	mp5EF.tmp" -o "D:\Sync\Projects\Software\Applications\NeoS\Testing\IL2CPP_Bug3\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_F38F1A33880E1CAB2A23B46AA75CE1D0\libil2cpp.so" -shared -Wl,-soname,libil2cpp.so -Wl,--no-undefined -Wl,-z,noexecstack -Wl,--gc-sections -Wl,--build-id --sysroot "C:\android-ndk-r13b\platforms\android-16\arch-arm" -gcc-toolchain "C:\android-ndk-r13b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64" -target armv7-none-linux-androideabi -Wl,--wrap,sigaction -L "C:\android-ndk-r13b\sources\cxx-stl\gnu-libstdc++\4.9\libs\armeabi-v7a" -lgnustl_static -llog -Xlinker -Map="D:\Sync\Projects\Software\Applications\NeoS\Testing\IL2CPP_Bug3\Library\il2cpp_android_armeabi-v7a\il2cpp_cache\linkresult_F38F1A33880E1CAB2A23B46AA75CE1D0\libil2cpp.map" -rdynamic -fPIE -pie -fuse-ld=bfd.exe

clang++.exe: warning: argument unused during compilation: '-pie'
C:\android-ndk-r13b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.bfd.exe: BFD (binutils-2.25-0666073) 2.25.51.20141117 assertion fail /usr/local/google/buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.25/bfd/elf32-arm.c:7827
C:\android-ndk-r13b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.bfd.exe: BFD (binutils-2.25-0666073) 2.25.51.20141117 assertion fail /usr/local/google/buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.25/bfd/elf32-arm.c:7827
C:\android-ndk-r13b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.bfd.exe: BFD (binutils-2.25-0666073) 2.25.51.20141117 assertion fail /usr/local/google/buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.25/bfd/elf32-arm.c:7827

< This repeats for a few hundred lines >

C:\android-ndk-r13b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.bfd.exe: BFD (binutils-2.25-0666073) 2.25.51.20141117 assertion fail /usr/local/google/buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.25/bfd/elf32-arm.c:7827
C:\android-ndk-r13b	oolchains\arm-linux-androideabi-4.9\prebuilt\windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld.bfd.exe: BFD (binutils-2.25-0666073) 2.25.51.20141117 assertion fail /usr/local/google/buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.25/bfd/elf32-arm.c:7827
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)


   at Unity.IL2CPP.Building.CppProgramBuilder.PostprocessObjectFiles(IEnumerable`1 objectFiles, CppToolChainContext toolChainContext)
   at Unity.IL2CPP.Building.CppProgramBuilder.Build(IBuildStatistics& statistics)
   at Unity.IL2CPP.Building.Statistics.BuildingTestRunnerHelper.BuildAndLogStatsForTestRunner(CppProgramBuilder builder, IBuildStatistics& statistics)
   at il2cpp.Program.DoRun(String[] args)
   at il2cpp.Program.Run(String[] args)
   at il2cpp.Program.Main(String[] args)

This looks like a bug in the Android linker provided with the NDK. It might be worth submitting a bug report to Unity so that we can investigate it. In Unity 2018.3 (yet to be released) we’ve updated to a new version of the Android NDK, so that might be worth trying when the 2018.3 beta releases are available.