Skip to content

[LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target #132688

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

Merged
merged 1 commit into from
Apr 9, 2025

Conversation

yingopq
Copy link
Contributor

@yingopq yingopq commented Mar 24, 2025

Now, because we do not support mips debugging, if we compile LLVM on mips target, would report error static assertion failed:Value mismatch for signal number SIGBUS, so add this condition to avoid error.

@yingopq yingopq requested a review from JDevlieghere as a code owner March 24, 2025 07:53
@llvmbot llvmbot added the lldb label Mar 24, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 24, 2025

@llvm/pr-subscribers-lldb

Author: None (yingopq)

Changes

MIPS changed the SIGBUS signal number to be the same as other architectures. So we would fail to compile llvm on mips. The relevant modification link is:
https://reviews.llvm.org/D146285


Full diff: https://github.com/llvm/llvm-project/pull/132688.diff

1 Files Affected:

  • (modified) lldb/source/Plugins/Process/Utility/LinuxSignals.cpp (+16-5)
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index eaecc84df15d4..aaada3b1e4c8f 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -61,10 +61,17 @@ void LinuxSignals::Reset() {
   AddSignal(5,      "SIGTRAP",      true,     true,   true,   "trace trap (not reset when caught)");
   AddSignal(6,      "SIGABRT",      false,    true,   true,   "abort()/IOT trap", "SIGIOT");
 
-  AddSignal(7,      "SIGBUS",       false,    true,   true,   "bus error");
-  ADD_SIGCODE(SIGBUS, 7, BUS_ADRALN, 1, "illegal alignment");
-  ADD_SIGCODE(SIGBUS, 7, BUS_ADRERR, 2, "illegal address");
-  ADD_SIGCODE(SIGBUS, 7, BUS_OBJERR, 3, "hardware error");
+#if defined(mips) || defined(__mips__) || defined(__mips)
+    AddSignal(10,      "SIGBUS",       false,    true,   true,   "bus error");
+    ADD_SIGCODE(SIGBUS, 10, BUS_ADRALN, 1, "illegal alignment");
+    ADD_SIGCODE(SIGBUS, 10, BUS_ADRERR, 2, "illegal address");
+    ADD_SIGCODE(SIGBUS, 10, BUS_OBJERR, 3, "hardware error");
+#else
+    AddSignal(7,      "SIGBUS",       false,    true,   true,   "bus error");
+    ADD_SIGCODE(SIGBUS, 7, BUS_ADRALN, 1, "illegal alignment");
+    ADD_SIGCODE(SIGBUS, 7, BUS_ADRERR, 2, "illegal address");
+    ADD_SIGCODE(SIGBUS, 7, BUS_OBJERR, 3, "hardware error");
+#endif
 
   AddSignal(8,      "SIGFPE",       false,    true,   true,   "floating point exception");
   ADD_SIGCODE(SIGFPE, 8, FPE_INTDIV, 1, "integer divide by zero");
@@ -77,7 +84,11 @@ void LinuxSignals::Reset() {
   ADD_SIGCODE(SIGFPE, 8, FPE_FLTSUB, 8, "subscript out of range");
 
   AddSignal(9,      "SIGKILL",      false,    true,   true,   "kill");
-  AddSignal(10,     "SIGUSR1",      false,    true,   true,   "user defined signal 1");
+#if defined(mips) || defined(__mips__) || defined(__mips)
+    AddSignal(7,     "SIGUSR1",      false,    true,   true,   "user defined signal 1");
+#else
+    AddSignal(10,     "SIGUSR1",      false,    true,   true,   "user defined signal 1");
+#endif
 
   AddSignal(11,     "SIGSEGV",      false,    true,   true,   "segmentation violation");
   ADD_SIGCODE(SIGSEGV, 11, SEGV_MAPERR,  1, "address not mapped to object", SignalCodePrintOption::Address);

@yingopq yingopq removed the request for review from JDevlieghere March 24, 2025 08:38
@DavidSpickett DavidSpickett changed the title [Mips] Fix signal number of SIGBUS on mips [LLDB][MIPS] Fix signal number of SIGBUS on mips Mar 25, 2025
@DavidSpickett
Copy link
Collaborator

MIPS changed the SIGBUS signal number to be the same as other architectures.

But your change appears to use different numbers for MIPS, which looks like the opposite.

Also please cite in the PR description the changes in the Linux Kernel that did this.

Also I'm pretty sure @labath removed a bunch of Linux MIPS support code at some point due to lack of use. So if you are about to add it all back, it would be good to know what your use case here is. Are you trying to get LLDB on MIPS Linux working again?

(we still support MIPS FreeBSD, though the latest FreeBSD release has dropped it)

ADD_SIGCODE(SIGBUS, 7, BUS_ADRALN, 1, "illegal alignment");
ADD_SIGCODE(SIGBUS, 7, BUS_ADRERR, 2, "illegal address");
ADD_SIGCODE(SIGBUS, 7, BUS_OBJERR, 3, "hardware error");
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that this code is also used in the lldb client, which may be built on a platform other than the target platform. For example, I can debug MIPS Linux remotely from a Mac OS host. It will need to be a runtime check in this case, and the compile time checks relaxed.

If this code only ever runs in lldb-server, then it could be fine.

@yingopq
Copy link
Contributor Author

yingopq commented Mar 26, 2025

MIPS changed the SIGBUS signal number to be the same as other architectures.

But your change appears to use different numbers for MIPS, which looks like the opposite.

Also please cite in the PR description the changes in the Linux Kernel that did this.

Also I'm pretty sure @labath removed a bunch of Linux MIPS support code at some point due to lack of use. So if you are about to add it all back, it would be good to know what your use case here is. Are you trying to get LLDB on MIPS Linux working again?

(we still support MIPS FreeBSD, though the latest FreeBSD release has dropped it)

There has a issue, when we compile LLVM of rust on mips, target we will face an error static assertion failed:Value mismatch for signal number SIGBUS, and after we revert https://reviews.llvm.org/D146285, can compile success; But this error did not occur on x86 target.
Check the file /usr/include/mipsel-linux-gnu/asm/signal.hon mips, the number is 10;
Check the file /usr/mips-linux-gnu/include/asm/signal.h on x86, the number is 7.

And now I did not has a clear test case, just found this problem when compiling.
So did we need to add check before ADD_SIGCODE(SIGBUS, 7, BUS_ADRALN, 1, "illegal alignment"); ?

@labath
Copy link
Collaborator

labath commented Mar 26, 2025

This needs to be a runtime instead of a build-time choice, because we support debugging foreign architectures, so I guess that what you need is more closer to reverting 93a4553.

However, your last comment makes me suspect you don't actually care about lldb+mips working, and just want to get rust building. Is that the case? If it is, then we may just want to make this build in that configuration, but not actually claim to support mips debugging (in theory, you should still be able to debug e.g. x86 core files with a mips build of lldb)

@labath
Copy link
Collaborator

labath commented Mar 26, 2025

If it is, then we may just want to make this build in that configuration, but not actually claim to support mips debugging (in theory, you should still be able to debug e.g. x86 core files with a mips build of lldb)

One way to do that would be to change #ifdef __linux__ on line 11 to #if defined(__linux__) && !defined(__mips__) and add a comment to say that this is because we don't support mips debugging.

@yingopq yingopq changed the title [LLDB][MIPS] Fix signal number of SIGBUS on mips [LLDB][MIPS] Fix signal SIGBUS number mismatch error on mips target Mar 31, 2025
Copy link

github-actions bot commented Mar 31, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Collaborator

@labath labath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I just tweaked the comment a bit. Please also update the endif comment on line 39.

Comment on lines 11 to 13
// Now, because we do not support mips debugging, if we compile LLVM on mips
// target, would report error `static assertion failed:Value mismatch for signal
// number SIGBUS`, so add this condition to avoid error.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Now, because we do not support mips debugging, if we compile LLVM on mips
// target, would report error `static assertion failed:Value mismatch for signal
// number SIGBUS`, so add this condition to avoid error.
// mips-linux debugging is not supported and mips uses different numbers for some signals (e.g. SIGBUS) on linux, so we skip the static checks below. The definitions here can be used for debugging non-mips targets on a mips-hosted lldb.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@labath please help review again, thanks!

Now, because we do not support mips debugging, if we compile LLVM
on mips target, would report error `static assertion failed:Value
mismatch for signal number SIGBUS`, so add this condition to avoid
error.
@labath
Copy link
Collaborator

labath commented Apr 9, 2025

The patch (still) looks good. I think what you need is for someone to push the submit button, so I'll do that now.

@labath labath merged commit 8877b91 into llvm:main Apr 9, 2025
10 checks passed
AllinLeeYL pushed a commit to AllinLeeYL/llvm-project that referenced this pull request Apr 10, 2025
…lvm#132688)

Now, because we do not support mips debugging, if we compile LLVM on
mips target, would report error `static assertion failed:Value mismatch
for signal number SIGBUS`, so add this condition to avoid error.
var-const pushed a commit to ldionne/llvm-project that referenced this pull request Apr 17, 2025
…lvm#132688)

Now, because we do not support mips debugging, if we compile LLVM on
mips target, would report error `static assertion failed:Value mismatch
for signal number SIGBUS`, so add this condition to avoid error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants