godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.2k stars 21.03k forks source link

Can't run an x86_32 game that was exported from an x86_64 bit host machine #80963

Closed fatduckling closed 4 months ago

fatduckling commented 1 year ago

Godot version

v4.1.1 bd6af8e0ea69167dd0627f3bd54f9105bda0f8b5

System information

Build machine: Debian GNU/Linux 11 (bullseye) 64 bit Testing machine: Debian GNU/Linux 12 (bookworm) 32 bit

Issue description

Hi,

I built a simple game with Godot 4.1.1 on my host machine Debian GNU/Linux 11 (bullseye) 64 bit. The game uses GDExtension. When I export the game to x86_64 and copy the files to another Linux x64 computer, it works fine. However, when I export the game to x86_32 architecture (while also compiling the C++ game library in x86_32 arch), and copy the files to a Linux x32 computer, I can't run the game. I get the following error on the 32 bit machine:

Godot Engine v4.1.1.stable.official.bd6af8e0e - https://godotengine.org
OpenGL API 4.5 (Core Profile) Mesa 22.3.6 - Compatibility - Using Device: Mesa/X.org - llvmpipe (LLVM 15.0.6, 256 bits)

================================================================
handle_crash: Program crashed with signal 8
Engine version: Godot Engine v4.1.1.stable.official (bd6af8e0ea69167dd0627f3bd54f9105bda0f8b5)
Dumping the backtrace. Please include this when reporting the bug to the project developer.
[1] linux-gate.so.1(__kernel_sigreturn+0) [0xb7f86564] (??:0)
[2] godot::ClassDB::bind_virtual_method(godot::StringName const&, godot::StringName const&, void (*)(void*, void const* const*, void*)) (??:0)
[3] void godot::ClassDB::_register_class<BoxObject2, false>(bool) (??:0)
[4] initialize_game_module(godot::ModuleInitializationLevel) (??:0)
[5] godot::GDExtensionBinding::initialize_level(void*, GDExtensionInitializationLevel) (??:0)
[6] ./game.x86_32() [0xabbe68c] (??:0)
[7] ./game.x86_32() [0x878e641] (??:0)
[8] ./game.x86_32() [0x86a4074] (??:0)
[9] /lib/i386-linux-gnu/libc.so.6(+0x232c5) [0xb7c232c5] (??:0)
[10] /lib/i386-linux-gnu/libc.so.6(__libc_start_main+0x88) [0xb7c23388] (??:0)
[11] ./game.x86_32() [0x86c6444] (??:0)
-- END OF BACKTRACE --
================================================================

In my host machine (x64), I make sure to set the binary format architecture to x86_32 (see screenshot): Screenshot from 2023-08-25 01-10-57

This is the contents of my game.gdextension

[configuration]

entry_symbol = "game_init_extension"
compatibility_minimum = 4.1

[libraries]

linux.x86_64 = "res://libGameLibrary64.so"
linux.x86_32 = "res://libGameLibrary32.so"

I've attached a sample reproducible game (with a simple C++ library) so you can test it.

Steps to reproduce

  1. Make sure you have godot-cpp set up for both Linux 32 and 64 bit libraries. https://github.com/godotengine/godot-cpp

  2. Download the reproducible project in this ticket

    Compile the simple game library

    I provided the 32 and 64 bit game library inside the game/ folder, but you can compile it yourself using the following commands:

    1. First, change set(GODOT_ROOT /home/saleem/software/godot/godot-cpp) in the CMakeLists.txt file to point to your godot-cpp installation path
    2. Compile the 32 bit library first:
      saleem@saleem-Z790:/tmp/Empty2$ mkdir build
      saleem@saleem-Z790:/tmp/Empty2$ cd build
      saleem@saleem-Z790:/tmp/Empty2/build$ cmake ..
      ...
      -- Build files have been written to: /tmp/Empty2/build
      saleem@saleem-Z790:/tmp/Empty2/build$ make -j23
      ...
      [100%] Linking CXX shared library libGameLibrary.so
      [100%] Built target GameLibrary
  3. This will produce a library libGameLibrary.so. Rename that libGameLibrary32.so and put that inside the game/ folder.

  4. Compile the 64 bit version. In the CMakeLists.txt, delete the lines associated with the -m32 and uncomment out the 64 bit lines so your CMakeLists.txt looks like this:

    
    ...
    set(CMAKE_CXX_FLAGS_RELEASE "-O3")

set(GODOT_LIBRARY ${GODOT_ROOT}/bin/libgodot-cpp.linux.template_debug.x86_64.a) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m64") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")

set(CMAKE_CXX_STANDARD 17) ...


Re-run `cmake` with the `make` command and rename the generated `.so` file to `libGameLibrary64.so` and put it inside the `game/` folder.
### Export the game
In the host machine (x64), export the game, both 64 and 32 bit versions and copy the generated game files to the respective architecture machines. You'll notice the 64 bit version works fine, but you'll see when you run the 32 bit version, you'll get the error. I'm just running Debian 11 x32 on Virtualbox to reproduce the error, but the issue also happens on my x32 laptop.

