public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Dimitrije Milosevic <Dimitrije.Milosevic@Syrmia.com>
To: Xi Ruoyao <xry111@xry111.site>,
	"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Cc: Djordje Todorovic <Djordje.Todorovic@syrmia.com>
Subject: Re: [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and TSAN
Date: Tue, 5 Jul 2022 06:30:50 +0000	[thread overview]
Message-ID: <AM0PR03MB48824E3E442312120B090F6582819@AM0PR03MB4882.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <7e4db89fea59f636afd7abce981cc625d940b5cd.camel@xry111.site>

Hi Xi.
Correct, I am using a simulator.
Here are my changes:

diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt
index fb89df4935c..6855a6ca9e7 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -55,6 +55,10 @@ case "${target}" in
   arm*-*-linux*)
        ;;
   mips*-*-linux*)
+       if test x$ac_cv_sizeof_void_p = x8; then
+               TSAN_SUPPORTED=yes
+               TSAN_TARGET_DEPENDENT_OBJECTS=tsan_rtl_mips64.lo
+       fi
        ;;
   aarch64*-*-linux*)
        if test x$ac_cv_sizeof_void_p = x8; then

Nit: Updated the code in gcc/config/mips/mips.cc a little bit, but no functional
change compared to your version.

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 8a55d2fb8f7..4ccc9e75482 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -20118,13 +20118,12 @@ mips_option_override (void)
   /* -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.  */
-  /* FIXME: TSAN could also utilize -fasynchronous-unwind-tables, but
-      should be first enabled for MIPS64.
-     FIXME: HWSAN could also utilize -fasynchronous-unwind-tables, but,
+  /* FIXME: HWSAN could also utilize -fasynchronous-unwind-tables, but,
       currently, it is only available on AArch64.
      FIXME: We would also like to check if -ffreestanding is passed in.
       However, it is only available in C-ish frontends.  */
-  if ((flag_sanitize & SANITIZE_USER_ADDRESS)
+  if (((flag_sanitize & SANITIZE_USER_ADDRESS)
+       || (TARGET_64BIT && (flag_sanitize & SANITIZE_THREAD)))
       && !global_options_set.x_flag_asynchronous_unwind_tables)
     flag_asynchronous_unwind_tables = 1;



From: Xi Ruoyao <xry111@xry111.site>
Sent: Tuesday, July 5, 2022 3:54 AM
To: Dimitrije Milosevic <Dimitrije.Milosevic@Syrmia.com>; gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
Cc: Djordje Todorovic <Djordje.Todorovic@syrmia.com>
Subject: Re: [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and TSAN 
 
On Mon, 2022-07-04 at 14:28 +0000, Dimitrije Milosevic wrote:
> On Saturday, June 11, 2022 2:03 PM, Xi wrote:
> > Just tried TSAN_SUPPORTED=yes with asynchronous unwind tables
> > enabled,
> > but I got some strange test failures for tls_race.c:
> > 
> > FAIL: c-c++-common/tsan/tls_race.c   -O0  output pattern test
> > Output was:
> > ThreadSanitizer: CHECK failed: tsan_platform_linux.cpp:452
> > "((thr_end)) <= ((tls_addr + tls_size))" (0xffec35f8c0,
> > 0xffec35f784) (tid=748216)
> >     #0 __tsan::CheckUnwind()
> > ../../../../gcc/libsanitizer/tsan/tsan_rtl.cpp:627
> > (libtsan.so.2+0xa30ec)
> >     #1 __sanitizer::CheckFailed(char const*, int, char const*,
> > unsigned long long, unsigned long long)
> > ../../../../gcc/libsanitizer/sanitizer_common/sanitizer_termination.
> > cpp:86 (libtsan.so.2+0xeb8cc)
> >     #2 __tsan::ImitateTlsWrite(__tsan::ThreadState*, unsigned long,
> > unsigned long)
> > ../../../../gcc/libsanitizer/tsan/tsan_platform_linux.cpp:452
> > (libtsan.so.2+0xa0cac)
> >     #3 __tsan::ThreadStart(__tsan::ThreadState*, unsigned int,
> > unsigned long long, __sanitizer::ThreadType)
> > ../../../../gcc/libsanitizer/tsan/tsan_rtl_thread.cpp:197
> > (libtsan.so.2+0xc0e88)
> >     #4 __tsan_thread_start_func
> > ../../../../gcc/libsanitizer/tsan/tsan_interceptors_posix.cpp:1009
> > (libtsan.so.2+0x3e5dc)
> >     #5 start_thread /sources/glibc-2.35/nptl/pthread_create.c:442
> > (libc.so.6+0xc75f4)
> > 
> > I've tried to diagnose the root cause but failed.
> 
> Hi Xi, thanks for looking into this. I've tried running the testsuite
> on a cross-toolchain (as I do not currently have access to a physical
> machine)
> for a MIPS64R6 and the test passes successfully. Could you please
> verify that the test fails solely based on this change?

I guess you mean you are running MIPS64R6 target code with qemu?  I'm
not 100% sure because maybe something is wrong in my system.  I'm now
retrying on gcc230.fsffrance.org (an EdgeRouter 4 in Cfarm) but building
GCC on it is really slow.

The changes I've tested:

diff --git a/gcc/config/mips/mips.cc b/gcc/config/mips/mips.cc
index 5eb845960e1..a7f0580e9ba 100644
--- a/gcc/config/mips/mips.cc
+++ b/gcc/config/mips/mips.cc
@@ -20115,10 +20115,11 @@ 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
+  /* For -fsanitize=address or -fsanitize=thread, it's needed 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 | SANITIZE_THREAD)
       && !global_options_set.x_flag_asynchronous_unwind_tables)
     flag_asynchronous_unwind_tables = 1;
 
diff --git a/libsanitizer/configure.tgt b/libsanitizer/configure.tgt
index fb89df4935c..52546bbe4e3 100644
--- a/libsanitizer/configure.tgt
+++ b/libsanitizer/configure.tgt
@@ -55,6 +55,9 @@ case "${target}" in
   arm*-*-linux*)
         ;;
   mips*-*-linux*)
+       if test x$ac_cv_sizeof_void_p = x8; then
+               TSAN_SUPPORTED=yes
+       fi
         ;;
   aarch64*-*-linux*)
         if test x$ac_cv_sizeof_void_p = x8; then
-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

      parent reply	other threads:[~2022-07-05  6:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-26 14:18 [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and LSAN Dimitrije Milosevic
     [not found] ` <e598dc5e6fb56c31e8ce8ff4569bb3bc64b49dfa.camel@xry111.site>
2022-05-30  7:10   ` [PATCH] Mips: Enable asynchronous unwind tables with both ASAN and TSAN Dimitrije Milosevic
2022-06-07  8:20     ` Xi Ruoyao
2022-06-07 10:13       ` Dimitrije Milosevic
2022-06-11 12:03         ` Xi Ruoyao
2022-07-04 14:28           ` Dimitrije Milosevic
2022-07-05  1:54             ` Xi Ruoyao
2022-07-05  4:21               ` Fangrui Song
2022-07-05  4:51                 ` Xi Ruoyao
2022-07-05  8:47                   ` Xi Ruoyao
2022-07-05  9:13                 ` Xi Ruoyao
2022-07-05  6:30               ` Dimitrije Milosevic [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM0PR03MB48824E3E442312120B090F6582819@AM0PR03MB4882.eurprd03.prod.outlook.com \
    --to=dimitrije.milosevic@syrmia.com \
    --cc=Djordje.Todorovic@syrmia.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=xry111@xry111.site \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).