danmons / mame_raspberrypi_cross_compile

MAME Cross Compile Environment
GNU General Public License v3.0
19 stars 2 forks source link

Mame 64 bit executable fails to run and compilation problems on the 32 bit version. #6

Closed marcomto closed 1 day ago

marcomto commented 2 months ago

Hello,

I successfully installed and got running the cross-compiler, downloaded the RPiOS libraries and tried to build both the 64 bit version and the 32 bit version of mame on Ubuntu 20.04 under a virtualbox machine. The 64 bit version compiles ok but when I run the mame (0.265) executable on my RPI 4 I get the error: required file is missing (I am running the 64 bit OS version on my raspberry pi 4).

On the other hand, trying to compile the 32 bit version I get all mame sources compiled, but when the mame executable is linking I get this error:

home/osboxes/x-tools/armv8-rpi4-linux-gnueabihf/lib/gcc/armv8-rpi4-linux-gnueabihf/10.4.0/../../../../armv8-rpi4-linux-gnueabihf/bin/ld.bfd: BFD (crosstool-NG 1.25.0) 2.35.1 assertion fail /home/osboxes/mame_raspberrypi_cross_compile/build/ctng_rpi_armhf/.build/armv8-rpi4-linux-gnueabihf/src/binutils/bfd/elf32-arm.c:9876
/home/osboxes/x-tools/armv8-rpi4-linux-gnueabihf/lib/gcc/armv8-rpi4-linux-gnueabihf/10.4.0/../../../../armv8-rpi4-linux-gnueabihf/bin/ld.bfd: BFD (crosstool-NG 1.25.0) 2.35.1 assertion fail /home/osboxes/mame_raspberrypi_cross_compile/build/ctng_rpi_armhf/.build/armv8-rpi4-linux-gnueabihf/src/binutils/bfd/elf32-arm.c:9876
/home/osboxes/x-tools/armv8-rpi4-linux-gnueabihf/lib/gcc/armv8-rpi4-linux-gnueabihf/10.4.0/../../../../armv8-rpi4-linux-gnueabihf/bin/ld.bfd: BFD (crosstool-NG 1.25.0) 2.35.1 assertion fail /home/osboxes/mame_raspberrypi_cross_compile/build/ctng_rpi_armhf/.build/armv8-rpi4-linux-gnueabihf/src/binutils/bfd/elf32-arm.c:9876
/home/osboxes/x-tools/armv8-rpi4-linux-gnueabihf/lib/gcc/armv8-rpi4-linux-gnueabihf/10.4.0/../../../../armv8-rpi4-linux-gnueabihf/bin/ld.bfd: BFD (crosstool-NG 1.25.0) 2.35.1 assertion fail /home/osboxes/mame_raspberrypi_cross_compile/build/ctng_rpi_armhf/.build/armv8-rpi4-linux-gnueabihf/src/binutils/bfd/elf32-arm.c:9876
/home/osboxes/x-tools/armv8-rpi4-linux-gnueabihf/lib/gcc/armv8-rpi4-linux-gnueabihf/10.4.0/../../../../armv8-rpi4-linux-gnueabihf/bin/ld.bfd: BFD (crosstool-NG 1.25.0) 2.35.1 assertion fail /home/osboxes/mame_raspberrypi_cross_compile/build/ctng_rpi_armhf/.build/armv8-rpi4-linux-gnueabihf/src/binutils/bfd/elf32-arm.c:9876
/home/osboxes/x-tools/armv8-rpi4-linux-gnueabihf/lib/gcc/armv8-rpi4-linux-gnueabihf/10.4.0/../../../../armv8-rpi4-linux-gnueabihf/bin/ld.bfd: BFD (crosstool-NG 1.25.0) 2.35.1 assertion fail /home/osboxes/mame_raspberrypi_cross_compile/build/ctng_rpi_armhf/.build/armv8-rpi4-linux-gnueabihf/src/binutils/bfd/elf32-arm.c:9876
collect2: error: ld returned 1 exit status
make[2]: *** [mame.make:269: ../../../../../mame] Error 1
make[1]: *** [Makefile:1123: mame] Error 2
make: *** [makefile:1300: linux] Error 2
Compressing...

I also downloaded the precompiled 64 bit version but it gives the same error as above. Not tried the 32 bit version because mame 0.265 is not there.

Any clue about my errors?

