public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Uros Bizjak <uros@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-11350] tree-optimization/111736 - avoid address sanitizing of __seg_gs
Date: Wed, 24 Apr 2024 14:39:52 +0000 (GMT)	[thread overview]
Message-ID: <20240424143952.DC7B93849ADA@sourceware.org> (raw)

https://gcc.gnu.org/g:b4e1aee01a2fa617cf74ab04cf0ab574761aaaea

commit r11-11350-gb4e1aee01a2fa617cf74ab04cf0ab574761aaaea
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Mar 21 08:30:39 2024 +0100

    tree-optimization/111736 - avoid address sanitizing of __seg_gs
    
    The following more thoroughly avoids address sanitizing accesses
    to non-generic address-spaces.
    
    gcc/ChangeLog:
    
            PR tree-optimization/111736
            * asan.c (instrument_derefs): Do not instrument accesses
            to non-generic address-spaces.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/i386/pr111736.c: New testcase.
    
    (cherry picked from commit 134ef2a8cac1a5cc718739bd7d3b3472947c80d6)

Diff:
---
 gcc/asan.c                               |  4 ++++
 gcc/testsuite/gcc.target/i386/pr111736.c | 23 +++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/gcc/asan.c b/gcc/asan.c
index b92c6007c97..fe24f531a04 100644
--- a/gcc/asan.c
+++ b/gcc/asan.c
@@ -2699,6 +2699,10 @@ instrument_derefs (gimple_stmt_iterator *iter, tree t,
   if (VAR_P (inner) && DECL_HARD_REGISTER (inner))
     return;
 
+  /* Accesses to non-generic address-spaces should not be instrumented.  */
+  if (!ADDR_SPACE_GENERIC_P (TYPE_ADDR_SPACE (TREE_TYPE (inner))))
+    return;
+
   poly_int64 decl_size;
   if ((VAR_P (inner) || TREE_CODE (inner) == RESULT_DECL)
       && offset == NULL_TREE
diff --git a/gcc/testsuite/gcc.target/i386/pr111736.c b/gcc/testsuite/gcc.target/i386/pr111736.c
new file mode 100644
index 00000000000..231fdd07e80
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr111736.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fsanitize=address" } */
+
+int __seg_gs m;
+
+int foo (void)
+{
+  return m;
+}
+
+extern int  __seg_gs n;
+
+int bar (void)
+{
+  return n;
+}
+
+int baz (int __seg_gs *o)
+{
+  return *o;
+}
+
+/* { dg-final { scan-assembler-not "asan_report_load" } } */

                 reply	other threads:[~2024-04-24 14:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240424143952.DC7B93849ADA@sourceware.org \
    --to=uros@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /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).