Enable libsanitizer build on mips64
authorXi Ruoyao <xry111@mengyan1223.wang>
Fri, 11 Mar 2022 03:07:00 +0000 (11:07 +0800)
committerXi Ruoyao <xry111@mengyan1223.wang>
Mon, 14 Mar 2022 16:39:47 +0000 (00:39 +0800)
Bootstrapped and regtested on mips64-linux-gnuabi64.

bootstrap-ubsan revealed 3 bugs (PR 104842, 104843, 104851).
bootstrap-asan did not reveal any new bug.

gcc/

* config/mips/mips.h (SUBTARGET_SHADOW_OFFSET): Define.
* config/mips/mips.cc (mips_option_override): Make
-fsanitize=address imply -fasynchronous-unwind-tables.  This is
needed by libasan for stack backtrace on MIPS.
(mips_asan_shadow_offset): Return SUBTARGET_SHADOW_OFFSET.

gcc/testsuite:

* c-c++-common/asan/global-overflow-1.c: Skip for MIPS with some
optimization levels because inaccurate debug info is causing
dg-output mismatch on line numbers.
* g++.dg/asan/large-func-test-1.C: Likewise.

libsanitizer/

* configure.tgt: Enable build on mips*64*-*-linux*.

gcc/config/mips/mips.cc
gcc/config/mips/mips.h
gcc/testsuite/c-c++-common/asan/global-overflow-1.c
gcc/testsuite/g++.dg/asan/large-func-test-1.C
libsanitizer/configure.tgt

index 4f9683e..a1c4b43 100644 (file)
@@ -19974,6 +19974,13 @@ mips_option_override (void)
        target_flags |= MASK_64BIT;
     }
 
+  /* -fsanitize=address needs to turn on -fasynchronous-unwind-tables in
+     order for tracebacks to be complete but not if any
+     -fasynchronous-unwind-table were already specified.  */
+  if (flag_sanitize & SANITIZE_USER_ADDRESS
+      && !global_options_set.x_flag_asynchronous_unwind_tables)
+    flag_asynchronous_unwind_tables = 1;
+
   if ((target_flags_explicit & MASK_FLOAT64) != 0)
     {
       if (mips_isa_rev >= 6 && !TARGET_FLOAT64)
@@ -22591,7 +22598,7 @@ mips_constant_alignment (const_tree exp, HOST_WIDE_INT align)
 static unsigned HOST_WIDE_INT
 mips_asan_shadow_offset (void)
 {
-  return 0x0aaa0000;
+  return SUBTARGET_SHADOW_OFFSET;
 }
 
 /* Implement TARGET_STARTING_FRAME_OFFSET.  See mips_compute_frame_info
index 0029864..858bbba 100644 (file)
@@ -3463,3 +3463,10 @@ struct GTY(())  machine_function {
    && !TARGET_MICROMIPS && !TARGET_FIX_24K)
 
 #define NEED_INDICATE_EXEC_STACK 0
+
+/* Define the shadow offset for asan. Other OS's can override in the
+   respective tm.h files.  */
+#ifndef SUBTARGET_SHADOW_OFFSET
+#define SUBTARGET_SHADOW_OFFSET \
+  (POINTER_SIZE == 64 ? HOST_WIDE_INT_1 << 37 : HOST_WIDE_INT_C (0x0aaa0000))
+#endif
index 1092a31..ec41223 100644 (file)
@@ -22,6 +22,7 @@ int main() {
   return res;
 }
 
+/* { dg-skip-if "inaccurate debug info" { mips*-*-* } { "*" } { "-O0" } } */
 /* { dg-output "READ of size 1 at 0x\[0-9a-f\]+ thread T0.*(\n|\r\n|\r)" } */
 /* { dg-output "    #0 0x\[0-9a-f\]+ +(in _*main (\[^\n\r]*global-overflow-1.c:20|\[^\n\r]*:0|\[^\n\r]*\\+0x\[0-9a-z\]*)|\[(\])\[^\n\r]*(\n|\r\n|\r).*" } */
 /* { dg-output "0x\[0-9a-f\]+ is located 0 bytes to the right of global variable" } */
index b42c09e..ac9deb8 100644 (file)
@@ -35,6 +35,7 @@ int main() {
   delete x;
 }
 
+// { dg-skip-if "inaccurate debug info" { mips*-*-* } { "-Os" } { "" }  }
 // { dg-output "ERROR: AddressSanitizer:? heap-buffer-overflow on address\[^\n\r]*" }
 // { dg-output "0x\[0-9a-f\]+ at pc 0x\[0-9a-f\]+ bp 0x\[0-9a-f\]+ sp 0x\[0-9a-f\]+\[^\n\r]*(\n|\r\n|\r)" }
 // { dg-output "\[^\n\r]*READ of size 4 at 0x\[0-9a-f\]+ thread T0\[^\n\r]*(\n|\r\n|\r)" }
index 5a59ea6..fb89df4 100644 (file)
@@ -54,10 +54,6 @@ case "${target}" in
        ;;
   arm*-*-linux*)
        ;;
-  mips*64*-*-linux*)
-       # This clause is only here to not match the supported mips*-*-linux*.
-       UNSUPPORTED=1
-       ;;
   mips*-*-linux*)
        ;;
   aarch64*-*-linux*)