danmons commented 2 months ago

(64bit) required file is missing

This is probably a missing library. You can run ldd against the binary to find all the libraries that are missing, then go and install those. In general however, the following will install most of the dependencies you need (this should work for RPiOS/Debian/Armbian/Ubuntu):

sudo apt install -y libfreetype6 libsdl2-ttf-2.0-0 libsdl2-2.0-0 libqt5widgets5 libqt5gui5 libgl1

Once installed, try MAME again.

(32bit) when the mame executable is linking I get this error

I think this is potentially a change upstream with the MAME source code itself. There are issues under MAME's GitHub page talking about using other non-ld linkers (LLVM's lld, GNU's gold, etc), although I don't think crosstool-ng supports the ones they're suggesting. I need to do further testing.

With that said, MAME is also deprecating older dependencies and pushing for a newer minimum GCC level, which might make 32bit compilation impossible in future releases. I don't think that's a huge deal though, as more and more cheap ARM SBCs are coming out that are 64bit capable. But I'll do some investigation when I get a chance anyway. If you can run 64bit though, you should, as there's a 10-20% performance boost in doing so. RPi3 and newer hardware will all run 64bit Linux.

I've struggled to get 32bit MAME compiled/linked for a few releases now. Oddly enough the older Debian 10 Buster release for RPi2B worked, but the Debian 11 Bullseye release for 32bit RPi3 and 4 didn't.

I also need to re-do the tools for Debian 12 Bookworm as well, which I think will end up being 64bit only, but further testing is required.

marcomto commented 2 months ago

Hy Dan,

first of all thank you for your reply. I tried sudo apt install -y libfreetype6 libsdl2-ttf-2.0-0 libsdl2-2.0-0 libqt5widgets5 libqt5gui5 libgl1 with no luck (all already installed, latest version). Running lld against the mame executable gives me the error: not a dynamic executable However while running readelf -d mame | grep 'NEEDED' I get the following output:

0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libSDL2-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libutil.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libGL.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libasound.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libQt5Widgets.so.5]
 0x0000000000000001 (NEEDED)             Shared library: [libQt5Gui.so.5]
 0x0000000000000001 (NEEDED)             Shared library: [libQt5Core.so.5]
 0x0000000000000001 (NEEDED)             Shared library: [libpulse.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libX11.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXinerama.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libXext.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libXi.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libSDL2_ttf-2.0.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libfontconfig.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libfreetype.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

I tried to install all the dependent libraries but I currently have all of them. However none of the executables works (chdman, romcmp, castool..). I did some research and it appears that the difference in carriage return between Dos and Linus lead to the error bash: ./mame: cannot execute: required file not found but this is a binary file. Finally I can confirm, as you stated, that the older precompiled Debian 10 Buster release for RPi2B works well on my system.

marcomto commented 2 months ago

Hello Dan, this afternoon I installed Raspberry PI OS (64 bit) Bookworm and all the required libraries. Now it works. My compiled version of Mame 0.265 executes and runs fine. I also want to report that your compiling procedure also works on a 64 bit Debian virtual machine I created today. Thank you for your work.

All the best.

achton commented 1 month ago

This is probably a missing library.

@danmons I have this exact problem and want to understand why, so that I can cross compile the 32-bit version. Unfortunately, the linker error fails the build and does not produce a mame binary to analyze with readelf. I do get a castool binary, but the libraries it needs are already installed.

Any way for the script to provide more information about what might be causing the error?

With that said, MAME is also deprecating older dependencies and pushing for a newer minimum GCC level, which might make 32bit compilation impossible in future releases.

I've built an arcade cabinet with RetroPie on an RPi3 inside, and I feel that this may complicate things for me in the future, because RetroPie does not seem like a project that can easily pivot away from 32-bit support.

In fact, I found this issue because I am seeking support for a specific arcade game that was not properly supported in the MAME version I have installed currently, so I'm looking to install another version (mame2003-plus) alongside the first one.

danmons commented 2 days ago

I've made some progress toward fixing this for 32bit builds. It required a combination of switching linkers from ld to gold, and passing --long-plt.

I'll update this repo with changes in the coming days.

danmons commented 1 day ago

New version of the tools uploaded today. Initial tests have 32bit builds working for Debian 11 Bullseye and Debian 12 Bookworm. I'll close this older issue now, but if further issues come up, please open new ones.