Skip to content

gdbserver crash on mips - Illegal instruction #51

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

Closed
patryk4815 opened this issue Apr 13, 2025 · 15 comments
Closed

gdbserver crash on mips - Illegal instruction #51

patryk4815 opened this issue Apr 13, 2025 · 15 comments
Labels
bug Something isn't working

Comments

@patryk4815
Copy link

patryk4815 commented Apr 13, 2025

Image
isa			: mips1 mips2 mips32r1 mips32r2
ASEs implemented	: mips16
Options implemented	: tlb 4kex 4k_cache 32fpr prefetch mcheck ejtag llsc dc_aliases perf_cntr_intr_bit mm_full
@patryk4815
Copy link
Author

patryk4815 commented Apr 13, 2025

@patryk4815
Copy link
Author

Image

Crash on FPU instruction.

LLM response:
The root cause:

  • The program you're running (likely gdbserver) was compiled with FPU instructions (e.g., sdc1, add.d, mov.d, etc.), which are not supported by your platform.
  • Your system is using soft-float (-msoft-float), meaning no hardware support for floating point operations.

@guyush1
Copy link
Owner

guyush1 commented Apr 14, 2025

Hmmm...
I had to do some guesswork, since gdbserver is compiled with a symbol-stripping option (i.e -s).

However, i am fairly certain that gdbserver called longjmp.
The reason for the crash seems to be because your cpu does not support 64-bit floating point operations.
This code emitted can be seen in libc's source code:

Image

It seems like a solution for your problem would be to use a different toolchain - one that comes with a libc that is compiled without this opcodes enabled. Unfortunately, simply passing -msoft-float isn't enough - since libc.a / libc.so comes pre-compiled...

@guyush1
Copy link
Owner

guyush1 commented Apr 14, 2025

Btw: if you could conpile gdbserver without the -s flag (simply remove it from build.sh), and then reproduce the crash - it would be helpful to make sure we are indeed crashing on longjmp

@patryk4815
Copy link
Author

I just manually compiled gdb+static musl with float=soft and it is working fine

@guyush1
Copy link
Owner

guyush1 commented Apr 14, 2025

Musl is good since its source code is better and probably does not contain the same problem

@guyush1
Copy link
Owner

guyush1 commented Apr 14, 2025

Btw, did you compile just gdbserver in static mode via musl? I tried changing our build scrupts to use musl instead of glibc to solve similar problems, but had problems with libexpat / libgmp that were tough to resolve, so it would be helpful to know if you managed to compile the whole thing via musl

@patryk4815
Copy link
Author

patryk4815 commented Apr 14, 2025

I just used nix:
nix build nixpkgs#pkgsCross.mips-linux-gnu.pkgsStatic.gdb

But I had to fix bug in gdb manually: https://sourceware.org/bugzilla/show_bug.cgi?id=21070
sed -i '[email protected]@asm/sgidefs.h@g' ./gdb/mips-linux-nat.c

@patryk4815
Copy link
Author

rust-lang/rust#34910 (comment)
🤔 looks like most of mips devices have only soft float?

@roddyrap roddyrap added the bug Something isn't working label May 2, 2025
@guyush1
Copy link
Owner

guyush1 commented May 2, 2025

@patryk4815
This should be fixed in our latest release now:
https://github.com/guyush1/gdb-static/releases/tag/v16.3-static

If anything still does not work, please reopen this :)

@guyush1 guyush1 closed this as completed May 2, 2025
@patryk4815
Copy link
Author

patryk4815 commented May 4, 2025

@guyush1 still same issue,

root@OpenWrt:~# /tmp/gdbserver 0:1234 /bin/sh
Illegal instruction

Crash at 0x21b04 offset

Image Image

@guyush1 guyush1 reopened this May 4, 2025
@guyush1
Copy link
Owner

guyush1 commented May 4, 2025

Hello, i will take a look at this soon-ish. It is probably related to setjmp yet again and can be resolved via using the proper compiler

@guyush1
Copy link
Owner

guyush1 commented May 4, 2025

Hello @patryk4815 , I think i have a solution for you.

I compiled gdbserver with a soft-float mips compiler. This should guarantee that the problematic inline assembly at longjmp (which is not effected by -msoft-float) is not present anymore, so no floating point operations will be performed in longjmp and cause you to crash.

Please try it and tell me if it works :).

gdbserver-mips-soft.zip

@patryk4815
Copy link
Author

patryk4815 commented May 4, 2025

Thanks works! :)

Image

@guyush1
Copy link
Owner

guyush1 commented May 9, 2025

Closing this since we found a solution. I might add a mips-sf (soft-float) variant if more people need it.

@guyush1 guyush1 closed this as completed May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants