summaryrefslogtreecommitdiff
path: root/system/gcc/sanitation.patch
blob: 984b604989195f2204170e35c67b3174e6bdffd2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
--- 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(...) \