ptitSeb / box64

Box64 - Linux Userspace x86_64 Emulator with a twist, targeted at ARM64 Linux devices
https://box86.org
MIT License
3.88k stars 281 forks source link

Exec format error with x86_64 file #433

Closed SillyFerretFuzz closed 2 years ago

SillyFerretFuzz commented 2 years ago

ark@rg353v:/roms2/ports/pokewilds$ box64 ./PokeWilds-x64 Box64 v0.1.9 fb7f134 built on Oct 25 2022 21:15:29 Using default BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/ Using default BOX64_PATH: ./:bin/ Counted 26 Env var Looking for ./PokeWilds-x64 Rename process to "PokeWilds-x64" Using native(wrapped) libdl.so.2 Using native(wrapped) libc.so.6 Using native(wrapped) ld-linux-x86-64.so.2 Using native(wrapped) libpthread.so.0 Using native(wrapped) librt.so.1 Using native(wrapped) libz.so.1 Using native(wrapped) libfuse.so.2 /tmp/.mount_PokeWiir58Wi/AppRun: 6: exec: pokewilds: Exec format error

I checked the type of file with the file command:

ark@rg353v:/roms2/ports/pokewilds$ file PokeWilds-x64 PokeWilds-x64: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=9b0b692e9674b12a987463ee5486fdf2a2d3ff1b, for GNU/Linux 2.6.32, stripped

However I do have the issue:

ark@rg353v:/roms2/ports/pokewilds$ systemctl status systemd-binfmt.service ● systemd-binfmt.service - Set Up Additional Binary Formats Loaded: loaded (/lib/systemd/system/systemd-binfmt.service; static; vendor preset: Active: failed (Result: exit-code) since Tue 2022-10-25 23:32:46 EDT; 9min ago Docs: man:systemd-binfmt.service(8) man:binfmt.d(5) https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems Process: 15556 ExecStart=/lib/systemd/systemd-binfmt (code=exited, status=1/FAILURE) Main PID: 15556 (code=exited, status=1/FAILURE)

I built directly on device and with a prebuilt dev, can't get binfmt to start

The device has an rk3568 chipset, 2gb ram

ptitSeb commented 2 years ago

This is an AppImage binary it seems. The issue is not PokeWilds.x64 that is launched correctly, but one of the program that is inside the AppImage: pokewilds Maybe it's a 32bits app and should need box86 to run (it should be detected if it installed, but need armhf subsystem). Try to extract the AppImage file to analyse the launched binary.

SillyFerretFuzz commented 2 years ago

I ran: box64 ./PokeWilds-x64 --appimage-extract

cd'd to squashfs-root/bin/ in the directory

Then: ark@rg353v:/roms2/ports/pokewilds/squashfs-root/bin$ file ./pokewilds ./pokewilds: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.18, not stripped

The only other things similarly named are in squashfs-root/lib/app/ with pokewilds.jar and .cfg

In /squashfs-root/ there is pokewilds.desktop

ptitSeb commented 2 years ago

can you run the extracted binary with box64?

SillyFerretFuzz commented 2 years ago

Is that done by executing squashfs-root/bin/pokewilds?

Looks like that does in fact execute with box 64 so I now have another issue to solve.

ark@rg353v:/roms2/ports/pokewilds/squashfs-root/bin$ box64 pokewilds Box64 v0.1.9 fb7f134 built on Oct 25 2022 21:15:29 Using default BOX64_LD_LIBRARY_PATH: ./:lib/:lib64/:x86_64/:bin64/:libs64/ Using default BOX64_PATH: ./:bin/ Counted 25 Env var Looking for pokewilds Rename process to "pokewilds" Using native(wrapped) libdl.so.2 Using native(wrapped) libc.so.6 Using native(wrapped) ld-linux-x86-64.so.2 Using native(wrapped) libpthread.so.0 Using native(wrapped) librt.so.1 Using emulated /roms2/ports/pokewilds/squashfs-root/lib/libapplauncher.so Using native(wrapped) libm.so.6 Warning: Weak Symbol _ZGTtnam not found, cannot apply R_X86_64_JUMP_SLOT @0x7fb8ea4628 (0x15026) Warning: Weak Symbol _ITM_RU1 not found, cannot apply R_X86_64_JUMP_SLOT @0x7fb8ea46e8 (0x151a6) Warning: Weak Symbol _ITM_memcpyRtWn not found, cannot apply R_X86_64_JUMP_SLOT @0x7fb8ea4778 (0x152c6) Warning: Weak Symbol _ITM_RU8 not found, cannot apply R_X86_64_JUMP_SLOT @0x7fb8ea4900 (0x155d6) Warning: Weak Symbol _ITM_memcpyRnWt not found, cannot apply R_X86_64_JUMP_SLOT @0x7fb8ea4958 (0x15686) Warning: Weak Symbol _ZGTtdlPv not found, cannot apply R_X86_64_JUMP_SLOT @0x7fb8ea49c0 (0x15756) Warning, resizing of TLS occured! size: 0->8192 / n_elfs: 1->1 Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/libjli.so Using native(wrapped) libz.so.1 Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/server/libjvm.so Warning: Global Symbol collector_func_load not found, cannot apply R_X86_64_GLOB_DAT @0x7fb7c85f60 ((nil)) in /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/server/libjvm.so Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/libjimage.so Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/libjava.so Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/libzip.so Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/libnio.so Using emulated /roms2/ports/pokewilds/squashfs-root/lib/runtime/lib/libnet.so Save path: /roms2/ports/pokewilds/squashfs-root/bin Using emulated /tmp/libgdxark/2d27742a/libgdx64.so Using emulated /tmp/lwjglark/3.3.1-SNAPSHOT/liblwjgl.so Using emulated /tmp/lwjglark/3.3.1-SNAPSHOT/libjemalloc.so Using emulated /tmp/lwjglark/3.3.1-SNAPSHOT/libglfw.so Using native(wrapped) libX11.so.6 Using native(wrapped) libwayland-client.so.0 [LWJGL] GLFW_PLATFORM_UNAVAILABLE error Description : Failed to detect any supported platform Stacktrace : org.lwjgl.glfw.GLFW.glfwInit(GLFW.java:1047) com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.initializeGlfw(Lwjgl3Application.java:88) com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration.getDisplayMode(Lwjgl3ApplicationConfiguration.java:219) com.pkmngen.game.desktop.DesktopLauncher.getScale(DesktopLauncher.java:104) com.pkmngen.game.desktop.DesktopLauncher.main(DesktopLauncher.java:18) Exception in thread "main" com.badlogic.gdx.utils.GdxRuntimeException: Unable to initialize GLFW at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.initializeGlfw(Lwjgl3Application.java:89) at com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration.getDisplayMode(Lwjgl3ApplicationConfiguration.java:219) at com.pkmngen.game.desktop.DesktopLauncher.getScale(DesktopLauncher.java:104) at com.pkmngen.game.desktop.DesktopLauncher.main(DesktopLauncher.java:18) #

A fatal error has been detected by the Java Runtime Environment:

#

SIGSEGV (0xb) at pc=0x0000007f8e31b3ff, pid=3522, tid=3537

#

JRE version: OpenJDK Runtime Environment Temurin-17.0.4.1+1 (17.0.4.1+1) (build 17.0.4.1+1)

Java VM: OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (17.0.4.1+1, mixed mode, tiered, compressed oops, compressed class ptrs, g1 gc, linux-amd64)

Problematic frame:

C [libjemalloc.so+0x4a3ff] je_malloc_usable_size+0x38eff

#

No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again

#

An error report file with more information is saved as:

/roms2/ports/pokewilds/squashfs-root/bin/hs_err_pid3522.log

#

If you would like to submit a bug report, please visit:

https://github.com/adoptium/adoptium-support/issues

#

ptitSeb commented 2 years ago

Ok, but that's another issue.

I would like to first understand why the AppImmage doesn't run first. can you run BOX64_LOG=2 box64 ./PokeWilds-x64 it will generate a lot of line of log. I'm interested in how it is trying to launch /tmp/.mount_PokeWiir58Wi/AppRun (the folder name will change, it's random), to understand why it's not using box64 to run it.

SillyFerretFuzz commented 2 years ago

This snippet? Apply Global R_X86_64_JUMP_SLOT 0x42d278 with sym=execv(ver 2: execv@GLIBC_2.2.5) (0x4054f6 -> 0x508a0 / (noelf)) return 0x7F93DAE060 7870|0x40604c: Calling my_execv (./PokeWilds-x64)(0x7F93DAE060, 0x9255E200, 0x1, ...) =>execv("/tmp/.mount_PokeWiSZIhzk/AppRun", 0x9255e200) is x64=0 x86=0 script=0 self=0 /tmp/.mount_PokeWiSZIhzk/AppRun: 6: exec: pokewilds: Exec format error

ptitSeb commented 2 years ago

Ah yes. So it's not detected as x64 binary :'(

What is /tmp/.mount_PokeWiSZIhzk/AppRun. It's bash script I guess, but what is the shebang (the first line starting with #!

SillyFerretFuzz commented 2 years ago

!/bin/sh

I really appreciate your help

ptitSeb commented 2 years ago

without space between the ! and then /?

SillyFerretFuzz commented 2 years ago

GNU nano 4.3 ./AppRun #!/bin/sh

I believe so? This is how it copies directly out of nano

ptitSeb commented 2 years ago

Ok, then that's why it's not detected. I'll add this shebang string to the detection...

SillyFerretFuzz commented 2 years ago

Do I just uninstall then rebuild later and try again?

ptitSeb commented 2 years ago

mmm, in fact, I was already looking for #!/bin/sh (without space), so not sure why it's not detected.

Anyway, I pushed something, so, please update box64 and try again

(to update, if you build occording to the COMPILE.md, simply do pushd ~/box64/build && git pull && make -j2 && sudo make install && popd and it should update, build and install the new version

SillyFerretFuzz commented 2 years ago

Updated and ran the log again:

13542|0x40604c: Calling my_execv (./PokeWilds-x64)(0x7F8C1DA070, 0x9098F0A0, 0x1, ...) =>execv("/tmp/.mount_PokeWiM3t94a/AppRun", 0x9098f0a0) is x64=0 x86=0 script=0 self=0 /tmp/.mount_PokeWiM3t94a/AppRun: 6: exec: pokewilds: Exec format error

ptitSeb commented 2 years ago

still not detected as a script :O I don't understand why. It's such a simple mater, and yet, it fails :'(

SillyFerretFuzz commented 2 years ago

I tried to be cheeky and use appimagetool-x86_64.AppImage to recompile with a new script that was #! /bin/sh/

But it ran into the exact same problem with the script within that tool

ptitSeb commented 2 years ago

I know what your issue is: you have not defined BOX64_BASH! You need to set this env. var. to the path of the x86_64 bash or it will not works. Look here https://box86.org/2022/09/running-bash-with-box86-box64/ for more details.

SillyFerretFuzz commented 2 years ago

Damn sure enough I thought I had set path but turns out I didn't.

Thanks so much for working through that with me.

ptitSeb commented 1 year ago

With latest box64, it seems to run much more stable now Screenshot from 2023-04-16 09-29-28