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

Jens Reidel via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 7 11:40:00 PST 2025


https://github.com/Gelbpunkt updated https://github.com/llvm/llvm-project/pull/124493

>From 600589dfe91146ceba09a60dd60919ebb48c9f0f Mon Sep 17 00:00:00 2001
From: Jens Reidel <adrian at travitia.xyz>
Date: Sun, 26 Jan 2025 22:24:57 +0100
Subject: [PATCH 1/2] [compiler-rt][Mips] Fix mips SP register definition

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 <adrian at travitia.xyz>
---
 .../sanitizer_stoptheworld_linux_libcdep.cpp          | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

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 945da99d41f4eac..91a105c9203c606 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -37,8 +37,11 @@
 # 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
+#if SANITIZER_MIPS
+// clang-format off
+# include <asm/sgidefs.h>  // <asm/sgidefs.h> must be included before <asm/reg.h>
+# include <asm/reg.h>      // for mips SP register
+// clang-format on
 #endif
 #include <sys/wait.h> // for signal-related stuff
 
@@ -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
 
 #elif defined(__aarch64__)
 typedef struct user_pt_regs regs_struct;

>From ee356a76c44fe635013b0baa9603ea0c95584239 Mon Sep 17 00:00:00 2001
From: Jens Reidel <adrian at travitia.xyz>
Date: Fri, 7 Feb 2025 20:39:10 +0100
Subject: [PATCH 2/2] [compiler-rt][NFC] clang-format changes

Signed-off-by: Jens Reidel <adrian at travitia.xyz>
---
 .../sanitizer_stoptheworld_linux_libcdep.cpp  | 32 +++++++++----------
 1 file changed, 16 insertions(+), 16 deletions(-)

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 91a105c9203c606..b05c67e3544186a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
@@ -37,28 +37,28 @@
 # include <asm/ptrace.h>
 #endif
 #include <sys/user.h>  // for user_regs_struct
-#if SANITIZER_MIPS
+#  if SANITIZER_MIPS
 // clang-format off
 # include <asm/sgidefs.h>  // <asm/sgidefs.h> must be included before <asm/reg.h>
 # include <asm/reg.h>      // for mips SP register
 // clang-format on
-#endif
-#include <sys/wait.h> // for signal-related stuff
+#  endif
+#  include <sys/wait.h>  // for signal-related stuff
 
-#ifdef sa_handler
-# undef sa_handler
-#endif
+#  ifdef sa_handler
+#    undef sa_handler
+#  endif
 
-#ifdef sa_sigaction
-# undef sa_sigaction
-#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"
+#  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
@@ -513,7 +513,7 @@ typedef pt_regs regs_struct;
 
 #elif defined(__mips__)
 typedef struct user regs_struct;
-#  define REG_SP regs[EF_R29]
+#    define REG_SP regs[EF_R29]
 
 #elif defined(__aarch64__)
 typedef struct user_pt_regs regs_struct;



More information about the llvm-commits mailing list