Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bus error with release version #114

Closed
edemirkan opened this issue Mar 9, 2024 · 27 comments
Closed

Bus error with release version #114

edemirkan opened this issue Mar 9, 2024 · 27 comments
Labels

Comments

@edemirkan
Copy link

Hi,
Following up your advice here I compiled using latest code from master for my arm32v7 platform but getting the following error on startup;

Need For Speed II SE
  Wrapper v1.3.7
  Game    v1.1.4-cpp_r1
  OpenGL  ES 2
Application closed with a signal: 7
/storage/roms/ports/Need For Speed II SE.sh: line 59: 10846 Bus error               $GAMEDIR/nfs2se

Debug does not crash, runs - I haven't played much but looks stable, however super slow..

Need For Speed II SE
  Wrapper v1.3.7
  Game    v1.1.4-cpp_r1
  OpenGL  ES 2
arm_release_ver: g13p0-01eac0, rk_so_ver: 3

The only difference I see between release and debug is optimization flags and binary stripping.

	if [[ $BUILD_TYPE == "debug" ]]; then
		FLAGS="-O0 -g"
		CPP_LTO=""
		echo "Debug"
	else
		FLAGS="-O3 -DNDEBUG"
		echo "Release"

Any ideas what might be the issue ? Any suggestions what can I check further?

More info on my build environment;

[root@fe6716181bd6 workspace]# clang -v
clang version 16.0.6
Target: armv7l-unknown-linux-gnueabihf
Thread model: posix
InstalledDir: /usr/sbin
Found candidate GCC installation: /usr/sbin/../lib/gcc/armv7l-unknown-linux-gnueabihf/12.1.0
Selected GCC installation: /usr/sbin/../lib/gcc/armv7l-unknown-linux-gnueabihf/12.1.0
Candidate multilib: .;@m32
Selected multilib: .;@m32
[root@fe6716181bd6 workspace]# ld.lld -v
LLD 16.0.6 (compatible with GNU linkers)

I also attached a readelf dump of the release binary I compiled.

readelf.txt

@zaps166
Copy link
Owner

zaps166 commented Mar 10, 2024

Any ideas what might be the issue ? Any suggestions what can I check further?

Could you upload the "release" binary?

@zaps166 zaps166 added the bug label Mar 10, 2024
@zaps166
Copy link
Owner

zaps166 commented Mar 10, 2024

Ah and second thing, try compile in debug with flags: FLAGS="-Og -g" - if it crashes, upload it, too.

@edemirkan
Copy link
Author

Please find release attached

Need For Speed II SE
  Wrapper v1.3.8
  Game    v1.1.4-cpp_r1
  OpenGL  ES 2
arm_release_ver: g13p0-01eac0, rk_so_ver: 3
Joystick "retrogame_joypad" opened at system index: 0 at index: 0 at: /dev/input/event3
Application closed with a signal: 7
/storage/roms/ports/Need For Speed II SE.sh: line 59:  8024 Bus error               $GAMEDIR/nfs2se

nfs2se.zip

I'll check debug now...

@edemirkan
Copy link
Author

edemirkan commented Mar 10, 2024

Debug crashed too with FLAGS="-Og -g" . Please find attached the binary.

Need For Speed II SE
  Wrapper v1.3.8
  Game    v1.1.4-cpp_r1
  OpenGL  ES 2
arm_release_ver: g13p0-01eac0, rk_so_ver: 3
Joystick "retrogame_joypad" opened at system index: 0 at index: 0 at: /dev/input/event3
Application closed with a signal: 7
/storage/roms/ports/Need For Speed II SE.sh: line 59:  9813 Bus error               $GAMEDIR/nfs2se

nfs2se.debug.zip

FLAGS="-O0 -g" is still working, but super slow.

@zaps166
Copy link
Owner

zaps166 commented Mar 10, 2024

Hmm, I used your binary and completed one race on R-Pi 4 without problems. What should I do to reproduce? Any settings, gamepads, wheels?

@zaps166
Copy link
Owner

zaps166 commented Mar 10, 2024

Completed another race with gamepad.

@zaps166
Copy link
Owner

zaps166 commented Mar 10, 2024

Also tried on very old HTC Sensation Android phone - runs stable.

@zaps166
Copy link
Owner

zaps166 commented Mar 10, 2024

If you can crash -Og -g, try running through gdb and check bt and disassemble on crash.

@edemirkan
Copy link
Author

I see. I'm running this on a device called RGB30, which is based on a RK3566 SoC and running an OS called JELOS This port is installed through a tool called PortMaster There might all sorts of issues, my cpu/gpu acting weird, or buggy lib32 libs. Thanks for your help on testing this so far, and at least we were able set a baseline with rpi4 and verified this was a problem on my end. I'll try the gdb method you suggested and let you know of my findings.

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

Ok, I see.
Bus error is by misalignment of game data in this wrapper. Float numbers must have address divisible by 4 for ARM's VFP, but here it's not, that's why I copy them to aligned stack and use them there (volatile is doing the job, prevents compiler optimizing this part). But in your case there must be still an unaligned access somewhere. Maybe this CPU is more sensible to this?

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

When do you have crash? Just after loading a race?

@edemirkan
Copy link
Author

If I use the binary provided by Portmaster as is, I get a crash during the game, not on startup - after 30-40sec e.g the first downhill in Mediterranean track.
Here's the link to that binary. https://github.com/PortsMaster/PortMaster-New/blob/main/ports/nfs2se/nfs2se/nfs2se
Now I'm not sure how that's compiled, but I know it's using an older version of your code.

If I use the latest from the master and compile myself, as I posted the binaries above - the crash just happens on game startup - just black screen, and then nothing.

Referring to a previous issue I was able to run it, but getting a crash in the game during a race. Again using an older version of your game.

  Wrapper v1.3.0
  Game    v1.1.2-cpp_r5
  OpenGL  ES 2

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

Ok, I'll check if I can align floats/doubles, but tomorrow!

@porschemad911
Copy link

I'm not sure if this information is useful, but every bit might help.

@edemirkan is using a Rockchip BSP 4.19 kernel plus Mali GPU drivers and KMS/DRM with their Powkiddy RGB30 on JELOS.

I am using a 6.7 mainline Linux kernel plus Panfrost GPU drivers and Weston / Wayland with my Odroid Go Ultra on JELOS.

Using the same binary (older version plus texturing and GLES2 renderer fix cherry-picked) here: #112 (comment)

I do not have any crashes, runs perfectly, while @edemirkan gets crashes in-race.

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

@edemirkan @porschemad911 Could you check align branch? Please do not forget to update git submodule! The version is 1.1.4-cpp_r2.

@edemirkan
Copy link
Author

edemirkan commented Mar 11, 2024

I'll check your branch shortly. This following was what I got from debug -Og -g you previously asked.

(gdb) file ./nfs2se
Reading symbols from ./nfs2se...
(gdb) run
Starting program: /storage/roms/ports/nfs2se/nfs2se 
warning: Unable to determine the number of hardware watchpoints available.
warning: Unable to determine the number of hardware breakpoints available.
warning: Loadable section "" outside of ELF segments
  in /usr/lib32/libGLESv2.so.2
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
Need For Speed II SE
  Wrapper v1.3.8
  Game    v1.1.4-cpp_r1
  OpenGL  ES 2
[New Thread 0xf10441a0 (LWP 10425)]
[New Thread 0xec71b1a0 (LWP 10426)]
[New Thread 0xeb9fd1a0 (LWP 10431)]
arm_release_ver: g13p0-01eac0, rk_so_ver: 3
[New Thread 0xeafff1a0 (LWP 10435)]
[New Thread 0xea7fe1a0 (LWP 10437)]
[New Thread 0xe9ffd1a0 (LWP 10438)]
[New Thread 0xe97fc1a0 (LWP 10439)]
[New Thread 0xe8ffb1a0 (LWP 10440)]
[New Thread 0xe87fa1a0 (LWP 10441)]
[New Thread 0xe7eb11a0 (LWP 10443)]
[New Thread 0xe75271a0 (LWP 10444)]
[New Thread 0xe6c251a0 (LWP 10445)]
[New Thread 0xe63231a0 (LWP 10446)]
Joystick "retrogame_joypad" opened at system index: 0 at index: 0 at: /dev/input/event3

Thread 4 "nfs2se" received signal SIGBUS, Bus error.
[Switching to Thread 0xeb9fd1a0 (LWP 10431)]
Application::get64f<signed char*> (addr=0x7189d6 <_data+16478> "") at Cpp/NFS2SE.cpp:291
291	Cpp/NFS2SE.cpp: No such file or directory.
(gdb) 

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

This following was what I got from -Og -g

Bus error in get64f - hmm. Could you use execute bt and disassemble commands? Just for curiosity (I hope align branch will work...)

Edit: I removed get64f in align branch anyway 😄

@edemirkan
Copy link
Author

(gdb) bt
#0  Application::get64f<signed char*> (addr=0x7189d6 <_data+16478> "") at Cpp/NFS2SE.cpp:291
#1  0x006d40a0 in Game::_sub_4BC250 (this=this@entry=0x14951a8) at Cpp/NFS2SE.cpp:241721
#2  0x006be100 in Game::_sub_4B77E0 (this=this@entry=0x14951a8) at Cpp/NFS2SE.cpp:240662
#3  0x00673bf0 in Game::_sub_4A7028 (this=this@entry=0x14951a8) at Cpp/NFS2SE.cpp:228718
#4  0x00673914 in Game::_sub_488928 (this=0x14951a8) at Cpp/NFS2SE.cpp:197744
#5  0x006ee0f0 in Application::call<int> (this=this@entry=0x14951a8, addr=16478) at Cpp/NFS2SE.cpp:360
#6  0x00659f34 in Game::_sub_481590 (this=0x14951a8) at Cpp/NFS2SE.cpp:188494
#7  0x006ed23c in wrap_stdcall4 (game=..., func=0x659af4 <sub_481590(Game*)>, arg0=<optimized out>, arg1=<optimized out>, arg2=0, arg3=0) at Cpp/NFS2SE.cpp:248901
#8  0x006f059c in DispatchMessageA_wrap (this=0x7189d6 <_data+16478>, msg=<optimized out>) at User32.c:357
#9  0x006593a4 in Game::_sub_481080 (this=0x14951a8) at Cpp/NFS2SE.cpp:188402
#10 0x0041cca8 in threadFunction (data=0x1483d90) at Kernel32.c:230
#11 0xf7ee66e4 in ?? () from /usr/lib32/libSDL2-2.0.so.0
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
(gdb) disassemble
Dump of assembler code for function _ZN11Application6get64fIPaEEdT_:
   0x006edf14 <+0>:	sub	sp, sp, #8
=> 0x006edf18 <+4>:	ldrd	r0, [r0]
   0x006edf1c <+8>:	strd	r0, [sp]
   0x006edf20 <+12>:	vldr	d0, [sp]
   0x006edf24 <+16>:	add	sp, sp, #8
   0x006edf28 <+20>:	bx	lr
End of assembler dump.

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

So you have bus error on ldrd when copying from unaligned to aligned place 😅 I didn't expect that. It can be workarounded for sure, but let's try align branch and fix everything there (if it'll still crash somewhere e.g. on loading integers).

Edit: Maybe I shouldn't use union, but use volatile on byte array and copy it byte-by-byte 😄

@zaps166
Copy link
Owner

zaps166 commented Mar 11, 2024

The bus error comes from (compile with -O0):

int main()
{
    char data[16] = {}; // address of `data` is dividible at least by `4` on stach (compiler must ensure it)
    auto &f = *(float *)&data[1]; // `f` is a reference, address of `f` is not dividible by `4` which is needed here
    f = 123.0f; // bus error
    return 0;
}

@porschemad911
Copy link

porschemad911 commented Mar 12, 2024

Attached binary recompiled from align branch works fine, no crashes for me.

Log:

ogu_panfrost:~/roms/ports/nfs2se # cat ./log.txt 
'/storage/.nfs2se' -> '/roms/ports/nfs2se/conf/.nfs2se'
Need For Speed II SE
  Wrapper v1.3.8
  Game    v1.1.4-cpp_r2
  OpenGL  2
Joystick "GO-Ultra Gamepad" opened at system index: 0 at index: 0 at: /dev/input/event2

nfs2se.zip

@edemirkan how is it for you?

@zaps166
Copy link
Owner

zaps166 commented Mar 12, 2024

@porschemad911 Nice!
@edemirkan If it will crash in FnInl(void) fild(const T &val) function let me know with bt and disassmeble, so I'll do byte-by-byte copy tomorrow!

@edemirkan
Copy link
Author

edemirkan commented Mar 12, 2024

Good news on my end too. I was able to do a full 4 laps on Mediterranean track, and no crashes. Thank you so much for your help.

Need For Speed II SE
  Wrapper v1.3.8
  Game    v1.1.4-cpp_r2
  OpenGL  ES 2
arm_release_ver: g13p0-01eac0, rk_so_ver: 3
Joystick "retrogame_joypad" opened at system index: 0 at index: 0 at: /dev/input/event3

I'll continue testing, and update this issue if anything changes. Have a wonderful night!

@porschemad911
Copy link

porschemad911 commented Mar 12, 2024

@zaps166 As an aside, I notice you've removed the Joystick0Buttons setting in nfs2se.conf. Any particular reason for this? I was using it to disable d-pad buttons, ie 8 - 11 on my device:

Joystick0Buttons=0,1,2,3,4,5,6,7,-1,-1,-1,-1,12,13,14

I then assigned these d-pad buttons to keyboard arrow keys via the gptokeyb keyboard mapper. This just made it easy to navigate menus with the d-pad but use the analogue stick for steering via in-game axis mapping. The stick does work fine for menu navigation, but it's a bit clunky vs the d-pad.

Not a big deal of course, just wondering ... and thank you for all your work!

@zaps166
Copy link
Owner

zaps166 commented Mar 12, 2024

@porschemad911

As an aside, I notice you've removed the Joystick0Buttons setting in nfs2se.conf. Any particular reason for this? I was using it to disable d-pad buttons, ie 8 - 11 on my device:

I removed it when introduced 32 buttons fix (see #104). I thought it's no longer needed to map buttons, because 32 is enough, but I forgot it might be used to disable buttons 😅

I can restore it as Joystick0ButtonsEnabled=1,1,1,1,.... or provide something else like Joystick0DPad=1,4,6,8?


@edemirkan

Good to hear, thanks for testing!

@porschemad911
Copy link

porschemad911 commented Mar 12, 2024

@zaps166 Something like Joystick0DPad=1,4,6,8 would be perfect. From the name I'm guessing it would be automatically map these buttons to directional inputs in-game?

@zaps166
Copy link
Owner

zaps166 commented Mar 12, 2024

@porschemad911 Added as Joystick0DPadButtons and Joystick1DPadButtons!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants