Skip to content

[compiler-rt][Mips] Fix mips SP register definition #124493

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 2 commits into from
Feb 11, 2025

Conversation

Gelbpunkt
Copy link
Contributor

The mainline Linux kernel defines EF_R29, not EF_REG29 1. Further, the asm/reg.h header requires _MIPS_SIM_* to be defined, which reside in asm/sgidefs.h 2.

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Jan 27, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Jens Reidel (Gelbpunkt)

Changes

The mainline Linux kernel defines EF_R29, not EF_REG29 1. Further, the asm/reg.h header requires _MIPS_SIM_* to be defined, which reside in asm/sgidefs.h 2.


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

1 Files Affected:

  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp (+23-24)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
index 945da99d41f4ea..95483cb79db263 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -37,25 +37,28 @@
 # include <asm/ptrace.h>
 #endif
 #include <sys/user.h>  // for user_regs_struct
-#if SANITIZER_ANDROID && SANITIZER_MIPS
-# include <asm/reg.h>  // for mips SP register in sys/user.h
-#endif
-#include <sys/wait.h> // for signal-related stuff
-
-#ifdef sa_handler
-# undef sa_handler
-#endif
-
-#ifdef sa_sigaction
-# undef sa_sigaction
-#endif
-
-#include "sanitizer_common.h"
-#include "sanitizer_flags.h"
-#include "sanitizer_libc.h"
-#include "sanitizer_linux.h"
-#include "sanitizer_mutex.h"
-#include "sanitizer_placement_new.h"
+#  if SANITIZER_MIPS
+// clang-format off
+#    include <asm/sgidefs.h>  // for _MIPS_SIM_* defines used in asm/reg.h
+#    include <asm/reg.h>      // for mips SP register in sys/user.h
+// clang-format on
+#  endif
+#  include <sys/wait.h>  // for signal-related stuff
+
+#  ifdef sa_handler
+#    undef sa_handler
+#  endif
+
+#  ifdef sa_sigaction
+#    undef sa_sigaction
+#  endif
+
+#  include "sanitizer_common.h"
+#  include "sanitizer_flags.h"
+#  include "sanitizer_libc.h"
+#  include "sanitizer_linux.h"
+#  include "sanitizer_mutex.h"
+#  include "sanitizer_placement_new.h"
 
 // Sufficiently old kernel headers don't provide this value, but we can still
 // call prctl with it. If the runtime kernel is new enough, the prctl call will
@@ -510,11 +513,7 @@ typedef pt_regs regs_struct;
 
 #elif defined(__mips__)
 typedef struct user regs_struct;
-# if SANITIZER_ANDROID
-#  define REG_SP regs[EF_R29]
-# else
-#  define REG_SP regs[EF_REG29]
-# endif
+#    define REG_SP regs[EF_R29]
 
 #elif defined(__aarch64__)
 typedef struct user_pt_regs regs_struct;

@Gelbpunkt
Copy link
Contributor Author

Ping

Copy link
Collaborator

@vitalybuka vitalybuka left a comment

Choose a reason for hiding this comment

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

Please undo reformat, or extract into a separate commit or PR

@vitalybuka vitalybuka requested a review from fmayer February 3, 2025 21:13
@Gelbpunkt
Copy link
Contributor Author

Please undo reformat, or extract into a separate commit or PR

Sorry, I was following https://llvm.org/docs/Contributing.html#how-to-submit-a-patch which says to use git clang-format HEAD~1 and amend the commit - I am a bit confused, is this not up to date anymore?

The mainline Linux kernel defines EF_R29, not EF_REG29 [1]. Further, the
asm/reg.h header requires _MIPS_SIM_* to be defined, which reside in
asm/sgidefs.h [2].

[1]: https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/reg.h#L151
[2]: https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/sgidefs.h#L33-L35

Signed-off-by: Jens Reidel <[email protected]>
@vitalybuka
Copy link
Collaborator

Please undo reformat, or extract into a separate commit or PR

Sorry, I was following https://llvm.org/docs/Contributing.html#how-to-submit-a-patch which says to use git clang-format HEAD~1 and amend the commit - I am a bit confused, is this not up to date anymore?

That's relevant, but it assume the pre-existing code is already clang formatted.

But there is "be an isolated change. Independent changes should be submitted as separate patches as this makes reviewing easier."

This file have legacy formatting, which we incrementally change to new format.
So we have 2 interdependent changes, format legacy code, and Mips change.

@vitalybuka vitalybuka merged commit c9f1d2c into llvm:main Feb 11, 2025
7 checks passed
Copy link

@Gelbpunkt Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@Gelbpunkt Gelbpunkt deleted the mips-sp-reg branch February 11, 2025 03:33
Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
The mainline Linux kernel defines EF_R29, not EF_REG29 [1]. Further, the
asm/reg.h header requires `_MIPS_SIM_*` to be defined, which reside in
asm/sgidefs.h [2].

[1]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/reg.h#L151
[2]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/sgidefs.h#L33-L35

---------

Signed-off-by: Jens Reidel <[email protected]>
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
The mainline Linux kernel defines EF_R29, not EF_REG29 [1]. Further, the
asm/reg.h header requires `_MIPS_SIM_*` to be defined, which reside in
asm/sgidefs.h [2].

[1]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/reg.h#L151
[2]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/sgidefs.h#L33-L35

---------

Signed-off-by: Jens Reidel <[email protected]>
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
The mainline Linux kernel defines EF_R29, not EF_REG29 [1]. Further, the
asm/reg.h header requires `_MIPS_SIM_*` to be defined, which reside in
asm/sgidefs.h [2].

[1]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/reg.h#L151
[2]:
https://github.com/torvalds/linux/blob/v6.13/arch/mips/include/uapi/asm/sgidefs.h#L33-L35

---------

Signed-off-by: Jens Reidel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants