summaryrefslogblamecommitdiff
path: root/system/gcc/sanitation.patch
blob: 984b604989195f2204170e35c67b3174e6bdffd2 (plain) (tree)
1
2

                                                                                                           






































































                                                                                                       

















                                                                                


                                               



                                                

                                             
       

                                                                    


                                                 
                                             
       























































                                                                                                                                   



















                                                                                                                           
--- gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp.old	2024-05-21 02:47:42.000000000 -0500
+++ gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_linux.cpp	2024-07-24 15:56:06.119891718 -0500
@@ -82,6 +82,10 @@
 #  include <sys/sysmacros.h>
 #endif
 
+#if SANITIZER_LINUX && defined(__powerpc__)
+#  include <asm/ptrace.h>
+#endif
+
 #if SANITIZER_FREEBSD
 #include <sys/exec.h>
 #include <sys/procctl.h>
@@ -277,7 +281,7 @@
   return res;
 }
 
-#if (!SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_SPARC) && SANITIZER_LINUX
+#if (!SANITIZER_LINUX_USES_64BIT_SYSCALLS || SANITIZER_SPARC) && SANITIZER_LINUX && defined(__glibc__)
 static void stat64_to_stat(struct stat64 *in, struct stat *out) {
   internal_memset(out, 0, sizeof(*out));
   out->st_dev = in->st_dev;
@@ -384,11 +388,8 @@
   return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
                           0);
 #    else
-  struct stat64 buf64;
-  int res = internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path,
-                             (uptr)&buf64, 0);
-  stat64_to_stat(&buf64, (struct stat *)buf);
-  return res;
+  return internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path, (uptr)buf,
+                          0);
 #    endif
 #  else
   struct stat64 buf64;
@@ -416,11 +417,8 @@
   return internal_syscall(SYSCALL(newfstatat), AT_FDCWD, (uptr)path, (uptr)buf,
                           AT_SYMLINK_NOFOLLOW);
 #    else
-  struct stat64 buf64;
-  int res = internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path,
-                             (uptr)&buf64, AT_SYMLINK_NOFOLLOW);
-  stat64_to_stat(&buf64, (struct stat *)buf);
-  return res;
+  return internal_syscall(SYSCALL(fstatat64), AT_FDCWD, (uptr)path, (uptr)buf,
+                          AT_SYMLINK_NOFOLLOW);
 #    endif
 #  else
   struct stat64 buf64;
@@ -448,10 +446,7 @@
   return internal_syscall(SYSCALL(fstat), fd, (uptr)buf);
 #      endif
 #else
-  struct stat64 buf64;
-  int res = internal_syscall(SYSCALL(fstat64), fd, &buf64);
-  stat64_to_stat(&buf64, (struct stat *)buf);
-  return res;
+  return internal_syscall(SYSCALL(fstat64), fd, (uptr)buf);
 #endif
 }
 
@@ -871,7 +866,9 @@
 #endif
 
 #if SANITIZER_LINUX
-#define SA_RESTORER 0x04000000
+#  ifndef SA_RESTORER
+#    define SA_RESTORER 0x04000000
+#  endif
 // Doesn't set sa_restorer if the caller did not set it, so use with caution
 //(see below).
 int internal_sigaction_norestorer(int signum, const void *act, void *oldact) {
@@ -1677,6 +1674,8 @@
   return res;
 }
 #elif defined(__arm__)
+#pragma GCC push_options
+#pragma GCC optimize("omit-frame-pointer")
 uptr internal_clone(int (*fn)(void *), void *child_stack, int flags, void *arg,
                     int *parent_tidptr, void *newtls, int *child_tidptr) {
   unsigned int res;
@@ -1742,6 +1741,7 @@
                        : "memory");
   return res;
 }
+#pragma GCC pop_options
 #endif
 #endif  // SANITIZER_LINUX
 
@@ -2173,11 +2173,20 @@
   *bp = ucontext->uc_mcontext.mc_frame[31];
 #    else
   ucontext_t *ucontext = (ucontext_t*)context;
+#ifdef __powerpc64__
   *pc = ucontext->uc_mcontext.regs->nip;
   *sp = ucontext->uc_mcontext.regs->gpr[PT_R1];
+#else
+  *pc = ucontext->uc_mcontext.gregs[PT_NIP];
+  *sp = ucontext->uc_mcontext.gregs[PT_R1];
+#endif
   // The powerpc{,64}-linux ABIs do not specify r31 as the frame
   // pointer, but GCC always uses r31 when we need a frame pointer.
+#ifdef __powerpc64__
   *bp = ucontext->uc_mcontext.regs->gpr[PT_R31];
+#else
+  *bp = ucontext->uc_mcontext.gregs[PT_R31];
+#endif
 #    endif
 #elif defined(__sparc__)
 #if defined(__arch64__) || defined(__sparcv9)
--- gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp.old	2024-06-20 14:03:27.437916098 -0500
+++ gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp	2024-07-09 03:28:44.101087267 -0500
@@ -51,7 +51,7 @@
 #include <time.h>
 #include <wchar.h>
 #include <regex.h>
-#if !SANITIZER_APPLE
+#if HAVE_UTMP_H
 #include <utmp.h>
 #endif
 
@@ -62,7 +62,6 @@
 #if !SANITIZER_ANDROID
 #include <sys/mount.h>
 #include <sys/timeb.h>
-#include <utmpx.h>
 #endif
 
 #if SANITIZER_LINUX
@@ -94,7 +93,7 @@
 # include <utime.h>
 # include <sys/ptrace.h>
 #    if defined(__mips64) || defined(__aarch64__) || defined(__arm__) || \
-        defined(__hexagon__) || SANITIZER_RISCV64
+        defined(__hexagon__) || defined(__powerpc__) || SANITIZER_RISCV64
 #      include <asm/ptrace.h>
 #      ifdef __arm__
 typedef struct user_fpregs elf_fpregset_t;
@@ -313,11 +312,11 @@
   int shmctl_shm_stat = (int)SHM_STAT;
 #endif
 
-#if !SANITIZER_APPLE && !SANITIZER_FREEBSD
+#if HAVE_UTMP_H
   unsigned struct_utmp_sz = sizeof(struct utmp);
 #endif
 #if !SANITIZER_ANDROID
-  unsigned struct_utmpx_sz = sizeof(struct utmpx);
+  unsigned struct_utmpx_sz = 400;
 #endif
 
   int map_fixed = MAP_FIXED;
--- gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp.old	2024-05-21 02:47:42.000000000 -0500
+++ gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp	2024-06-20 16:23:27.115377319 -0500
@@ -31,7 +31,7 @@
 #include <sys/types.h> // for pid_t
 #include <sys/uio.h> // for iovec
 #include <elf.h> // for NT_PRSTATUS
-#if (defined(__aarch64__) || SANITIZER_RISCV64) && !SANITIZER_ANDROID
+#if (defined(__aarch64__) || defined(__powerpc__) || SANITIZER_RISCV64) && !SANITIZER_ANDROID
 // GLIBC 2.20+ sys/user does not include asm/ptrace.h
 # include <asm/ptrace.h>
 #endif
--- gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_syscall_linux_arm.inc.old	2024-05-21 02:47:42.000000000 -0500
+++ gcc-13.3.0/libsanitizer/sanitizer_common/sanitizer_syscall_linux_arm.inc	2024-07-24 15:56:06.129890658 -0500
@@ -12,6 +12,9 @@
 
 #define SYSCALL(name) __NR_ ## name
 
+#pragma GCC push_options
+#pragma GCC optimize("omit-frame-pointer")
+
 static uptr __internal_syscall(u32 nr) {
   register u32 r8 asm("r7") = nr;
   register u32 r0 asm("r0");
@@ -115,6 +118,7 @@
 #define __internal_syscall6(n, a1, a2, a3, a4, a5, a6) \
   (__internal_syscall)(n, (u32)(a1), (long)(a2), (long)(a3), (long)(a4), \
                        (u32)(a5), (long)(a6))
+#pragma GCC pop_options
 
 #define __SYSCALL_NARGS_X(a1, a2, a3, a4, a5, a6, a7, a8, n, ...) n
 #define __SYSCALL_NARGS(...) \