I understand that the reproducible steps are a bit challenging to follow, so I'm happy to assist developers with anything they need. Here is a **Video recording** of the steps to reproduce the issue:
[2023-08-25 02-12-16.mp4.zip](https://github.com/godotengine/godot/files/12431429/2023-08-25.02-12-16.mp4.zip)

### Minimal reproduction project

[Empty2.zip](https://github.com/godotengine/godot/files/12430864/Empty2.zip)
fatduckling commented 1 year ago

Here is the screenshot of the lscpu command on the 32 bit machine

Architecture:            i686
  CPU op-mode(s):        32-bit
  Address sizes:         39 bits physical, 48 bits virtual
  Byte Order:            Little Endian
CPU(s):                  2
  On-line CPU(s) list:   0,1
Vendor ID:               GenuineIntel
  Model name:            13th Gen Intel(R) Core(TM) i7-13700KF
    CPU family:          6
    Model:               183
    Thread(s) per core:  1
    Core(s) per socket:  2
    Socket(s):           1
    Stepping:            1
    BogoMIPS:            6835.19
    Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxs
                         r sse sse2 ht nx rdtscp constant_tsc xtopology nonstop_tsc cpuid tsc_known_freq pni pcl
                         mulqdq ssse3 cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lah
                         f_lm abm 3dnowprefetch pti fsgsbase bmi1 avx2 bmi2 invpcid rdseed clflushopt md_clear f
                         lush_l1d arch_capabilities
Virtualization features: 
  Hypervisor vendor:     KVM
  Virtualization type:   full
Caches (sum of all):     
  L1d:                   96 KiB (2 instances)
  L1i:                   64 KiB (2 instances)
  L2:                    4 MiB (2 instances)
  L3:                    60 MiB (2 instances)
Vulnerabilities:         
  Gather data sampling:  Not affected
  Itlb multihit:         KVM: Mitigation: VMX unsupported
  L1tf:                  Mitigation; PTE Inversion
  Mds:                   Mitigation; Clear CPU buffers; SMT Host state unknown
  Meltdown:              Mitigation; PTI
  Mmio stale data:       Unknown: No mitigations
  Retbleed:              Not affected
  Spec rstack overflow:  Not affected
  Spec store bypass:     Vulnerable
  Spectre v1:            Mitigation; usercopy/swapgs barriers and __user pointer sanitization
  Spectre v2:            Mitigation; Retpolines, STIBP disabled, RSB filling, PBRSB-eIBRS Not affected
  Srbds:                 Not affected
  Tsx async abort:       Not affected

Output of my export command:

~/software/godot/godot --headless --path /tmp/Empty2/game --export-release Release64 hello
Godot Engine v4.1.1.stable.official.bd6af8e0e - https://godotengine.org

WARNING: Custom cursor shape not supported by this display server.
     at: cursor_set_custom_image (servers/display_server.cpp:480)
WARNING: Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported.
     at: _editor_init (modules/gltf/register_types.cpp:73)
savepack: begin: Packing steps: 102
    savepack: step 2: Storing File: res://game.gdextension
    savepack: step 35: Storing File: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex
    savepack: step 35: Storing File: res://icon.svg.import
    savepack: step 68: Storing File: res://.godot/exported/133200997/export-6581cd44ca730c421bddc3302d6ce6cc-root.scn
    savepack: step 102: Storing File: res://root.tscn.remap
    savepack: step 102: Storing File: res://.godot/global_script_class_cache.cfg
    savepack: step 102: Storing File: res://icon.svg
    savepack: step 102: Storing File: res://.godot/uid_cache.bin
    savepack: step 102: Storing File: res://.godot/extension_list.cfg
    savepack: step 102: Storing File: res://project.binary
savepack: end
Enter tree
Ready
Exit tree
Enter tree
Exit tree
Segmentation fault
saleem@saleem-Z790:/tmp/Empty2/game$ ~/software/godot/godot --headless --path /tmp/Empty2/game --export-release Release32 hello
Godot Engine v4.1.1.stable.official.bd6af8e0e - https://godotengine.org

WARNING: Custom cursor shape not supported by this display server.
     at: cursor_set_custom_image (servers/display_server.cpp:480)
WARNING: Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported.
     at: _editor_init (modules/gltf/register_types.cpp:73)
savepack: begin: Packing steps: 102
    savepack: step 2: Storing File: res://game.gdextension
    savepack: step 35: Storing File: res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex
    savepack: step 35: Storing File: res://icon.svg.import
    savepack: step 68: Storing File: res://.godot/exported/133200997/export-6581cd44ca730c421bddc3302d6ce6cc-root.scn
    savepack: step 102: Storing File: res://root.tscn.remap
    savepack: step 102: Storing File: res://.godot/global_script_class_cache.cfg
    savepack: step 102: Storing File: res://icon.svg
    savepack: step 102: Storing File: res://.godot/uid_cache.bin
    savepack: step 102: Storing File: res://.godot/extension_list.cfg
    savepack: step 102: Storing File: res://project.binary
savepack: end
Enter tree
Ready
Exit tree
Enter tree
Exit tree
Segmentation fault
Mrcubix commented 1 year ago

This is not specific to linux

Windows is also affected, note that this happens with both GDScript and C#

Starting program: E:\Godot\Color Tiles\build\win-x86\Color-Tiles-win-x86.exe
[New Thread 14272.0x8a4]
[New Thread 14272.0x47b4]
[New Thread 14272.0x54d4]
[New Thread 14272.0x1b84]
[New Thread 14272.0x2e6c]
[New Thread 14272.0x1ae4]
[New Thread 14272.0x44c4]
[New Thread 14272.0x3c6c]
[New Thread 14272.0x1ebc]
[New Thread 14272.0x5928]
[New Thread 14272.0xdac]
[New Thread 14272.0x109c]
[New Thread 14272.0x5a34]
[New Thread 14272.0x32e4]
[New Thread 14272.0x3a54]
[New Thread 14272.0x1c90]
[New Thread 14272.0x1be4]
[New Thread 14272.0x2c64]
[New Thread 14272.0x4558]
Godot Engine v4.1.1.stable.mono.official.bd6af8e0e - https://godotengine.org
[New Thread 14272.0xd64]
[New Thread 14272.0x439c]
[New Thread 14272.0x2ba8]
[Thread 14272.0xd64 exited with code 0]
[Thread 14272.0x439c exited with code 0]
[Thread 14272.0x2ba8 exited with code 0]
[New Thread 14272.0x3838]
[New Thread 14272.0x954]
[New Thread 14272.0x3354]
[New Thread 14272.0x1ea0]
OpenGL API 3.3.0 NVIDIA 536.67 - Compatibility - Using Device: NVIDIA - NVIDIA GeForce GTX 1060 6GB
[New Thread 14272.0x5228]

[New Thread 14272.0x2390]
[New Thread 14272.0x54e0]
[New Thread 14272.0x25d0]
warning: Profiler was prevented from loading notification profiler due to app settings.
  Process ID (decimal): 14272.  Message ID: [0x2509].
[New Thread 14272.0x21dc]
[New Thread 14272.0x23ec]
[New Thread 14272.0x1d38]

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00000008 in ?? ()
(gdb) c
Continuing.

Thread 1 received signal SIGSEGV, Segmentation fault.
0x5d9d5a2e in coreclr_shutdown_2 () from E:\Godot\Color Tiles\build\win-x86\data_Color Tiles_x86_32\coreclr.dll
(gdb) c
Continuing.

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00000008 in ?? ()
(gdb) c
Continuing.
[Thread 14272.0x1b84 exited with code 3221225477]
[Thread 14272.0x47b4 exited with code 3221225477]
[Thread 14272.0x1ae4 exited with code 3221225477]
[Thread 14272.0x44c4 exited with code 3221225477]
[Thread 14272.0x54d4 exited with code 3221225477]
[Thread 14272.0x3c6c exited with code 3221225477]
[Thread 14272.0x1ebc exited with code 3221225477]
[Thread 14272.0xdac exited with code 3221225477]
[Thread 14272.0x109c exited with code 3221225477]
[Thread 14272.0x2e6c exited with code 3221225477]
[Thread 14272.0x5928 exited with code 3221225477]
[Thread 14272.0x3a54 exited with code 3221225477]
[Thread 14272.0x1c90 exited with code 3221225477]
[Thread 14272.0x1be4 exited with code 3221225477]
[Thread 14272.0x3838 exited with code 3221225477]
[Thread 14272.0x4558 exited with code 3221225477]
[Thread 14272.0x1ea0 exited with code 3221225477]
[Thread 14272.0x25d0 exited with code 3221225477]
[Thread 14272.0x2390 exited with code 3221225477]
[Thread 14272.0x1d38 exited with code 3221225477]
[Thread 14272.0x3354 exited with code 3221225477]
[Thread 14272.0x32e4 exited with code 3221225477]
[Thread 14272.0x954 exited with code 3221225477]
[Thread 14272.0x5228 exited with code 3221225477]
[Thread 14272.0x2c64 exited with code 3221225477]
[Thread 14272.0x54e0 exited with code 3221225477]
[Thread 14272.0x21dc exited with code 3221225477]
[Thread 14272.0x23ec exited with code 3221225477]
[Inferior 1 (process 14272) exited with code 030000000005]
fatduckling commented 10 months ago

Hi @Calinou After upgrading my project to 4.2 RC2, this seems to have been fixed. I'm able to compile on Debian 11 x64 using the -m32 flags and then run it on debian 11 x32

Edit: Also tried this using MinGW cross-compiler and I'm able to run both the x64 and x32 binaries on Windows. I think this can be closed now, thank you!

@Mrcubix Please confirm if the issue still persists for you on 4.2 RC2.

Mrcubix commented 10 months ago

Can't confirm as i don't have access to a 32 bits machine anymore

dsnopek commented 4 months ago

Seems like we can close this one now! If there are still any issues, we can re-open