Repository: godot
Issue: Can build Mono-enabled editor and templates on ARM, but only editor and unoptimized debug template work
Labels: bug,platform:linuxbsd,topic:dotnet

<!-- Please search existing issues for potential duplicates before filing yours:
https://github.com/godotengine/godot/issues?q=is%3Aissue
-->

**Godot version:** 3.2.3.stable
<!-- Specify commit hash if using non-official build. -->


**OS/device including version:** Raspberry Pi 4, 4GB, GLES2
<!-- Specify GPU model, drivers, and the backend (GLES2, GLES3, Vulkan) if graphics-related. -->


**Issue description:** I am trying to build Godot with Mono for the Raspberry Pi. It's necessary to build templates from source, as mono is bundled with Godot, and Mono needs to correspond to the cpu arch. In case of the Pi the arch is ARM for which official export templates do not (as far as i know) exist. 
Following the documentation, I am able to build the Editor (tools) as well as debug, release_debug and release templates with Mono enabled. 
The editor runs perfectly, and I can run a sample project from there. 
Exporting seems to work as well, however the resulting binary does not runs _unless_ I  export with "Export with Debug" checked. 
If I copy the template files and data folders to my workstation and reference them as Custom Templates, the resulting files also do not run. 
Here's an output example:
```
Godot Engine v3.2.3.stable.mono.custom_build.31d0f8ad8 - https://godotengine.org
OpenGL ES 2.0 Renderer: llvmpipe (LLVM 9.0.1, 128 bits)
OpenGL ES 2.0 Batching: ON
 
Mono: Log file is: '/home/pi/.local/share/godot/app_userdata/TestProject/mono/mono_logs/2020_12_18 10.26.33 (2104).txt'
ERROR: _load_api_assemblies: The assembly 'GodotSharp' is out of sync.
   At: modules/mono/mono_gd/gd_mono.cpp:954.
ERROR: _load_api_assemblies: FATAL: Method failed.
   At: modules/mono/mono_gd/gd_mono.cpp:965.

=================================================================
	Native Crash Reporting
=================================================================
Got a SIGILL while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
/proc/self/maps:
00010000-03421000 r-xp 00000000 b3:02 263293     /home/pi/Documents/precompiled/debug/TestProject.x86
03430000-034a8000 r--p 03410000 b3:02 263293     /home/pi/Documents/precompiled/debug/TestProject.x86
034a8000-034b3000 rw-p 03488000 b3:02 263293     /home/pi/Documents/precompiled/debug/TestProject.x86
034b3000-034c1000 rw-p 00000000 00:00 0 
040c1000-0509a000 rw-p 00000000 00:00 0          [heap]
a4792000-a4bfe000 rw-p 00000000 00:00 0 
a4db6000-a4ffe000 rw-p 00000000 00:00 0 
a53ff000-a5bff000 rw-p 00000000 00:00 0 
a5bff000-a5c00000 ---p 00000000 00:00 0 
a5c00000-a6800000 rw-p 00000000 00:00 0 
a694f000-a6b24000 rw-p 00000000 00:00 0 
a6bf8000-a6bf9000 ---p 00000000 00:00 0 
a6bf9000-ab9ff000 rw-p 00000000 00:00 0 
ab9ff000-aba00000 ---p 00000000 00:00 0 
aba00000-ac200000 rw-p 00000000 00:00 0 
ac200000-ac221000 rw-p 00000000 00:00 0 
ac221000-ac300000 ---p 00000000 00:00 0 
ac37c000-ac3fc000 rw-p 00000000 00:00 0 
ac400000-ac421000 rw-p 00000000 00:00 0 
ac421000-ac500000 ---p 00000000 00:00 0 
ac57c000-ac5fd000 rw-p 00000000 00:00 0 
ac5fd000-ac5fe000 ---p 00000000 00:00 0 
ac5fe000-acdfe000 rw-p 00000000 00:00 0 
acdfe000-acdff000 ---p 00000000 00:00 0 
acdff000-ad5ff000 rw-p 00000000 00:00 0 

=================================================================
	Basic Fault Adddress Reporting
=================================================================
Memory around native instruction pointer (0xda7f68):0xda7f58  03 30 8f e0 64 c0 9f e5 00 c0 8d e5 ca 72 71 eb  .0..d........rq.
0xda7f68  fe de ff e7 0d 00 00 ea 3c 00 9f e5 00 00 8f e0  ........<.......
0xda7f78  38 10 9f e5 01 10 8f e0 34 20 9f e5 34 30 9f e5  8.......4 ..40..
0xda7f88  03 30 8f e0 30 c0 9f e5 0c c0 8f e0 2c e0 9f e5  .0..0.......,...

=================================================================
	Native stacktrace:
=================================================================
	 (No frames) 


=================================================================
	Telemetry Dumper:
=================================================================
Pkilling 0xa6cf8370 from 0xb6fba010
Entering thread summarizer pause from 0xb6fba010
Finished thread summarizer pause from 0xb6fba010.

Waiting for dumping threads to resume

=================================================================
	External Debugger Dump:
=================================================================
[New LWP 2105]
[New LWP 2124]
[New LWP 2125]
[New LWP 2126]
[New LWP 2127]
[New LWP 2128]
[New LWP 2129]
[New LWP 2130]
[New LWP 2131]
[New LWP 2132]
[New LWP 2133]
[New LWP 2134]
[New LWP 2135]
[New LWP 2136]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/arm-linux-gnueabihf/libthread_db.so.1".
__waitpid (options=0, stat_loc=0xbee1c938, pid=2138) at ../sysdeps/unix/sysv/linux/waitpid.c:30
30	../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
  Id   Target Id                                      Frame 
* 1    Thread 0xb6fba010 (LWP 2104) "TestProject.x86" __waitpid (options=0, stat_loc=0xbee1c938, pid=2138) at ../sysdeps/unix/sysv/linux/waitpid.c:30
  2    Thread 0xb573f370 (LWP 2105) "TestProject.x86" 0xb6718088 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=1, futex_word=0x4133f54) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
  3    Thread 0xb0557370 (LWP 2124) "llvmpipe-0"      futex_wait_cancelable (private=0, expected=0, futex_word=0x41d55d4) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  4    Thread 0xafd56370 (LWP 2125) "llvmpipe-1"      futex_wait_cancelable (private=0, expected=0, futex_word=0x41d56dc) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  5    Thread 0xaf3ff370 (LWP 2126) "llvmpipe-2"      futex_wait_cancelable (private=0, expected=0, futex_word=0x41d57e4) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  6    Thread 0xae9ff370 (LWP 2127) "llvmpipe-3"      futex_wait_cancelable (private=0, expected=0, futex_word=0x41d58ec) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  7    Thread 0xaddff370 (LWP 2128) "TestProject.x86" futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  8    Thread 0xad5fe370 (LWP 2129) "TestProject.x86" futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  9    Thread 0xacdfd370 (LWP 2130) "TestProject.x86" futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  10   Thread 0xac1ff370 (LWP 2131) "TestProject.x86" futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  11   Thread 0xaf555370 (LWP 2132) "TestProject.x86" 0xb6718088 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=1, futex_word=0x4453474) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
  12   Thread 0xaeb5d370 (LWP 2133) "TestProject.x86" __GI___nanosleep (remaining=0xaeb5cc98, requested_time=0xaeb5cc98) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
  13   Thread 0xae16b370 (LWP 2134) "TestProject.x86" __GI___nanosleep (remaining=0x0, requested_time=0xae16ac84) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
  14   Thread 0xa63ff370 (LWP 2135) "SGen worker"     futex_wait_cancelable (private=0, expected=0, futex_word=0xb6c098e8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
  15   Thread 0xa6cf8370 (LWP 2136) "Finalizer"       0xb6718088 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=1, futex_word=0xb6c01f90) at ../sysdeps/unix/sysv/linux/futex-internal.h:205

Thread 15 (Thread 0xa6cf8370 (LWP 2136)):
#0  0xb6718088 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=1, futex_word=0xb6c01f90) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
#1  do_futex_wait (sem=sem@entry=0xb6c01f90, abstime=0x0) at sem_waitcommon.c:115
#2  0xb67181f4 in __new_sem_wait_slow (sem=0xb6c01f90, abstime=0x0) at sem_waitcommon.c:282
#3  0xb6a973bc in ?? () from /usr/lib/libmonosgen-2.0.so.1
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 14 (Thread 0xa63ff370 (LWP 2135)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0xb6c098e8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0xb6c098c0) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0xb6c098c0, mutex=0x0) at pthread_cond_wait.c:655
#3  0xb6af1a18 in ?? () from /usr/lib/libmonosgen-2.0.so.1
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 13 (Thread 0xae16b370 (LWP 2134)):
#0  __GI___nanosleep (remaining=0x0, requested_time=0xae16ac84) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#1  __GI___nanosleep (requested_time=0xae16ac84, requested_time@entry=0xae16ac7c, remaining=remaining@entry=0x0) at ../sysdeps/unix/sysv/linux/nanosleep.c:25
#2  0xb6516fc0 in usleep (useconds=<optimized out>) at ../sysdeps/posix/usleep.c:32
#3  0x00d4b6e8 in JoypadLinux::monitor_joypads (this=0x4aa6420) at platform/x11/joypad_linux.cpp:216
#4  0x00d4b5b0 in JoypadLinux::run_joypad_thread (this=0x4aa6420) at platform/x11/joypad_linux.cpp:114
#5  0x00d4b268 in JoypadLinux::joy_thread_func (p_user=0x4aa6420) at platform/x11/joypad_linux.cpp:102
#6  0x015f45a4 in ThreadPosix::thread_callback (userdata=0x4aa6280) at drivers/unix/thread_posix.cpp:74
#7  0xb670e494 in start_thread (arg=0xae16b370) at pthread_create.c:486
#8  0xb651d578 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:73 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 12 (Thread 0xaeb5d370 (LWP 2133)):
#0  __GI___nanosleep (remaining=0xaeb5cc98, requested_time=0xaeb5cc98) at ../sysdeps/unix/sysv/linux/nanosleep.c:28
#1  __GI___nanosleep (requested_time=0xaeb5cc98, remaining=0xaeb5cc98) at ../sysdeps/unix/sysv/linux/nanosleep.c:25
#2  0x015eebe0 in OS_Unix::delay_usec (this=0xbee1ff98, p_usec=1000) at drivers/unix/os_unix.cpp:263
#3  0x015f64a0 in AudioDriverALSA::thread_func (p_udata=0xbee20200) at drivers/alsa/audio_driver_alsa.cpp:200
#4  0x015f45a4 in ThreadPosix::thread_callback (userdata=0x45152b8) at drivers/unix/thread_posix.cpp:74
#5  0xb670e494 in start_thread (arg=0xaeb5d370) at pthread_create.c:486
#6  0xb651d578 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:73 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 11 (Thread 0xaf555370 (LWP 2132)):
#0  0xb6718088 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=1, futex_word=0x4453474) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
#1  do_futex_wait (sem=sem@entry=0x4453474, abstime=0x0) at sem_waitcommon.c:115
#2  0xb67181f4 in __new_sem_wait_slow (sem=0x4453474, abstime=0x0) at sem_waitcommon.c:282
#3  0x015f4134 in SemaphorePosix::wait (this=0x4453470) at drivers/unix/semaphore_posix.cpp:41
#4  0x02808f24 in VisualServerScene::_gi_probe_bake_thread (this=0xadf73018) at servers/visual/visual_server_scene.cpp:2550
#5  0x02808ee8 in VisualServerScene::_gi_probe_bake_threads (self=0xadf73018) at servers/visual/visual_server_scene.cpp:2336
#6  0x015f45a4 in ThreadPosix::thread_callback (userdata=0x446a720) at drivers/unix/thread_posix.cpp:74
#7  0xb670e494 in start_thread (arg=0xaf555370) at pthread_create.c:486
#8  0xb651d578 in ?? () at ../sysdeps/unix/sysv/linux/arm/clone.S:73 from /lib/arm-linux-gnueabihf/libc.so.6
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 10 (Thread 0xac1ff370 (LWP 2131)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x4207180) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x4207180, mutex=0x0) at pthread_cond_wait.c:655
Backtrace stopped: Cannot access memory at address 0x5d18f2f8

Thread 9 (Thread 0xacdfd370 (LWP 2130)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x4207180) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x4207180, mutex=0x0) at pthread_cond_wait.c:655
Backtrace stopped: Cannot access memory at address 0x5d18f2f8

Thread 8 (Thread 0xad5fe370 (LWP 2129)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x4207180) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x4207180, mutex=0x0) at pthread_cond_wait.c:655
Backtrace stopped: Cannot access memory at address 0x5d18f2f8

Thread 7 (Thread 0xaddff370 (LWP 2128)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x42071a8) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x4207180) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x4207180, mutex=0x0) at pthread_cond_wait.c:655
Backtrace stopped: Cannot access memory at address 0x5d18f2f8

Thread 6 (Thread 0xae9ff370 (LWP 2127)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x41d58ec) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x41d58c0) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x41d58c0, mutex=0x0) at pthread_cond_wait.c:655
#3  0xb43352b0 in ?? () from /usr/lib/arm-linux-gnueabihf/dri/swrast_dri.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 5 (Thread 0xaf3ff370 (LWP 2126)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x41d57e4) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x41d57b8) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x41d57b8, mutex=0x0) at pthread_cond_wait.c:655
#3  0xb43352b0 in ?? () from /usr/lib/arm-linux-gnueabihf/dri/swrast_dri.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 4 (Thread 0xafd56370 (LWP 2125)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x41d56dc) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x41d56b0) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x41d56b0, mutex=0x0) at pthread_cond_wait.c:655
#3  0xb43352b0 in ?? () from /usr/lib/arm-linux-gnueabihf/dri/swrast_dri.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 3 (Thread 0xb0557370 (LWP 2124)):
#0  futex_wait_cancelable (private=0, expected=0, futex_word=0x41d55d4) at ../sysdeps/unix/sysv/linux/futex-internal.h:88
#1  __pthread_cond_wait_common (abstime=0x0, mutex=0x0, cond=0x41d55a8) at pthread_cond_wait.c:502
#2  __pthread_cond_wait (cond=0x41d55a8, mutex=0x0) at pthread_cond_wait.c:655
#3  0xb43352b0 in ?? () from /usr/lib/arm-linux-gnueabihf/dri/swrast_dri.so
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Thread 2 (Thread 0xb573f370 (LWP 2105)):
#0  0xb6718088 in futex_abstimed_wait_cancelable (private=0, abstime=0x0, expected=1, futex_word=0x4133f54) at ../sysdeps/unix/sysv/linux/futex-internal.h:205
#1  do_futex_wait (sem=sem@entry=0x4133f54, abstime=0x0) at sem_waitcommon.c:115
#2  0xb67181f4 in __new_sem_wait_slow (sem=0x4133f54, abstime=0x0) at sem_waitcommon.c:282
#3  0x015f4134 in SemaphorePosix::wait (this=0x4133f50) at drivers/unix/semaphore_posix.cpp:41
#4  0x02cd458c in _IP_ResolverPrivate::_thread_function (self=0x4133b20) at core/io/ip.cpp:101
#5  0x015f45a4 in ThreadPosix::thread_callback (userdata=0x41329c0) at drivers/unix/thread_posix.cpp:74
#6  0xb670e494 in start_thread (arg=0xb573f370) at pthread_create.c:486
Backtrace stopped: Cannot access memory at address 0x3e0f5c20

Thread 1 (Thread 0xb6fba010 (LWP 2104)):
#0  __waitpid (options=0, stat_loc=0xbee1c938, pid=2138) at ../sysdeps/unix/sysv/linux/waitpid.c:30
#1  __waitpid (pid=2138, stat_loc=0xbee1c938, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:25
#2  0xb68fa858 in ?? () from /usr/lib/libmonosgen-2.0.so.1
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
ALSA lib pcm.c:8424:(snd_pcm_recover) underrun occurred
[Inferior 1 (process 2104) detached]

=================================================================
	Managed Stacktrace:
=================================================================
=================================================================
Aborted
```
<!-- What happened, and what was expected. -->


**Steps to reproduce:**
1. Clone Godot from git and checkout 3.2.3-stable on a Pi
2. Build:
    * `scons p=x11 tools=yes module_mono_enabled=yes mono_glue=no module_webm_enabled=no -j4`
    * `bin/godot.x11.tools.32.mono --generate-mono-glue modules/mono/glue/ --video-driver GLES2`
    * `scons p=x11 tools=no module_mono_enabled=yes mono_glue=yes module_webm_enabled=no -j4 target=release_debug `
    * `scons p=x11 tools=no module_mono_enabled=yes mono_glue=yes module_webm_enabled=no -j4 target=debug`
    * `scons p=x11 tools=no module_mono_enabled=yes mono_glue=yes module_webm_enabled=no -j4 target=release`
3. Symlink bin folder to `$HOME/.local/share/godot/templates/3.2.3.mono.stable
4. Export without debug on the Pi, or copy templates to other machine and export with them as Custom Templates
5. Run generated file on the Pi: `./TestProject.x86`

**Minimal reproduction project:** 
<!-- A small Godot project which reproduces the issue. Drag and drop a zip archive to upload it. -->
[TestProject.zip](https://github.com/godotengine/godot/files/5719513/TestProject.zip)