[compiler-rt] r229656 - [MSan][MIPS] Fix for some failing tests on MIPS64

Mohit K. Bhakkad mohit.bhakkad at imgtec.com
Wed Feb 18 01:24:19 PST 2015


Author: mohit.bhakkad
Date: Wed Feb 18 03:24:19 2015
New Revision: 229656

URL: http://llvm.org/viewvc/llvm-project?rev=229656&view=rev
Log:
[MSan][MIPS] Fix for some failing tests on MIPS64

Enabling internal ptrace for mips, which fixes some
ptrace related tests. Along with this fixing some
other failures.

Reviewers: Reviewers: eugenis, kcc, samsonov

Subscribers: dsanders, sagar, lldb-commits

Differential Revision: http://reviews.llvm.org/D7332

Modified:
    compiler-rt/trunk/lib/msan/tests/msan_test.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
    compiler-rt/trunk/test/msan/mmap_below_shadow.cc
    compiler-rt/trunk/test/msan/strlen_of_shadow.cc
    compiler-rt/trunk/test/msan/vector_select.cc
    compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ptrace.cc

Modified: compiler-rt/trunk/lib/msan/tests/msan_test.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/tests/msan_test.cc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/tests/msan_test.cc (original)
+++ compiler-rt/trunk/lib/msan/tests/msan_test.cc Wed Feb 18 03:24:19 2015
@@ -2869,8 +2869,13 @@ static void GetPathToLoadable(char *buf,
   const char *last_slash = strrchr(program_path, '/');
   ASSERT_NE(nullptr, last_slash);
   size_t dir_len = (size_t)(last_slash - program_path);
-
+#if defined(__x86_64__)
   static const char basename[] = "libmsan_loadable.x86_64.so";
+#elif defined(__MIPSEB__) || defined(MIPSEB)
+  static const char basename[] = "libmsan_loadable.mips64.so";
+#elif defined(__mips64)
+  static const char basename[] = "libmsan_loadable.mips64el.so";
+#endif
   int res = snprintf(buf, sz, "%.*s/%s",
                      (int)dir_len, program_path, basename);
   ASSERT_GE(res, 0);
@@ -2920,7 +2925,7 @@ TEST(MemorySanitizer, dlopen) {
 
 // Regression test for a crash in dlopen() interceptor.
 TEST(MemorySanitizer, dlopenFailed) {
-  const char *path = "/libmsan_loadable_does_not_exist.x86_64.so";
+  const char *path = "/libmsan_loadable_does_not_exist.so";
   void *lib = dlopen(path, RTLD_LAZY);
   ASSERT_TRUE(lib == NULL);
 }

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common_syscalls.inc Wed Feb 18 03:24:19 2015
@@ -2297,7 +2297,8 @@ PRE_SYSCALL(ni_syscall)() {}
 POST_SYSCALL(ni_syscall)(long res) {}
 
 PRE_SYSCALL(ptrace)(long request, long pid, long addr, long data) {
-#if !SANITIZER_ANDROID && (defined(__i386) || defined (__x86_64))
+#if !SANITIZER_ANDROID && \
+    (defined(__i386) || defined(__x86_64) || defined(__mips64))
   if (data) {
     if (request == ptrace_setregs) {
       PRE_READ((void *)data, struct_user_regs_struct_sz);
@@ -2316,7 +2317,8 @@ PRE_SYSCALL(ptrace)(long request, long p
 }
 
 POST_SYSCALL(ptrace)(long res, long request, long pid, long addr, long data) {
-#if !SANITIZER_ANDROID && (defined(__i386) || defined (__x86_64))
+#if !SANITIZER_ANDROID && \
+    (defined(__i386) || defined(__x86_64) || defined(__mips64))
   if (res >= 0 && data) {
     // Note that this is different from the interceptor in
     // sanitizer_common_interceptors.inc.

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Wed Feb 18 03:24:19 2015
@@ -127,7 +127,7 @@
 #define SANITIZER_INTERCEPT_READDIR SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_READDIR64 SI_LINUX_NOT_ANDROID
 #define SANITIZER_INTERCEPT_PTRACE SI_LINUX_NOT_ANDROID && \
-   (defined(__i386) || defined (__x86_64))  // NOLINT
+   (defined(__i386) || defined (__x86_64) || defined (__mips64))  // NOLINT
 #define SANITIZER_INTERCEPT_SETLOCALE SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_GETCWD SI_NOT_WINDOWS
 #define SANITIZER_INTERCEPT_GET_CURRENT_DIR_NAME SI_LINUX_NOT_ANDROID

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.cc Wed Feb 18 03:24:19 2015
@@ -116,6 +116,9 @@
 #if SANITIZER_LINUX || SANITIZER_FREEBSD
 # include <utime.h>
 # include <sys/ptrace.h>
+# if defined(__mips64)
+#  include <asm/ptrace.h>
+# endif
 #endif
 
 #if !SANITIZER_ANDROID
@@ -139,6 +142,9 @@
 #include <sys/shm.h>
 #include <sys/statvfs.h>
 #include <sys/timex.h>
+#if defined(__mips64)
+# include <sys/procfs.h>
+#endif
 #include <sys/user.h>
 #include <sys/ustat.h>
 #include <linux/cyclades.h>
@@ -283,14 +289,19 @@ namespace __sanitizer {
 #endif
 
 #if SANITIZER_LINUX && !SANITIZER_ANDROID && \
-    (defined(__i386) || defined(__x86_64))
+    (defined(__i386) || defined(__x86_64) || defined(__mips64))
+#if defined(__mips64)
+  unsigned struct_user_regs_struct_sz = sizeof(struct pt_regs);
+  unsigned struct_user_fpregs_struct_sz = sizeof(elf_fpregset_t);
+#else
   unsigned struct_user_regs_struct_sz = sizeof(struct user_regs_struct);
   unsigned struct_user_fpregs_struct_sz = sizeof(struct user_fpregs_struct);
-#ifdef __x86_64
+#endif // __mips64
+#if (defined(__x86_64) || defined(__mips64))
   unsigned struct_user_fpxregs_struct_sz = 0;
 #else
   unsigned struct_user_fpxregs_struct_sz = sizeof(struct user_fpxregs_struct);
-#endif
+#endif // __x86_64 || __mips64
 
   int ptrace_peektext = PTRACE_PEEKTEXT;
   int ptrace_peekdata = PTRACE_PEEKDATA;

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_limits_posix.h Wed Feb 18 03:24:19 2015
@@ -695,7 +695,7 @@ namespace __sanitizer {
 #endif
 
 #if SANITIZER_LINUX && !SANITIZER_ANDROID && \
-    (defined(__i386) || defined(__x86_64))
+  (defined(__i386) || defined(__x86_64) || defined(__mips64))
   extern unsigned struct_user_regs_struct_sz;
   extern unsigned struct_user_fpregs_struct_sz;
   extern unsigned struct_user_fpxregs_struct_sz;

Modified: compiler-rt/trunk/test/msan/mmap_below_shadow.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/mmap_below_shadow.cc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/mmap_below_shadow.cc (original)
+++ compiler-rt/trunk/test/msan/mmap_below_shadow.cc Wed Feb 18 03:24:19 2015
@@ -15,8 +15,13 @@
 
 int main(void) {
   // Hint address just below shadow.
+#if defined(__x86_64__)
   uintptr_t hint = 0x4f0000000000ULL;
   const uintptr_t app_start = 0x600000000000ULL;
+#elif defined (__mips64)
+  uintptr_t hint = 0x4f00000000ULL;
+  const uintptr_t app_start = 0x6000000000ULL;
+#endif
   uintptr_t p = (uintptr_t)mmap(
       (void *)hint, 4096, PROT_WRITE,
       MAP_PRIVATE | MAP_ANONYMOUS | (FIXED ? MAP_FIXED : 0), -1, 0);

Modified: compiler-rt/trunk/test/msan/strlen_of_shadow.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/strlen_of_shadow.cc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/strlen_of_shadow.cc (original)
+++ compiler-rt/trunk/test/msan/strlen_of_shadow.cc Wed Feb 18 03:24:19 2015
@@ -9,7 +9,11 @@
 #include <string.h>
 
 const char *mem_to_shadow(const char *p) {
+#if defined(__x86_64__)
   return (char *)((uintptr_t)p & ~0x400000000000ULL);
+#elif defined (__mips64)
+  return (char *)((uintptr_t)p & ~0x4000000000ULL);
+#endif
 }
 
 int main(void) {

Modified: compiler-rt/trunk/test/msan/vector_select.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/vector_select.cc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/test/msan/vector_select.cc (original)
+++ compiler-rt/trunk/test/msan/vector_select.cc Wed Feb 18 03:24:19 2015
@@ -4,10 +4,18 @@
 // Regression test for MemorySanitizer instrumentation of a select instruction
 // with vector arguments.
 
+#if defined(__x86_64__)
 #include <emmintrin.h>
 
 __m128d select(bool b, __m128d c, __m128d d)
 {
   return b ? c : d;
 }
+#elif defined (__mips64)
+typedef double __w64d __attribute__ ((vector_size(16)));
 
+__w64d select(bool b, __w64d c, __w64d d)
+{
+  return b ? c : d;
+}
+#endif

Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ptrace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ptrace.cc?rev=229656&r1=229655&r2=229656&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ptrace.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/ptrace.cc Wed Feb 18 03:24:19 2015
@@ -8,6 +8,10 @@
 #include <sys/user.h>
 #include <sys/wait.h>
 #include <unistd.h>
+#if __mips64
+ #include <asm/ptrace.h>
+ #include <sys/procfs.h>
+#endif
 
 int main(void) {
   pid_t pid;
@@ -33,19 +37,23 @@ int main(void) {
       printf("%x\n", fpregs.mxcsr);
 #endif // __x86_64__
 
-#if __powerpc64__
+#if (__powerpc64__ || __mips64)
     struct pt_regs regs;
     res = ptrace((enum __ptrace_request)PTRACE_GETREGS, pid, NULL, &regs);
     assert(!res);
+#if (__powerpc64__)
     if (regs.nip)
       printf("%lx\n", regs.nip);
-
+#else
+    if (regs.cp0_epc)
+    printf("%lx\n", regs.cp0_epc);
+#endif
     elf_fpregset_t fpregs;
     res = ptrace((enum __ptrace_request)PTRACE_GETFPREGS, pid, NULL, &fpregs);
     assert(!res);
     if ((elf_greg_t)fpregs[32]) // fpscr
       printf("%lx\n", (elf_greg_t)fpregs[32]);
-#endif // __powerpc64__
+#endif // (__powerpc64__ || __mips64)
 
     siginfo_t siginfo;
     res = ptrace(PTRACE_GETSIGINFO, pid, NULL, &siginfo);





More information about the llvm-commits mailing list